diff --git a/client/service_manager.go b/client/service_manager.go index a8ae74d11..7b46dafe9 100644 --- a/client/service_manager.go +++ b/client/service_manager.go @@ -35,12 +35,9 @@ func (s *ServiceManager) Setup() { // addServiceMonitor watches a channel to add services into operation. func (s *ServiceManager) addServiceMonitor() { log.Println("[DEBUG] starting service creation monitor") - for { - select { - case p := <-s.commandCreatedChan: - if p != nil && p.Process != nil { - s.processMap.Set(p.Process.Pid, p) - } + for p := range s.commandCreatedChan { + if p != nil && p.Process != nil { + s.processMap.Set(p.Process.Pid, p) } } } @@ -48,14 +45,12 @@ func (s *ServiceManager) addServiceMonitor() { // removeServiceMonitor watches a channel to remove services from operation. func (s *ServiceManager) removeServiceMonitor() { log.Println("[DEBUG] starting service removal monitor") - var p *exec.Cmd - for { - select { - case p = <-s.commandCompleteChan: - if p != nil && p.Process != nil { - p.Process.Signal(os.Interrupt) - s.processMap.Delete(p.Process.Pid) + for p := range s.commandCompleteChan { + if p != nil && p.Process != nil { + if err := p.Process.Signal(os.Interrupt); err != nil { + log.Println("[ERROR] service removal monitor failed to process signal:", err) } + s.processMap.Delete(p.Process.Pid) } } } @@ -161,7 +156,7 @@ type processMap struct { func (pm *processMap) Get(k int) *exec.Cmd { pm.RLock() defer pm.RUnlock() - v, _ := pm.processes[k] + v := pm.processes[k] return v } diff --git a/client/service_test.go b/client/service_test.go index 52e27a9c4..0bb45ee57 100644 --- a/client/service_test.go +++ b/client/service_test.go @@ -13,7 +13,7 @@ var channelTimeout = 50 * time.Millisecond func createServiceManager() *ServiceManager { cs := []string{"-test.run=TestHelperProcess", "--", os.Args[0]} - env := []string{"GO_WANT_HELPER_PROCESS=1", fmt.Sprintf("GO_WANT_HELPER_PROCESS_TO_SUCCEED=true")} + env := []string{"GO_WANT_HELPER_PROCESS=1", "GO_WANT_HELPER_PROCESS_TO_SUCCEED=true"} mgr := &ServiceManager{ Cmd: os.Args[0], Args: cs, @@ -24,9 +24,7 @@ func createServiceManager() *ServiceManager { } func TestServiceManager(t *testing.T) { - var manager interface{} - manager = new(ServiceManager) - + var manager interface{} = new(ServiceManager) if _, ok := manager.(*ServiceManager); !ok { t.Fatalf("Must be a ServiceManager") } @@ -47,7 +45,7 @@ func TestServiceManager_Setup(t *testing.T) { func TestServiceManager_removeServiceMonitor(t *testing.T) { mgr := createServiceManager() cmd := fakeExecCommand("", true, "") - cmd.Start() + cmd.Start() // nolint:errcheck mgr.processMap.processes = map[int]*exec.Cmd{ cmd.Process.Pid: cmd, } @@ -75,7 +73,7 @@ func TestServiceManager_removeServiceMonitor(t *testing.T) { func TestServiceManager_addServiceMonitor(t *testing.T) { mgr := createServiceManager() cmd := fakeExecCommand("", true, "") - cmd.Start() + cmd.Start() // nolint:errcheck mgr.commandCreatedChan <- cmd var timeout = time.After(channelTimeout) @@ -128,12 +126,12 @@ func TestServiceManager_addServiceMonitorWithDeadJob(t *testing.T) { func TestServiceManager_Stop(t *testing.T) { mgr := createServiceManager() cmd := fakeExecCommand("", true, "") - cmd.Start() + cmd.Start() // nolint:errcheck mgr.processMap.processes = map[int]*exec.Cmd{ cmd.Process.Pid: cmd, } - mgr.Stop(cmd.Process.Pid) + mgr.Stop(cmd.Process.Pid) // nolint:errcheck var timeout = time.After(channelTimeout) for { mgr.processMap.Lock() @@ -157,7 +155,7 @@ func TestServiceManager_Stop(t *testing.T) { func TestServiceManager_List(t *testing.T) { mgr := createServiceManager() cmd := fakeExecCommand("", true, "") - cmd.Start() + cmd.Start() // nolint:errcheck processes := map[int]*exec.Cmd{ cmd.Process.Pid: cmd, } @@ -196,15 +194,6 @@ func TestServiceManager_Start(t *testing.T) { } } -// Adapted from http://npf.io/2015/06/testing-exec-command/ -var fakeExecSuccessCommand = func() *exec.Cmd { - return fakeExecCommand("", true, "") -} - -var fakeExecFailCommand = func() *exec.Cmd { - return fakeExecCommand("", false, "") -} - func fakeExecCommand(command string, success bool, args ...string) *exec.Cmd { cs := []string{"-test.run=TestHelperProcess", "--", command} cs = append(cs, args...) diff --git a/dsl/broker_test.go b/dsl/broker_test.go index 191763093..ee1c5512f 100644 --- a/dsl/broker_test.go +++ b/dsl/broker_test.go @@ -24,7 +24,7 @@ func setupMockBroker(auth bool) *httptest.Server { w.Header().Set("WWW-Authenticate", `Basic realm="Broker Authentication Required"`) w.WriteHeader(401) - w.Write([]byte("401 Unauthorized\n")) + w.Write([]byte("401 Unauthorized\n")) // nolint:errcheck }) } } else { @@ -67,7 +67,7 @@ func setupMockBroker(auth bool) *httptest.Server { mux.Handle("/pacts/provider/broken/latest/dev", authFunc(func(w http.ResponseWriter, req *http.Request) { log.Println("[DEBUG] broker broker response") w.WriteHeader(500) - w.Write([]byte("500 Server Error\n")) + w.Write([]byte("500 Server Error\n")) // nolint:errcheck })) // Find 'bobby' consumers for tag 'dev' diff --git a/dsl/client.go b/dsl/client.go index 13bcdb412..42cb4ebfb 100644 --- a/dsl/client.go +++ b/dsl/client.go @@ -97,8 +97,11 @@ func (p *PactClient) StartServer(args []string, port int) *types.MockServer { svc := p.pactMockSvcManager.NewService(args) cmd := svc.Start() - waitForPort(port, p.getNetworkInterface(), p.Address, p.TimeoutDuration, + err := waitForPort(port, p.getNetworkInterface(), p.Address, p.TimeoutDuration, fmt.Sprintf(`Timed out waiting for Mock Server to start on port %d - are you sure it's running?`, port)) + if err != nil { + log.Println("[ERROR] client: failed to wait for Mock Server:", err) + } return &types.MockServer{ Pid: cmd.Process.Pid, @@ -137,7 +140,9 @@ func (p *PactClient) RemoveAllServers(server *types.MockServer) []*types.MockSer for _, s := range p.verificationSvcManager.List() { if s != nil { - p.pactMockSvcManager.Stop(s.Process.Pid) + if _, err := p.pactMockSvcManager.Stop(s.Process.Pid); err != nil { + log.Println("[ERROR] client: stop server failed:", err) + } } } return nil @@ -195,8 +200,8 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid // Each pact is verified by line, and the results (as JSON) sent to stdout. // See https://github.com/pact-foundation/pact-go/issues/88#issuecomment-404686337 stdOutScanner := bufio.NewScanner(stdOutPipe) + wg.Add(1) go func() { - wg.Add(1) defer wg.Done() stdOutBuf := make([]byte, bufio.MaxScanTokenSize) stdOutScanner.Buffer(stdOutBuf, 64*1024*1024) @@ -208,13 +213,12 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid // Scrape errors stdErrScanner := bufio.NewScanner(stdErrPipe) + wg.Add(1) go func() { - wg.Add(1) defer wg.Done() for stdErrScanner.Scan() { stdErr.WriteString(fmt.Sprintf("%s\n", stdErrScanner.Text())) } - }() err = cmd.Start() @@ -429,13 +433,13 @@ var waitForPort = func(port int, network string, address string, timeoutDuration func sanitiseRubyResponse(response string) string { log.Println("[TRACE] response from Ruby process pre-sanitisation:", response) - r := regexp.MustCompile("(?m)^\\s*#.*$") + r := regexp.MustCompile(`(?m)^\s*#.*$`) s := r.ReplaceAllString(response, "") r = regexp.MustCompile("(?m).*bundle exec rake pact:verify.*$") s = r.ReplaceAllString(s, "") - r = regexp.MustCompile("\\n+") + r = regexp.MustCompile(`\n+`) s = r.ReplaceAllString(s, "\n") return s diff --git a/dsl/client_test.go b/dsl/client_test.go index a2986cc0d..7d70f2e5e 100644 --- a/dsl/client_test.go +++ b/dsl/client_test.go @@ -45,7 +45,10 @@ func TestClient_StartServerFail(t *testing.T) { func TestClient_StopServer(t *testing.T) { client, svc := createMockClient(true) - client.StopServer(&types.MockServer{}) + _, err := client.StopServer(&types.MockServer{}) + if err != nil { + t.Fatalf("Failed to stop server: %v", err) + } if svc.ServiceStopCount != 1 { t.Fatalf("Expected 1 server to have been stopped, got %d", svc.ServiceStartCount) } @@ -216,13 +219,13 @@ func createMockClient(success bool) (*PactClient, *ServiceMock) { // Start all processes to get the Pids! for _, s := range svc.ServiceList { - s.Start() + s.Start() // nolint:errcheck } // Cleanup all Processes when we finish defer func() { for _, s := range svc.ServiceList { - s.Process.Kill() + s.Process.Kill() // nolint:errcheck } }() diff --git a/dsl/interaction_test.go b/dsl/interaction_test.go index 425f0d9d1..739080be5 100644 --- a/dsl/interaction_test.go +++ b/dsl/interaction_test.go @@ -58,7 +58,7 @@ func TestInteraction_WithRequest(t *testing.T) { var expect interface{} body, _ := json.Marshal(obj) - json.Unmarshal(body, &expect) + json.Unmarshal(body, &expect) // nolint:errcheck if _, ok := i.Request.Body.(map[string]string); !ok { t.Fatal("Expected response to be of type 'map[string]string', but got", reflect.TypeOf(i.Request.Body)) @@ -104,7 +104,7 @@ func TestInteraction_WillRespondWith(t *testing.T) { var expect interface{} body, _ := json.Marshal(obj) - json.Unmarshal(body, &expect) + json.Unmarshal(body, &expect) // nolint:errcheck if _, ok := i.Response.Body.(map[string]string); !ok { t.Fatal("Expected response to be of type 'map[string]string', but got", reflect.TypeOf(i.Response.Body)) diff --git a/dsl/matcher.go b/dsl/matcher.go index d663e9ed6..5aa04dc32 100644 --- a/dsl/matcher.go +++ b/dsl/matcher.go @@ -14,7 +14,6 @@ import ( const ( hexadecimal = `[0-9a-fA-F]+` ipAddress = `(\d{1,3}\.)+\d{1,3}` - ipv6Address = `(\A([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,6}\Z)|(\A([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}\Z)|(\A([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}\Z)|(\A([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}\Z)|(\A([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}\Z)|(\A([0-9a-f]{1,4}:){1,6}(:[0-9a-f]{1,4}){1,1}\Z)|(\A(([0-9a-f]{1,4}:){1,7}|:):\Z)|(\A:(:[0-9a-f]{1,4}){1,7}\Z)|(\A((([0-9a-f]{1,4}:){6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})\Z)|(\A(([0-9a-f]{1,4}:){5}[0-9a-f]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})\Z)|(\A([0-9a-f]{1,4}:){5}:[0-9a-f]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,3}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,2}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,1}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A(([0-9a-f]{1,4}:){1,5}|:):(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A:(:[0-9a-f]{1,4}){1,5}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)` uuid = `[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}` timestamp = `^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$` date = `^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))?)` diff --git a/dsl/matcher_test.go b/dsl/matcher_test.go index 8b4ff5bf9..824cc7997 100644 --- a/dsl/matcher_test.go +++ b/dsl/matcher_test.go @@ -332,16 +332,16 @@ func formatJSON(object interface{}) interface{} { var out bytes.Buffer switch content := object.(type) { case string: - json.Indent(&out, []byte(content), "", "\t") + json.Indent(&out, []byte(content), "", "\t") // nolint:errcheck default: jsonString, err := json.Marshal(object) if err != nil { log.Println("[ERROR] unable to marshal json:", err) } - json.Indent(&out, []byte(jsonString), "", "\t") + json.Indent(&out, []byte(jsonString), "", "\t") // nolint:errcheck } - return string(out.Bytes()) + return out.String() } // Instrument the StructMatcher type to be able to assert the diff --git a/dsl/message_test.go b/dsl/message_test.go index b36723f98..8e2667521 100644 --- a/dsl/message_test.go +++ b/dsl/message_test.go @@ -2,10 +2,6 @@ package dsl import "testing" -type t struct { - ID int -} - func TestMessage_DSL(t *testing.T) { m := &Message{} m.Given("state string"). diff --git a/dsl/pact.go b/dsl/pact.go index a88e0b404..848b82828 100644 --- a/dsl/pact.go +++ b/dsl/pact.go @@ -143,11 +143,11 @@ func (p *Pact) Setup(startMockServer bool) *Pact { } if p.LogDir == "" { - p.LogDir = fmt.Sprintf(filepath.Join(dir, "logs")) + p.LogDir = filepath.Join(dir, "logs") } if p.PactDir == "" { - p.PactDir = fmt.Sprintf(filepath.Join(dir, "pacts")) + p.PactDir = filepath.Join(dir, "pacts") } if p.SpecificationVersion == 0 { @@ -488,9 +488,13 @@ func stateHandlerMiddleware(stateHandlers types.StateHandlers) proxy.Middleware return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == providerStatesSetupPath { - var s *types.ProviderState + var s types.ProviderState decoder := json.NewDecoder(r.Body) - decoder.Decode(&s) + if err := decoder.Decode(&s); err != nil { + log.Printf("[ERROR] failed to decode provider state: %v", err) + w.WriteHeader(http.StatusBadRequest) + return + } // Setup any provider state for _, state := range s.States { @@ -582,12 +586,14 @@ var messageVerificationHandler = func(messageHandlers MessageHandlers, stateHand resBody, errM := json.Marshal(wrappedResponse) if errM != nil { w.WriteHeader(http.StatusServiceUnavailable) - log.Println("[ERROR] error marshalling objcet:", errM) + log.Println("[ERROR] error marshalling object:", errM) return } w.WriteHeader(http.StatusOK) - w.Write(resBody) + if _, err := w.Write(resBody); err != nil { + log.Println("[ERROR] error writing response:", err) + } } } @@ -693,7 +699,12 @@ func (p *Pact) VerifyMessageProviderRaw(request VerifyMessageRequest) ([]types.P defer ln.Close() log.Printf("[DEBUG] API handler starting: port %d (%s)", port, ln.Addr()) - go http.Serve(ln, mux) + go func() { + if err := http.Serve(ln, mux); err != nil { + // NOTE: calling Fatalf causing test failures due to "accept tcp [::]:: use of closed network connection" + log.Printf("[ERROR] API handler start failed: %v", err) + } + }() portErr := waitForPort(port, "tcp", "localhost", p.ClientTimeout, fmt.Sprintf(`Timed out waiting for pact proxy on port %d - check for errors`, port)) @@ -715,7 +726,7 @@ func (p *Pact) VerifyMessageProviderRaw(request VerifyMessageRequest) ([]types.P // It is the receiver of an interaction, and needs to be able to handle whatever // request was provided. func (p *Pact) VerifyMessageConsumerRaw(message *Message, handler MessageConsumer) error { - log.Printf("[DEBUG] verify message") + log.Println("[DEBUG] verify message") p.Setup(false) // Reify the message back to its "example/generated" form diff --git a/dsl/pact_test.go b/dsl/pact_test.go index 7eaa2019f..425ce23ac 100644 --- a/dsl/pact_test.go +++ b/dsl/pact_test.go @@ -408,7 +408,7 @@ func TestPact_BeforeEach(t *testing.T) { } // expect http handler to NOT have been called - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h != "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h != "true" { t.Error("expected http handler to be invoked") } } @@ -435,7 +435,7 @@ func TestPact_BeforeEachNotSetupPath(t *testing.T) { } // expect http handler to NOT have been called - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h != "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h != "true" { t.Error("expected http handler to be invoked") } } @@ -462,7 +462,7 @@ func TestPact_AfterEach(t *testing.T) { } // expect http handler to NOT have been called - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h != "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h != "true" { t.Error("expected http handler to be invoked") } } @@ -490,7 +490,7 @@ func TestPact_AfterEachSetupPath(t *testing.T) { } // expect http handler to NOT have been called - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h != "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h != "true" { t.Error("expected http handler to be invoked") } } @@ -527,7 +527,7 @@ func TestPact_StateHandlerMiddlewareStateHandlerExists(t *testing.T) { } // expect http handler to NOT have been called - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h == "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h == "true" { t.Error("expected http handler to not be invoked") } } @@ -558,7 +558,7 @@ func TestPact_StateHandlerMiddlewareStateHandlerNotExists(t *testing.T) { } // expect http handler to NOT have been called - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h == "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h == "true" { t.Error("expected http handler to not be invoked") } } @@ -591,7 +591,7 @@ func TestPact_StateHandlerMiddlewareStateHandlerError(t *testing.T) { } // expect http handler to NOT have been called - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h == "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h == "true" { t.Error("expected http handler to not be invoked") } } @@ -611,7 +611,7 @@ func TestPact_StateHandlerMiddlewarePassThroughInvalidPath(t *testing.T) { mw(dummyHandler("X-Dummy-Handler")).ServeHTTP(rr, req) // expect http handler to have been called - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h != "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h != "true" { t.Errorf("expected target http handler to be invoked") } } diff --git a/dsl/publish_test.go b/dsl/publish_test.go index 1004b1070..cbb6b3d9a 100644 --- a/dsl/publish_test.go +++ b/dsl/publish_test.go @@ -3,65 +3,13 @@ package dsl import ( "encoding/base64" "fmt" - "io/ioutil" - "log" "net/http" - "net/http/httptest" - "os" - "path/filepath" "strings" "testing" "github.com/pact-foundation/pact-go/types" ) -func createMockRemoteServer(valid bool) (*httptest.Server, string) { - file := createSimplePact(valid) - dir := filepath.Dir(file.Name()) - path := filepath.Base(file.Name()) - server := httptest.NewServer(http.FileServer(http.Dir(dir))) - - return server, fmt.Sprintf("%s/%s", server.URL, path) -} - -func createSimplePact(valid bool) *os.File { - var data []byte - if valid { - data = []byte(` - { - "consumer": { - "name": "Some Consumer" - }, - "provider": { - "name": "Some Provider" - } - } - `) - } else { - data = []byte(` - { - "consumer": { - "name": "Some Consumer" - } - } - `) - } - - tmpfile, err := ioutil.TempFile("", "pactgo") - if err != nil { - log.Fatal(err) - } - - if _, err := tmpfile.Write(data); err != nil { - log.Fatal(err) - } - if err := tmpfile.Close(); err != nil { - log.Fatal(err) - } - - return tmpfile -} - var checkAuth = func(w http.ResponseWriter, r *http.Request) bool { s := strings.SplitN(r.Header.Get("Authorization"), " ", 2) if len(s) != 2 { @@ -81,21 +29,6 @@ var checkAuth = func(w http.ResponseWriter, r *http.Request) bool { return pair[0] == "foo" && pair[1] == "bar" } -func createMockRemoteServerWithAuth(valid bool) *httptest.Server { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if checkAuth(w, r) { - w.Write([]byte("Authenticated!")) - return - } - - w.Header().Set("WWW-Authenticate", `Basic realm="MY REALM"`) - w.WriteHeader(401) - w.Write([]byte("401 Unauthorized\n")) - })) - - return ts -} - func TestPublish_Publish(t *testing.T) { c := newMockClient() p := Publisher{ diff --git a/dsl/request_test.go b/dsl/request_test.go index efbadd285..73b7478a9 100644 --- a/dsl/request_test.go +++ b/dsl/request_test.go @@ -2,14 +2,6 @@ package dsl import "testing" -func TestRequest_Interface(t *testing.T) { - var req interface{} - req = Request{} - if _, ok := req.(Request); !ok { - t.Fatalf("Must be a *Request") - } -} - func TestRequest(t *testing.T) { req := Request{ Method: "GET", diff --git a/dsl/service_mock.go b/dsl/service_mock.go index 978264c8d..052f6f8af 100644 --- a/dsl/service_mock.go +++ b/dsl/service_mock.go @@ -45,7 +45,7 @@ func (s *ServiceMock) Start() *exec.Cmd { s.ServiceStartCount++ cmd := s.ExecFunc() - cmd.Start() + cmd.Start() // nolint:errcheck if s.processes == nil { s.processes = make(map[int]*exec.Cmd) } diff --git a/install/installer.go b/install/installer.go index e7ac26b67..0f146a4a9 100644 --- a/install/installer.go +++ b/install/installer.go @@ -69,6 +69,10 @@ func (i *Installer) CheckVersion(binary, version string) error { log.Println("[DEBUG] checking if version", v, "within semver range", versionRange) constraints, err := goversion.NewConstraint(versionRange) + if err != nil { + log.Println("[DEBUG] err", err) + return err + } if constraints.Check(v) { log.Println("[DEBUG]", v, "satisfies constraints", v, constraints) return nil diff --git a/proxy/http.go b/proxy/http.go index b1a2bbcfc..d9eed0d9a 100644 --- a/proxy/http.go +++ b/proxy/http.go @@ -97,7 +97,7 @@ func HTTPReverseProxy(options Options) (int, error) { wrapper := chainHandlers(append(options.Middleware, loggingMiddleware)...) log.Println("[DEBUG] starting reverse proxy on port", port) - go http.ListenAndServe(fmt.Sprintf(":%d", port), wrapper(proxy)) + go http.ListenAndServe(fmt.Sprintf(":%d", port), wrapper(proxy)) // nolint:errcheck return port, nil } diff --git a/proxy/http_test.go b/proxy/http_test.go index 47700ca76..67d101401 100644 --- a/proxy/http_test.go +++ b/proxy/http_test.go @@ -1,7 +1,6 @@ package proxy import ( - "fmt" "net/http" "net/http/httptest" "testing" @@ -32,7 +31,7 @@ func TestLoggingMiddleware(t *testing.T) { loggingMiddleware(dummyHandler("X-Dummy-Handler")).ServeHTTP(rr, req) - if h := rr.HeaderMap.Get("X-Dummy-Handler"); h != "true" { + if h := rr.Header().Get("X-Dummy-Handler"); h != "true" { t.Errorf("expected handler to set the header 'X-Dummy-Handler: true' but got '%v'", h) } @@ -63,7 +62,7 @@ func TestChainHandlers(t *testing.T) { middlewareChain(dummyHandler("X-Dummy-Handler")).ServeHTTP(rr, req) for _, h := range headers { - if v := rr.HeaderMap.Get(h); v != "true" { + if v := rr.Header().Get(h); v != "true" { t.Errorf("expected handler to set the header '%v: true' but got '%v'", h, v) } @@ -78,7 +77,7 @@ func TestHTTPReverseProxy(t *testing.T) { DummyMiddleware("1"), }, TargetScheme: "http", - TargetAddress: fmt.Sprintf("127.0.0.1:1234"), + TargetAddress: "127.0.0.1:1234", }) if err != nil {