From 62a95f0e48459429e18f17a54b93e05101598be8 Mon Sep 17 00:00:00 2001 From: Simon Aronsson Date: Wed, 17 Apr 2019 21:32:09 +0200 Subject: [PATCH] Fix linting errors --- container/container_test.go | 2 +- container/mocks/ApiServer.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/container/container_test.go b/container/container_test.go index 47ec8e0..2543976 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -19,7 +19,7 @@ var _ = Describe("the container", func() { Describe("the client", func() { var client Client BeforeSuite(func() { - server := mocks.NewMockApiServer() + server := mocks.NewMockAPIServer() c, _ := cli.NewClientWithOpts( cli.WithHost(server.URL), cli.WithHTTPClient(server.Client(), diff --git a/container/mocks/ApiServer.go b/container/mocks/ApiServer.go index f63b93b..79290a2 100644 --- a/container/mocks/ApiServer.go +++ b/container/mocks/ApiServer.go @@ -10,22 +10,24 @@ import ( "strings" ) -func NewMockApiServer() *httptest.Server { +// NewMockAPIServer returns a mocked docker api server that responds to some fixed requests +// used in the test suite. +func NewMockAPIServer() *httptest.Server { return httptest.NewServer(http.HandlerFunc( func(w http.ResponseWriter, r *http.Request) { logrus.Debug("Mock server has received a HTTP call on ", r.URL) var response = "" if isRequestFor("containers/json?limit=0", r) { - response = getMockJsonFromDisk("./mocks/data/containers.json") + response = getMockJSONFromDisk("./mocks/data/containers.json") } else if isRequestFor("ae8964ba86c7cd7522cf84e09781343d88e0e3543281c747d88b27e246578b65", r) { - response = getMockJsonFromDisk("./mocks/data/container_stopped.json") + response = getMockJSONFromDisk("./mocks/data/container_stopped.json") } else if isRequestFor("b978af0b858aa8855cce46b628817d4ed58e58f2c4f66c9b9c5449134ed4c008", r) { - response = getMockJsonFromDisk("./mocks/data/container_running.json") + response = getMockJSONFromDisk("./mocks/data/container_running.json") } else if isRequestFor("sha256:19d07168491a3f9e2798a9bed96544e34d57ddc4757a4ac5bb199dea896c87fd", r) { - response = getMockJsonFromDisk("./mocks/data/image01.json") + response = getMockJSONFromDisk("./mocks/data/image01.json") } else if isRequestFor("sha256:4dbc5f9c07028a985e14d1393e849ea07f68804c4293050d5a641b138db72daa", r) { - response = getMockJsonFromDisk("./mocks/data/image02.json") + response = getMockJSONFromDisk("./mocks/data/image02.json") } fmt.Fprintln(w, response) }, @@ -36,7 +38,7 @@ func isRequestFor(urlPart string, r *http.Request) bool { return strings.Contains(r.URL.String(), urlPart) } -func getMockJsonFromDisk(relPath string) string { +func getMockJSONFromDisk(relPath string) string { absPath, _ := filepath.Abs(relPath) logrus.Error(absPath) buf, err := ioutil.ReadFile(absPath)