diff --git a/dataclients/kubernetes/kube_test.go b/dataclients/kubernetes/kube_test.go index 6ae6f13db4..a2f6225e73 100644 --- a/dataclients/kubernetes/kube_test.go +++ b/dataclients/kubernetes/kube_test.go @@ -28,6 +28,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "github.com/zalando/skipper/dataclients/kubernetes/definitions" "github.com/zalando/skipper/eskip" @@ -579,6 +580,8 @@ func TestIngressClassFilter(t *testing.T) { } func TestIngress(t *testing.T) { + defer goleak.VerifyNone(t) + api := newTestAPI(t, nil, &definitions.IngressList{}) defer api.Close() @@ -741,8 +744,8 @@ func TestIngress(t *testing.T) { } checkRoutes(t, r, map[string]string{ - "kube_namespace1__default_only______": "", //shunted because invalid backend - "kube_namespace1__mega__foo_example_org___test1__service1": "", //shunted because invalid backend + "kube_namespace1__default_only______": "", // shunted because invalid backend + "kube_namespace1__mega__foo_example_org___test1__service1": "", // shunted because invalid backend }) }) @@ -1864,7 +1867,7 @@ func TestBuildHTTPClient(t *testing.T) { t.Errorf("should return invalid certificate") } - err = os.WriteFile("ca.empty.crt", []byte(""), 0644) + err = os.WriteFile("ca.empty.crt", []byte(""), 0o644) if err != nil { t.Error(err) } @@ -1875,8 +1878,8 @@ func TestBuildHTTPClient(t *testing.T) { t.Error("empty certificate is invalid certificate") } - //create CA file - err = os.WriteFile("ca.temp.crt", generateSSCert(), 0644) + // create CA file + err = os.WriteFile("ca.temp.crt", generateSSCert(), 0o644) if err != nil { t.Error(err) } @@ -1899,7 +1902,7 @@ func TestScoping(t *testing.T) { // generateSSCert only for testing purposes func generateSSCert() []byte { - //create root CA + // create root CA serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) serialNumber, _ := rand.Int(rand.Reader, serialNumberLimit) @@ -1923,8 +1926,8 @@ func generateSSCert() []byte { } func createCert(template, parent *x509.Certificate, pub interface{}, parentPriv interface{}) ( - cert *x509.Certificate, certPEM []byte, err error) { - + cert *x509.Certificate, certPEM []byte, err error, +) { certDER, err := x509.CreateCertificate(rand.Reader, template, parent, pub, parentPriv) if err != nil { return @@ -2164,7 +2167,8 @@ func TestComputeBackendWeights(t *testing.T) { Backend: &definitions.Backend{ ServiceName: "baz", }, - }, { + }, + { Path: "", Backend: &definitions.Backend{ ServiceName: "qux", @@ -2990,7 +2994,6 @@ func TestSkipperDefaultFilters(t *testing.T) { defer dc.Close() r, err := dc.LoadAll() - if err != nil { t.Error("should not return an error", err) return @@ -3012,7 +3015,7 @@ func TestSkipperDefaultFilters(t *testing.T) { t.Error(err) } file := filepath.Join(defaultFiltersDir, "service1.namespace1") - if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0666); err != nil { + if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0o666); err != nil { t.Error(err) } @@ -3052,7 +3055,7 @@ func TestSkipperDefaultFilters(t *testing.T) { t.Error(err) } file := filepath.Join(dir, "service1.namespace1") - if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0666); err != nil { + if err := os.WriteFile(file, []byte("consecutiveBreaker(15)"), 0o666); err != nil { t.Error(err) } @@ -3084,7 +3087,7 @@ func TestSkipperDefaultFilters(t *testing.T) { t.Error(err) } invalidFileName := filepath.Join(defaultFiltersDir, "file.name.doesnt.match.our.pattern") - if err := os.WriteFile(invalidFileName, []byte("consecutiveBreaker(15)"), 0666); err != nil { + if err := os.WriteFile(invalidFileName, []byte("consecutiveBreaker(15)"), 0o666); err != nil { t.Error(err) } err = os.Mkdir(filepath.Join(defaultFiltersDir, "some.directory"), os.ModePerm) @@ -3092,7 +3095,7 @@ func TestSkipperDefaultFilters(t *testing.T) { t.Error(err) } bigFile := filepath.Join(defaultFiltersDir, "huge.file") - if err := os.WriteFile(bigFile, make([]byte, 1024*1024+1), 0666); err != nil { + if err := os.WriteFile(bigFile, make([]byte, 1024*1024+1), 0o666); err != nil { t.Error(err) } diff --git a/dataclients/kubernetes/main_test.go b/dataclients/kubernetes/main_test.go new file mode 100644 index 0000000000..b1827b6a3c --- /dev/null +++ b/dataclients/kubernetes/main_test.go @@ -0,0 +1,11 @@ +package kubernetes_test + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/eskipfile/main_test.go b/eskipfile/main_test.go new file mode 100644 index 0000000000..646c9b55c7 --- /dev/null +++ b/eskipfile/main_test.go @@ -0,0 +1,11 @@ +package eskipfile_test + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/eskipfile/watch_test.go b/eskipfile/watch_test.go index 2a75544da9..39a32e870a 100644 --- a/eskipfile/watch_test.go +++ b/eskipfile/watch_test.go @@ -10,6 +10,7 @@ import ( "github.com/zalando/skipper/filters/builtin" "github.com/zalando/skipper/logging/loggingtest" "github.com/zalando/skipper/routing" + "go.uber.org/goleak" ) const testWatchFile = "fixtures/watch-test.eskip" @@ -172,12 +173,16 @@ func (t *watchTest) close() { } func TestWatchInitialFails(t *testing.T) { + defer goleak.VerifyNone(t) + test := initWatchTest(t) defer test.close() test.timeoutInitial() } func TestWatchInitialRecovers(t *testing.T) { + defer goleak.VerifyNone(t) + test := initWatchTest(t) defer test.close() test.timeoutInitial() @@ -187,6 +192,8 @@ func TestWatchInitialRecovers(t *testing.T) { } func TestWatchUpdateFails(t *testing.T) { + defer goleak.VerifyNone(t) + createFile(t) defer deleteFile(t) test := initWatchTest(t) @@ -197,6 +204,8 @@ func TestWatchUpdateFails(t *testing.T) { } func TestWatchUpdateRecover(t *testing.T) { + defer goleak.VerifyNone(t) + createFile(t) defer deleteFile(t) test := initWatchTest(t) @@ -209,6 +218,8 @@ func TestWatchUpdateRecover(t *testing.T) { } func TestInitialAndUnchanged(t *testing.T) { + defer goleak.VerifyNone(t) + createFile(t) defer deleteFile(t) test := initWatchTest(t) @@ -218,6 +229,8 @@ func TestInitialAndUnchanged(t *testing.T) { } func TestInitialAndDeleteFile(t *testing.T) { + defer goleak.VerifyNone(t) + createFile(t) defer deleteFile(t) test := initWatchTest(t) @@ -228,6 +241,8 @@ func TestInitialAndDeleteFile(t *testing.T) { } func TestWatchUpdate(t *testing.T) { + defer goleak.VerifyNone(t) + createFile(t) defer deleteFile(t) test := initWatchTest(t) diff --git a/filters/serve/serve_test.go b/filters/serve/serve_test.go index e0a735d660..7aa6aa49a2 100644 --- a/filters/serve/serve_test.go +++ b/filters/serve/serve_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/zalando/skipper/filters/filtertest" + "go.uber.org/goleak" ) const testDelay = 12 * time.Millisecond @@ -95,6 +96,8 @@ func TestBlock(t *testing.T) { } func TestServe(t *testing.T) { + defer goleak.VerifyNone(t) + parts := []string{"foo", "bar", "baz"} ctx := &filtertest.Context{FRequest: &http.Request{}} ServeHTTP(ctx, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/go.mod b/go.mod index 1caef27bd9..277794be20 100644 --- a/go.mod +++ b/go.mod @@ -43,6 +43,7 @@ require ( github.com/yookoala/gofast v0.6.0 github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 go.uber.org/atomic v1.9.0 + go.uber.org/goleak v1.1.12 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 diff --git a/go.sum b/go.sum index 08154861dc..25761c2b09 100644 --- a/go.sum +++ b/go.sum @@ -958,6 +958,7 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= @@ -1008,6 +1009,7 @@ golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=