From 9755a522777dd2385d1f2257618837fb4f851f42 Mon Sep 17 00:00:00 2001 From: Sasha Melentyev Date: Sun, 26 Dec 2021 13:17:54 +0300 Subject: [PATCH] refactor(all): Small refactor --- client/service_manager.go | 6 +++--- command/install.go | 3 +-- dsl/client.go | 7 +++---- dsl/pact.go | 8 ++++---- dsl/pact_test.go | 4 ++-- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/client/service_manager.go b/client/service_manager.go index 7b46dafe9..d1dfa6657 100644 --- a/client/service_manager.go +++ b/client/service_manager.go @@ -130,10 +130,10 @@ func (s *ServiceManager) Start() *exec.Cmd { } }() - scanner2 := bufio.NewScanner(cmdReaderErr) + scannerErr := bufio.NewScanner(cmdReaderErr) go func() { - for scanner2.Scan() { - log.Printf("[ERROR] service: %s\n", scanner2.Text()) + for scannerErr.Scan() { + log.Printf("[ERROR] service: %s\n", scannerErr.Text()) } }() diff --git a/command/install.go b/command/install.go index d604aeaaf..424b7adac 100644 --- a/command/install.go +++ b/command/install.go @@ -19,8 +19,7 @@ var installCmd = &cobra.Command{ // Run the installer i := install.NewInstaller() - var err error - if err = i.CheckInstallation(); err != nil { + if err := i.CheckInstallation(); err != nil { log.Println("[ERROR] Your Pact CLI installation is out of date, please update to the latest version. Error:", err) os.Exit(1) } diff --git a/dsl/client.go b/dsl/client.go index b09bff4b3..5451da7b1 100644 --- a/dsl/client.go +++ b/dsl/client.go @@ -70,14 +70,14 @@ type PactClient struct { } // newClient creates a new Pact client manager with the provided services -func newClient(MockServiceManager client.Service, verificationServiceManager client.Service, messageServiceManager client.Service, publishServiceManager client.Service) *PactClient { - MockServiceManager.Setup() +func newClient(mockServiceManager client.Service, verificationServiceManager client.Service, messageServiceManager client.Service, publishServiceManager client.Service) *PactClient { + mockServiceManager.Setup() verificationServiceManager.Setup() messageServiceManager.Setup() publishServiceManager.Setup() return &PactClient{ - pactMockSvcManager: MockServiceManager, + pactMockSvcManager: mockServiceManager, verificationSvcManager: verificationServiceManager, messageSvcManager: messageServiceManager, publishSvcManager: publishServiceManager, @@ -165,7 +165,6 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid err = waitForPort(port, p.getNetworkInterface(), address, p.TimeoutDuration, fmt.Sprintf(`Timed out waiting for Provider API to start on port %d - are you sure it's running?`, port)) - if err != nil { return response, err } diff --git a/dsl/pact.go b/dsl/pact.go index 68d6dc1b6..1c8fd8dc8 100644 --- a/dsl/pact.go +++ b/dsl/pact.go @@ -440,13 +440,13 @@ var checkCliCompatibility = func() { // BeforeEachMiddleware is invoked before any other, only on the __setup // request (to avoid duplication) -func BeforeEachMiddleware(BeforeEach types.Hook) proxy.Middleware { +func BeforeEachMiddleware(beforeEach types.Hook) proxy.Middleware { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == providerStatesSetupPath { log.Println("[DEBUG] executing before hook") - err := BeforeEach() + err := beforeEach() if err != nil { log.Println("[ERROR] error executing before hook:", err) @@ -461,14 +461,14 @@ func BeforeEachMiddleware(BeforeEach types.Hook) proxy.Middleware { // AfterEachMiddleware is invoked after any other, and is the last // function to be called prior to returning to the test suite. It is // therefore not invoked on __setup -func AfterEachMiddleware(AfterEach types.Hook) proxy.Middleware { +func AfterEachMiddleware(afterEach types.Hook) proxy.Middleware { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { next.ServeHTTP(w, r) if r.URL.Path != providerStatesSetupPath { log.Println("[DEBUG] executing after hook") - err := AfterEach() + err := afterEach() if err != nil { log.Println("[ERROR] error executing after hook:", err) diff --git a/dsl/pact_test.go b/dsl/pact_test.go index 425ce23ac..95639a3af 100644 --- a/dsl/pact_test.go +++ b/dsl/pact_test.go @@ -617,9 +617,9 @@ func TestPact_StateHandlerMiddlewarePassThroughInvalidPath(t *testing.T) { } func dummyHandler(header string) http.HandlerFunc { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { w.Header().Set(header, "true") - }) + } } func TestPact_AddMessage(t *testing.T) {