From 7cada2c9e8d35486479f8cff1690e409069c0622 Mon Sep 17 00:00:00 2001 From: Otto Bittner Date: Thu, 30 Jun 2022 15:24:36 +0200 Subject: [PATCH] Add goleak to all tests (#227) * Run goleak as part of all tests We are already using goleak in various tests. This commit adds a TestMain to all remaining tests and calls goleak.VerifyTestMain in them. * Add goleak to debugd/deploy package and fix bug. * Run go mod tidy * Fix integration tests * Move goleak invocation for mount integration test * Ignore leak in state integration tests Co-authored-by: Fabian Kammel --- access_manager/access_manager_test.go | 5 +++++ activation/kms/kms_test.go | 5 +++++ activation/kubeadm/kubeadm_test.go | 5 +++++ activation/kubernetesca/kubernetesca_test.go | 5 +++++ activation/server/server_test.go | 5 +++++ cli/internal/azure/autoscaling_node_group_test.go | 5 +++++ cli/internal/azure/client/client_test.go | 5 +++++ cli/internal/cloudcmd/clients_test.go | 9 +++++++++ cli/internal/cmd/cloud_test.go | 9 +++++++++ cli/internal/gcp/autoscaling_node_group_test.go | 5 +++++ cli/internal/gcp/client/client_test.go | 8 ++++++++ cli/internal/proto/client_test.go | 8 ++++++++ cli/internal/vpn/vpn_test.go | 5 +++++ coordinator/cloudprovider/azure/api_test.go | 9 +++++++++ coordinator/cloudprovider/role_test.go | 8 ++++++++ coordinator/diskencryption/diskencryption_test.go | 5 +++++ .../k8sapi/kubectl/client/client_test.go | 5 +++++ .../kubernetes/k8sapi/kubectl/kubectl_test.go | 5 +++++ .../k8sapi/resources/access_manager_test.go | 5 +++++ coordinator/nodestate/nodestate_test.go | 5 +++++ coordinator/role/role_test.go | 5 +++++ coordinator/wireguard/wireguard_test.go | 5 +++++ debugd/coordinator/streamer_test.go | 5 +++++ debugd/debugd/deploy/download_test.go | 8 ++++++++ debugd/debugd/deploy/service.go | 2 +- debugd/debugd/deploy/service_test.go | 14 +++++--------- .../metadata/cloudprovider/cloudprovider_test.go | 8 ++++++++ debugd/debugd/metadata/fallback/fallback_test.go | 5 +++++ debugd/debugd/metadata/scheduler_test.go | 5 +++++ debugd/debugd/server/server_test.go | 5 +++++ hack/go.mod | 1 + hack/go.sum | 3 +++ hack/pcr-reader/main_test.go | 8 ++++++++ internal/attestation/azure/azure_test.go | 5 +++++ internal/attestation/gcp/gcp_test.go | 5 +++++ .../attestation/simulator/simulator_disabled.go | 7 +++++++ internal/attestation/vtpm/vtpm_test.go | 5 +++++ internal/azureshared/appcredentials_test.go | 5 +++++ internal/cloud/cloudtypes/instance_test.go | 5 +++++ internal/config/config_test.go | 5 +++++ internal/deploy/ssh/ssh_test.go | 5 +++++ internal/deploy/user/linux_user_test.go | 5 +++++ internal/file/file_test.go | 5 +++++ internal/gcpshared/metadata_test.go | 5 +++++ internal/grpc/dialer/dialer_test.go | 5 +++++ internal/statuswaiter/statuswaiter_test.go | 5 +++++ internal/watcher/validator_test.go | 8 ++++++++ kms/internal/storage/memfsstroage_test.go | 8 ++++++++ kms/kms/aws/aws_test.go | 8 ++++++++ kms/kms/azure/azure_test.go | 8 ++++++++ kms/kms/cluster/cluster_test.go | 5 +++++ kms/kms/gcp/gcp_test.go | 8 ++++++++ kms/kms/util/crypto_test.go | 5 +++++ kms/setup/setup_test.go | 8 ++++++++ mount/cryptmapper/cryptmapper_test.go | 5 +++++ mount/kms/constellation_test.go | 5 +++++ mount/test/mount_integration_test.go | 3 +++ state/keyservice/keyservice_test.go | 8 ++++++++ state/setup/setup_test.go | 5 +++++ state/test/integration_test.go | 6 ++++++ 60 files changed, 342 insertions(+), 10 deletions(-) diff --git a/access_manager/access_manager_test.go b/access_manager/access_manager_test.go index 35ee3ae22..91eca4731 100644 --- a/access_manager/access_manager_test.go +++ b/access_manager/access_manager_test.go @@ -15,9 +15,14 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" v1 "k8s.io/api/core/v1" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestEvictUser(t *testing.T) { require := require.New(t) assert := assert.New(t) diff --git a/activation/kms/kms_test.go b/activation/kms/kms_test.go index 317744ea4..d82e10cd1 100644 --- a/activation/kms/kms_test.go +++ b/activation/kms/kms_test.go @@ -8,6 +8,7 @@ import ( "github.com/edgelesssys/constellation/internal/logger" "github.com/edgelesssys/constellation/kms/kmsproto" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/test/bufconn" ) @@ -21,6 +22,10 @@ func (c *stubClient) GetDataKey(context.Context, *kmsproto.GetDataKeyRequest, *g return &kmsproto.GetDataKeyResponse{DataKey: c.dataKey}, c.getDataKeyErr } +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestGetDataKey(t *testing.T) { testCases := map[string]struct { client *stubClient diff --git a/activation/kubeadm/kubeadm_test.go b/activation/kubeadm/kubeadm_test.go index f79cb0e14..4796cfa22 100644 --- a/activation/kubeadm/kubeadm_test.go +++ b/activation/kubeadm/kubeadm_test.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" @@ -19,6 +20,10 @@ import ( fakecorev1 "k8s.io/client-go/kubernetes/typed/core/v1/fake" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestGetJoinToken(t *testing.T) { validConf := `apiVersion: v1 kind: Config diff --git a/activation/kubernetesca/kubernetesca_test.go b/activation/kubernetesca/kubernetesca_test.go index eac8e3909..3c0fe8bba 100644 --- a/activation/kubernetesca/kubernetesca_test.go +++ b/activation/kubernetesca/kubernetesca_test.go @@ -18,8 +18,13 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestGetCertificate(t *testing.T) { ecCert, ecKey := mustCreateCert(mustCreateECKey) rsaCert, rsaKey := mustCreateCert(mustCreateRSAKey) diff --git a/activation/server/server_test.go b/activation/server/server_test.go index 83ec558fe..e14a89f30 100644 --- a/activation/server/server_test.go +++ b/activation/server/server_test.go @@ -16,9 +16,14 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" kubeadmv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestActivateNode(t *testing.T) { someErr := errors.New("error") testKey := []byte{0x1, 0x2, 0x3} diff --git a/cli/internal/azure/autoscaling_node_group_test.go b/cli/internal/azure/autoscaling_node_group_test.go index 402ce121c..066f6228b 100644 --- a/cli/internal/azure/autoscaling_node_group_test.go +++ b/cli/internal/azure/autoscaling_node_group_test.go @@ -4,8 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestAutoscalingNodeGroup(t *testing.T) { assert := assert.New(t) nodeGroups := AutoscalingNodeGroup("scale-set", 0, 100) diff --git a/cli/internal/azure/client/client_test.go b/cli/internal/azure/client/client_test.go index b4159db99..59bf3eb36 100644 --- a/cli/internal/azure/client/client_test.go +++ b/cli/internal/azure/client/client_test.go @@ -8,8 +8,13 @@ import ( "github.com/edgelesssys/constellation/internal/state" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestSetGetState(t *testing.T) { testCases := map[string]struct { state state.ConstellationState diff --git a/cli/internal/cloudcmd/clients_test.go b/cli/internal/cloudcmd/clients_test.go index b7119cf34..130284488 100644 --- a/cli/internal/cloudcmd/clients_test.go +++ b/cli/internal/cloudcmd/clients_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "strconv" + "testing" azurecl "github.com/edgelesssys/constellation/cli/internal/azure/client" gcpcl "github.com/edgelesssys/constellation/cli/internal/gcp/client" @@ -12,8 +13,16 @@ import ( "github.com/edgelesssys/constellation/internal/cloud/cloudtypes" "github.com/edgelesssys/constellation/internal/gcpshared" "github.com/edgelesssys/constellation/internal/state" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + type fakeAzureClient struct { nodes cloudtypes.Instances coordinators cloudtypes.Instances diff --git a/cli/internal/cmd/cloud_test.go b/cli/internal/cmd/cloud_test.go index 764ca2bdc..958f2a5c4 100644 --- a/cli/internal/cmd/cloud_test.go +++ b/cli/internal/cmd/cloud_test.go @@ -2,12 +2,21 @@ package cmd import ( "context" + "testing" "github.com/edgelesssys/constellation/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/state" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + type stubCloudCreator struct { createCalled bool state state.ConstellationState diff --git a/cli/internal/gcp/autoscaling_node_group_test.go b/cli/internal/gcp/autoscaling_node_group_test.go index d835e4300..6213a1d13 100644 --- a/cli/internal/gcp/autoscaling_node_group_test.go +++ b/cli/internal/gcp/autoscaling_node_group_test.go @@ -4,8 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestAutoscalingNodeGroup(t *testing.T) { assert := assert.New(t) nodeGroups := AutoscalingNodeGroup("some-project", "some-zone", "some-group", 0, 100) diff --git a/cli/internal/gcp/client/client_test.go b/cli/internal/gcp/client/client_test.go index 2bf808296..67bf298c0 100644 --- a/cli/internal/gcp/client/client_test.go +++ b/cli/internal/gcp/client/client_test.go @@ -9,8 +9,16 @@ import ( "github.com/edgelesssys/constellation/internal/state" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestSetGetState(t *testing.T) { testCases := map[string]struct { state state.ConstellationState diff --git a/cli/internal/proto/client_test.go b/cli/internal/proto/client_test.go index 7df4350c2..9a0b33d59 100644 --- a/cli/internal/proto/client_test.go +++ b/cli/internal/proto/client_test.go @@ -12,12 +12,20 @@ import ( "github.com/edgelesssys/constellation/coordinator/state" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/connectivity" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/test/bufconn" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestClose(t *testing.T) { assert := assert.New(t) require := require.New(t) diff --git a/cli/internal/vpn/vpn_test.go b/cli/internal/vpn/vpn_test.go index a3d5620df..a4ba50c46 100644 --- a/cli/internal/vpn/vpn_test.go +++ b/cli/internal/vpn/vpn_test.go @@ -7,9 +7,14 @@ import ( wgquick "github.com/nmiculinic/wg-quick-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestCreate(t *testing.T) { require := require.New(t) diff --git a/coordinator/cloudprovider/azure/api_test.go b/coordinator/cloudprovider/azure/api_test.go index 8daf663f6..edfc39959 100644 --- a/coordinator/cloudprovider/azure/api_test.go +++ b/coordinator/cloudprovider/azure/api_test.go @@ -2,12 +2,21 @@ package azure import ( "context" + "testing" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + type stubIMDSAPI struct { res metadataResponse retrieveErr error diff --git a/coordinator/cloudprovider/role_test.go b/coordinator/cloudprovider/role_test.go index ca5b5de2b..bb2187f4e 100644 --- a/coordinator/cloudprovider/role_test.go +++ b/coordinator/cloudprovider/role_test.go @@ -6,8 +6,16 @@ import ( "github.com/edgelesssys/constellation/coordinator/core" "github.com/edgelesssys/constellation/coordinator/role" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestExtractRole(t *testing.T) { testCases := map[string]struct { metadata map[string]string diff --git a/coordinator/diskencryption/diskencryption_test.go b/coordinator/diskencryption/diskencryption_test.go index d8a4980aa..4e429c681 100644 --- a/coordinator/diskencryption/diskencryption_test.go +++ b/coordinator/diskencryption/diskencryption_test.go @@ -8,8 +8,13 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestOpenClose(t *testing.T) { testCases := map[string]struct { initByNameErr error diff --git a/coordinator/kubernetes/k8sapi/kubectl/client/client_test.go b/coordinator/kubernetes/k8sapi/kubectl/client/client_test.go index b9ca3bde6..9cc871481 100644 --- a/coordinator/kubernetes/k8sapi/kubectl/client/client_test.go +++ b/coordinator/kubernetes/k8sapi/kubectl/client/client_test.go @@ -10,6 +10,7 @@ import ( "github.com/edgelesssys/constellation/coordinator/kubernetes/k8sapi/resources" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/protobuf/proto" apps "k8s.io/api/apps/v1" k8s "k8s.io/api/core/v1" @@ -26,6 +27,10 @@ import ( "k8s.io/client-go/restmapper" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + var ( corev1GV = schema.GroupVersion{Version: "v1"} nginxDeployment = &apps.Deployment{ diff --git a/coordinator/kubernetes/k8sapi/kubectl/kubectl_test.go b/coordinator/kubernetes/k8sapi/kubectl/kubectl_test.go index 93db48777..14095bb64 100644 --- a/coordinator/kubernetes/k8sapi/kubectl/kubectl_test.go +++ b/coordinator/kubernetes/k8sapi/kubectl/kubectl_test.go @@ -6,9 +6,14 @@ import ( "github.com/edgelesssys/constellation/coordinator/kubernetes/k8sapi/resources" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" "k8s.io/cli-runtime/pkg/resource" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + type stubClient struct { applyOneObjectErr error getObjectsInfos []*resource.Info diff --git a/coordinator/kubernetes/k8sapi/resources/access_manager_test.go b/coordinator/kubernetes/k8sapi/resources/access_manager_test.go index f6fb7679e..fdadf627f 100644 --- a/coordinator/kubernetes/k8sapi/resources/access_manager_test.go +++ b/coordinator/kubernetes/k8sapi/resources/access_manager_test.go @@ -5,8 +5,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestAccessManagerMarshalUnmarshal(t *testing.T) { require := require.New(t) assert := assert.New(t) diff --git a/coordinator/nodestate/nodestate_test.go b/coordinator/nodestate/nodestate_test.go index a0694608c..01a8b8349 100644 --- a/coordinator/nodestate/nodestate_test.go +++ b/coordinator/nodestate/nodestate_test.go @@ -9,8 +9,13 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestFromFile(t *testing.T) { testCases := map[string]struct { fileContents string diff --git a/coordinator/role/role_test.go b/coordinator/role/role_test.go index 2d6b224c5..e4ae08f06 100644 --- a/coordinator/role/role_test.go +++ b/coordinator/role/role_test.go @@ -5,8 +5,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestMarshal(t *testing.T) { testCases := map[string]struct { role Role diff --git a/coordinator/wireguard/wireguard_test.go b/coordinator/wireguard/wireguard_test.go index 2f20ce986..93be5fcdb 100644 --- a/coordinator/wireguard/wireguard_test.go +++ b/coordinator/wireguard/wireguard_test.go @@ -7,9 +7,14 @@ import ( "github.com/edgelesssys/constellation/coordinator/peer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestUpdatePeer(t *testing.T) { requirePre := require.New(t) diff --git a/debugd/coordinator/streamer_test.go b/debugd/coordinator/streamer_test.go index 423cdf51a..ca3f434dd 100644 --- a/debugd/coordinator/streamer_test.go +++ b/debugd/coordinator/streamer_test.go @@ -9,8 +9,13 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestWriteStream(t *testing.T) { filename := "testfile" diff --git a/debugd/debugd/deploy/download_test.go b/debugd/debugd/deploy/download_test.go index 382cca982..bbe8be085 100644 --- a/debugd/debugd/deploy/download_test.go +++ b/debugd/debugd/deploy/download_test.go @@ -15,10 +15,18 @@ import ( "github.com/edgelesssys/constellation/internal/grpc/testdialer" "github.com/edgelesssys/constellation/internal/logger" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/protobuf/proto" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestDownloadCoordinator(t *testing.T) { filename := "/opt/coordinator" diff --git a/debugd/debugd/deploy/service.go b/debugd/debugd/deploy/service.go index c1bb6b522..f02125c9b 100644 --- a/debugd/debugd/deploy/service.go +++ b/debugd/debugd/deploy/service.go @@ -86,7 +86,7 @@ func (s *ServiceManager) SystemdAction(ctx context.Context, request ServiceManag return fmt.Errorf("establishing systemd connection: %w", err) } - resultChan := make(chan string) + resultChan := make(chan string, 1) switch request.Action { case Start: _, err = conn.StartUnitContext(ctx, request.Unit, "replace", resultChan) diff --git a/debugd/debugd/deploy/service_test.go b/debugd/debugd/deploy/service_test.go index 0a0a70cd9..c8dc0604e 100644 --- a/debugd/debugd/deploy/service_test.go +++ b/debugd/debugd/deploy/service_test.go @@ -218,26 +218,22 @@ type fakeDbusConn struct { func (f *fakeDbusConn) StartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { f.inputs = append(f.inputs, dbusConnActionInput{name: name, mode: mode}) - go func() { - ch <- f.result - }() + ch <- f.result return f.jobID, f.actionErr } func (f *fakeDbusConn) StopUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { f.inputs = append(f.inputs, dbusConnActionInput{name: name, mode: mode}) - go func() { - ch <- f.result - }() + ch <- f.result + return f.jobID, f.actionErr } func (f *fakeDbusConn) RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { f.inputs = append(f.inputs, dbusConnActionInput{name: name, mode: mode}) - go func() { - ch <- f.result - }() + ch <- f.result + return f.jobID, f.actionErr } diff --git a/debugd/debugd/metadata/cloudprovider/cloudprovider_test.go b/debugd/debugd/metadata/cloudprovider/cloudprovider_test.go index fcdb03a5d..dc851fe53 100644 --- a/debugd/debugd/metadata/cloudprovider/cloudprovider_test.go +++ b/debugd/debugd/metadata/cloudprovider/cloudprovider_test.go @@ -9,8 +9,16 @@ import ( "github.com/edgelesssys/constellation/internal/deploy/ssh" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestDiscoverDebugIPs(t *testing.T) { err := errors.New("some err") diff --git a/debugd/debugd/metadata/fallback/fallback_test.go b/debugd/debugd/metadata/fallback/fallback_test.go index de63cd520..3cdf80cb5 100644 --- a/debugd/debugd/metadata/fallback/fallback_test.go +++ b/debugd/debugd/metadata/fallback/fallback_test.go @@ -5,8 +5,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestDiscoverDebugdIPs(t *testing.T) { assert := assert.New(t) diff --git a/debugd/debugd/metadata/scheduler_test.go b/debugd/debugd/metadata/scheduler_test.go index f2fbd8386..5936361c7 100644 --- a/debugd/debugd/metadata/scheduler_test.go +++ b/debugd/debugd/metadata/scheduler_test.go @@ -10,8 +10,13 @@ import ( "github.com/edgelesssys/constellation/internal/deploy/ssh" "github.com/edgelesssys/constellation/internal/logger" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestSchedulerStart(t *testing.T) { testCases := map[string]struct { fetcher stubFetcher diff --git a/debugd/debugd/server/server_test.go b/debugd/debugd/server/server_test.go index 0fd7a60d8..93a97afe2 100644 --- a/debugd/debugd/server/server_test.go +++ b/debugd/debugd/server/server_test.go @@ -16,10 +16,15 @@ import ( "github.com/edgelesssys/constellation/internal/logger" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestUploadAuthorizedKeys(t *testing.T) { endpoint := "192.0.2.1:4000" diff --git a/hack/go.mod b/hack/go.mod index 26a08f155..adadf469c 100644 --- a/hack/go.mod +++ b/hack/go.mod @@ -43,6 +43,7 @@ require ( github.com/spf13/afero v1.8.2 github.com/spf13/cobra v1.5.0 github.com/stretchr/testify v1.7.1 + go.uber.org/goleak v1.1.12 go.uber.org/zap v1.21.0 google.golang.org/grpc v1.46.2 gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99 diff --git a/hack/go.sum b/hack/go.sum index 81064823f..0383ed5a0 100644 --- a/hack/go.sum +++ b/hack/go.sum @@ -1016,6 +1016,7 @@ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= 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/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= @@ -1079,6 +1080,7 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/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= @@ -1384,6 +1386,7 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/hack/pcr-reader/main_test.go b/hack/pcr-reader/main_test.go index f4e8a4f28..9fbab11f9 100644 --- a/hack/pcr-reader/main_test.go +++ b/hack/pcr-reader/main_test.go @@ -13,8 +13,16 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestExportToFile(t *testing.T) { testCases := map[string]struct { pcrs map[uint32][]byte diff --git a/internal/attestation/azure/azure_test.go b/internal/attestation/azure/azure_test.go index df46b93da..f3fe6184f 100644 --- a/internal/attestation/azure/azure_test.go +++ b/internal/attestation/azure/azure_test.go @@ -10,8 +10,13 @@ import ( "github.com/edgelesssys/constellation/internal/attestation/vtpm" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestAttestation(t *testing.T) { assert := assert.New(t) require := require.New(t) diff --git a/internal/attestation/gcp/gcp_test.go b/internal/attestation/gcp/gcp_test.go index 967b6d9e1..c91f4037c 100644 --- a/internal/attestation/gcp/gcp_test.go +++ b/internal/attestation/gcp/gcp_test.go @@ -10,8 +10,13 @@ import ( "github.com/edgelesssys/constellation/internal/attestation/vtpm" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestAttestation(t *testing.T) { assert := assert.New(t) require := require.New(t) diff --git a/internal/attestation/simulator/simulator_disabled.go b/internal/attestation/simulator/simulator_disabled.go index 4053cd097..962807eea 100644 --- a/internal/attestation/simulator/simulator_disabled.go +++ b/internal/attestation/simulator/simulator_disabled.go @@ -5,8 +5,15 @@ package simulator import ( "io" + "testing" + + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + // OpenSimulatedTPM returns a simulated TPM device. func OpenSimulatedTPM() (io.ReadWriteCloser, error) { panic("simulator not enabled") diff --git a/internal/attestation/vtpm/vtpm_test.go b/internal/attestation/vtpm/vtpm_test.go index 645e770de..f62bb2016 100644 --- a/internal/attestation/vtpm/vtpm_test.go +++ b/internal/attestation/vtpm/vtpm_test.go @@ -4,8 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestNOPTPM(t *testing.T) { assert := assert.New(t) diff --git a/internal/azureshared/appcredentials_test.go b/internal/azureshared/appcredentials_test.go index 416490f8b..5aa9275f3 100644 --- a/internal/azureshared/appcredentials_test.go +++ b/internal/azureshared/appcredentials_test.go @@ -6,8 +6,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestApplicationCredentialsFromURI(t *testing.T) { creds := ApplicationCredentials{ TenantID: "tenant-id", diff --git a/internal/cloud/cloudtypes/instance_test.go b/internal/cloud/cloudtypes/instance_test.go index 429799fa5..f328fafde 100644 --- a/internal/cloud/cloudtypes/instance_test.go +++ b/internal/cloud/cloudtypes/instance_test.go @@ -4,8 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestIDs(t *testing.T) { assert := assert.New(t) testState := testInstances() diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 2cc813268..275c8649d 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -9,8 +9,13 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestDefaultConfig(t *testing.T) { assert := assert.New(t) def := Default() diff --git a/internal/deploy/ssh/ssh_test.go b/internal/deploy/ssh/ssh_test.go index f8220c898..0a6f6642a 100644 --- a/internal/deploy/ssh/ssh_test.go +++ b/internal/deploy/ssh/ssh_test.go @@ -10,8 +10,13 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestDeploySSHAuthorizedKey(t *testing.T) { authorizedKey := UserKey{ Username: "user", diff --git a/internal/deploy/user/linux_user_test.go b/internal/deploy/user/linux_user_test.go index 86f17115c..644916552 100644 --- a/internal/deploy/user/linux_user_test.go +++ b/internal/deploy/user/linux_user_test.go @@ -8,8 +8,13 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestGetLinuxUser(t *testing.T) { username := "user" diff --git a/internal/file/file_test.go b/internal/file/file_test.go index fa71f6e23..eca1eef27 100644 --- a/internal/file/file_test.go +++ b/internal/file/file_test.go @@ -8,9 +8,14 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "gopkg.in/yaml.v3" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestReadJSON(t *testing.T) { type testContent struct { First string diff --git a/internal/gcpshared/metadata_test.go b/internal/gcpshared/metadata_test.go index 730ca1eff..20bc78d3d 100644 --- a/internal/gcpshared/metadata_test.go +++ b/internal/gcpshared/metadata_test.go @@ -4,8 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestSplitProviderID(t *testing.T) { testCases := map[string]struct { providerID string diff --git a/internal/grpc/dialer/dialer_test.go b/internal/grpc/dialer/dialer_test.go index 14892b95c..11ccfa8f0 100644 --- a/internal/grpc/dialer/dialer_test.go +++ b/internal/grpc/dialer/dialer_test.go @@ -10,10 +10,15 @@ import ( "github.com/edgelesssys/constellation/internal/oid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/test/grpc_testing" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestDial(t *testing.T) { testCases := map[string]struct { tls bool diff --git a/internal/statuswaiter/statuswaiter_test.go b/internal/statuswaiter/statuswaiter_test.go index dea4ae5bf..67f650d23 100644 --- a/internal/statuswaiter/statuswaiter_test.go +++ b/internal/statuswaiter/statuswaiter_test.go @@ -13,12 +13,17 @@ import ( "github.com/edgelesssys/constellation/internal/grpc/atlscredentials" "github.com/edgelesssys/constellation/internal/oid" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/grpc/test/bufconn" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestInitializeValidators(t *testing.T) { assert := assert.New(t) diff --git a/internal/watcher/validator_test.go b/internal/watcher/validator_test.go index 80a93663d..faf8bbd09 100644 --- a/internal/watcher/validator_test.go +++ b/internal/watcher/validator_test.go @@ -20,8 +20,16 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestNewUpdateableValidator(t *testing.T) { testCases := map[string]struct { provider string diff --git a/kms/internal/storage/memfsstroage_test.go b/kms/internal/storage/memfsstroage_test.go index 0ca516e30..45b46e3b2 100644 --- a/kms/internal/storage/memfsstroage_test.go +++ b/kms/internal/storage/memfsstroage_test.go @@ -5,8 +5,16 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestMemMapStorage(t *testing.T) { assert := assert.New(t) diff --git a/kms/kms/aws/aws_test.go b/kms/kms/aws/aws_test.go index ffa0f7ce6..b8de4e98c 100644 --- a/kms/kms/aws/aws_test.go +++ b/kms/kms/aws/aws_test.go @@ -20,8 +20,16 @@ import ( "github.com/edgelesssys/constellation/kms/internal/storage" kmsInterface "github.com/edgelesssys/constellation/kms/kms" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + const ( kekLen = 32 importedPublicKeyLen = 2048 diff --git a/kms/kms/azure/azure_test.go b/kms/kms/azure/azure_test.go index 636363239..48e394b9e 100644 --- a/kms/kms/azure/azure_test.go +++ b/kms/kms/azure/azure_test.go @@ -11,8 +11,16 @@ import ( "github.com/edgelesssys/constellation/kms/internal/storage" "github.com/edgelesssys/constellation/kms/kms" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + type stubAzureClient struct { setSecretCalled bool setSecretErr error diff --git a/kms/kms/cluster/cluster_test.go b/kms/kms/cluster/cluster_test.go index 1148f290b..decb2aacc 100644 --- a/kms/kms/cluster/cluster_test.go +++ b/kms/kms/cluster/cluster_test.go @@ -5,8 +5,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestCoordinatorKMS(t *testing.T) { assert := assert.New(t) kms := &ClusterKMS{} diff --git a/kms/kms/gcp/gcp_test.go b/kms/kms/gcp/gcp_test.go index 0e4bd070e..52977031a 100644 --- a/kms/kms/gcp/gcp_test.go +++ b/kms/kms/gcp/gcp_test.go @@ -10,12 +10,20 @@ import ( "github.com/edgelesssys/constellation/kms/kms/util" "github.com/googleapis/gax-go/v2" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" "google.golang.org/api/option" kmspb "google.golang.org/genproto/googleapis/cloud/kms/v1" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + var testKeyRSA = `-----BEGIN PUBLIC KEY----- MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAu+OepfHCTiTi27nkTGke dn+AIkiM1AIWWDwqfqG85aNulcj60mGQGXIYV8LoEVkyKOhYBIUmJUaVczB4ltqq diff --git a/kms/kms/util/crypto_test.go b/kms/kms/util/crypto_test.go index 0ec4ec311..e9e8f8ed3 100644 --- a/kms/kms/util/crypto_test.go +++ b/kms/kms/util/crypto_test.go @@ -4,8 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestWrapKeyAES(t *testing.T) { assert := assert.New(t) diff --git a/kms/setup/setup_test.go b/kms/setup/setup_test.go index 893e71162..fd4ed6485 100644 --- a/kms/setup/setup_test.go +++ b/kms/setup/setup_test.go @@ -8,8 +8,16 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestGetStore(t *testing.T) { testCases := map[string]struct { uri string diff --git a/mount/cryptmapper/cryptmapper_test.go b/mount/cryptmapper/cryptmapper_test.go index d9544476d..0aed6ce6c 100644 --- a/mount/cryptmapper/cryptmapper_test.go +++ b/mount/cryptmapper/cryptmapper_test.go @@ -8,8 +8,13 @@ import ( "github.com/edgelesssys/constellation/mount/kms" cryptsetup "github.com/martinjungblut/go-cryptsetup" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + type stubCryptDevice struct { deviceName string uuid string diff --git a/mount/kms/constellation_test.go b/mount/kms/constellation_test.go index b4b7b3570..c90101a8d 100644 --- a/mount/kms/constellation_test.go +++ b/mount/kms/constellation_test.go @@ -7,10 +7,15 @@ import ( "github.com/edgelesssys/constellation/coordinator/vpnapi/vpnproto" "github.com/stretchr/testify/assert" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/test/bufconn" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + type stubVPNClient struct { getDataKeyErr error dataKey []byte diff --git a/mount/test/mount_integration_test.go b/mount/test/mount_integration_test.go index 67256d38e..fd1428d32 100644 --- a/mount/test/mount_integration_test.go +++ b/mount/test/mount_integration_test.go @@ -13,6 +13,7 @@ import ( "github.com/edgelesssys/constellation/mount/kms" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "k8s.io/klog/v2" ) @@ -46,6 +47,8 @@ func TestMain(m *testing.M) { klog.InitFlags(nil) defer klog.Flush() + goleak.VerifyTestMain(m) + result := m.Run() os.Exit(result) } diff --git a/state/keyservice/keyservice_test.go b/state/keyservice/keyservice_test.go index be785389d..253a07995 100644 --- a/state/keyservice/keyservice_test.go +++ b/state/keyservice/keyservice_test.go @@ -17,10 +17,18 @@ import ( "github.com/edgelesssys/constellation/state/keyservice/keyproto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/test/bufconn" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) +} + func TestRequestKeyLoop(t *testing.T) { defaultInstance := cloudtypes.Instance{ Name: "test-instance", diff --git a/state/setup/setup_test.go b/state/setup/setup_test.go index d5c39af94..9ac7c1260 100644 --- a/state/setup/setup_test.go +++ b/state/setup/setup_test.go @@ -15,8 +15,13 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" ) +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} + func TestPrepareExistingDisk(t *testing.T) { someErr := errors.New("error") diff --git a/state/test/integration_test.go b/state/test/integration_test.go index 6f9ae88d5..f5229c140 100644 --- a/state/test/integration_test.go +++ b/state/test/integration_test.go @@ -22,6 +22,7 @@ import ( "github.com/martinjungblut/go-cryptsetup" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/grpc" ) @@ -44,6 +45,11 @@ func TestMain(m *testing.M) { os.Exit(1) } + goleak.VerifyTestMain(m, + // https://github.com/census-instrumentation/opencensus-go/issues/1262 + goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), + ) + result := m.Run() os.Exit(result) }