diff --git a/integration_tests/consensus/consensus_test.go b/integration_tests/consensus/consensus_test.go index 60936090b..8cae8e142 100644 --- a/integration_tests/consensus/consensus_test.go +++ b/integration_tests/consensus/consensus_test.go @@ -15,11 +15,11 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/beholder/beholdertest" commoncap "github.com/smartcontractkit/chainlink-common/pkg/capabilities" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" "github.com/smartcontractkit/chainlink-common/pkg/workflows" events2 "github.com/smartcontractkit/chainlink-protos/workflows/go/events" "github.com/smartcontractkit/chainlink/v2/core/capabilities/integration_tests/framework" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/gateway/handlers/capabilities" "github.com/smartcontractkit/capabilities/integration_tests/utils" @@ -30,10 +30,8 @@ func Test_Consensus(t *testing.T) { ctx := t.Context() beholderTester := beholdertest.NewObserver(t) - lggr := logger.TestLogger(t) - defer func() { - utils.CleanupCapabilitiesDir(lggr) - }() + lggr := logger.Test(t) + t.Cleanup(utils.RemoveCapabilitiesDir(t)) readBalancesWithConfigPath, err := filepath.Abs("./workflow") require.NoError(t, err) diff --git a/integration_tests/cron/cron_test.go b/integration_tests/cron/cron_test.go index d50d3eede..1a721338f 100644 --- a/integration_tests/cron/cron_test.go +++ b/integration_tests/cron/cron_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink/v2/core/capabilities/integration_tests/framework" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/capabilities/integration_tests/utils" ) @@ -27,10 +27,8 @@ type Payload struct { func Test_CronTrigger(t *testing.T) { t.Skip("skipping broken test") ctx := t.Context() - lggr := logger.TestLogger(t) - defer func() { - utils.CleanupCapabilitiesDir(lggr) - }() + lggr := logger.Test(t) + t.Cleanup(utils.RemoveCapabilitiesDir(t)) cronBinary, err := utils.DeployCapability(t, "cron") require.NoError(t, err) diff --git a/integration_tests/cron/setup.go b/integration_tests/cron/setup.go index 622dcb21f..726813750 100644 --- a/integration_tests/cron/setup.go +++ b/integration_tests/cron/setup.go @@ -8,9 +8,9 @@ import ( "github.com/stretchr/testify/require" commoncap "github.com/smartcontractkit/chainlink-common/pkg/capabilities" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" "github.com/smartcontractkit/chainlink/v2/core/capabilities/integration_tests/framework" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/capabilities/integration_tests/utils" ) diff --git a/integration_tests/evm/evm_logtrigger_test.go b/integration_tests/evm/evm_logtrigger_test.go index 1a02285b9..f2b1e3fc3 100644 --- a/integration_tests/evm/evm_logtrigger_test.go +++ b/integration_tests/evm/evm_logtrigger_test.go @@ -21,8 +21,8 @@ import ( "gopkg.in/yaml.v3" "github.com/smartcontractkit/chainlink-common/pkg/beholder/beholdertest" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/stretchr/testify/require" @@ -308,10 +308,8 @@ func assertLogTriggerWorks(t *testing.T, eventName string, workflowName string, verifyNonMatchingIgnored bool) { ctx := t.Context() beholderTester := beholdertest.NewObserver(t) - lggr, obs := logger.TestLoggerObserved(t, zapcore.InfoLevel) // change this to debug to print all logs from the trigger/log poller if needed to debug - defer func() { - utils.CleanupCapabilitiesDir(lggr) - }() + lggr, obs := logger.TestObserved(t, zapcore.InfoLevel) // change this to debug to print all logs from the trigger/log poller if needed to debug + t.Cleanup(utils.RemoveCapabilitiesDir(t)) workflowPath, err := filepath.Abs("./workflow") require.NoError(t, err) diff --git a/integration_tests/load/load_test.go b/integration_tests/load/load_test.go index c999d7061..550f2f99b 100644 --- a/integration_tests/load/load_test.go +++ b/integration_tests/load/load_test.go @@ -137,9 +137,7 @@ func runLoadTest(t *testing.T, numberOfNodes int, f uint8, numberOfWorkflows int ctx := t.Context() lggr := logger.Test(t) - defer func() { - utils.CleanupCapabilitiesDir(lggr) - }() + t.Cleanup(utils.RemoveCapabilitiesDir(t)) targetSink, registerWorkflowOnDon := setupLoadtestDON(ctx, t, lggr, numberOfNodes, f, protocolRoundTime) diff --git a/integration_tests/por/por_test.go b/integration_tests/por/por_test.go index 956b6efeb..7414a9b48 100644 --- a/integration_tests/por/por_test.go +++ b/integration_tests/por/por_test.go @@ -69,9 +69,7 @@ func Test_PORReadbalances(t *testing.T) { ctx := t.Context() lggr := logger.Test(t) - defer func() { - utils.CleanupCapabilitiesDir(lggr) - }() + t.Cleanup(utils.RemoveCapabilitiesDir(t)) readBalancesWithConfigPath, err := filepath.Abs("../../workflows/readbalances-with-config/cmd") require.NoError(t, err) diff --git a/integration_tests/readcontract/readcontract_test.go b/integration_tests/readcontract/readcontract_test.go index 4d10e0d7f..fd19fcca0 100644 --- a/integration_tests/readcontract/readcontract_test.go +++ b/integration_tests/readcontract/readcontract_test.go @@ -16,12 +16,12 @@ import ( beholderpb "github.com/smartcontractkit/chainlink-common/pkg/beholder/pb" commoncap "github.com/smartcontractkit/chainlink-common/pkg/capabilities" "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" kcr "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/capabilities_registry_1_1_0" "github.com/smartcontractkit/chainlink-protos/cre/go/values" "github.com/smartcontractkit/chainlink/v2/core/capabilities/integration_tests/framework" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/registrysyncer" "github.com/smartcontractkit/capabilities/integration_tests/readcontract/contract" @@ -36,11 +36,9 @@ type ReadContractConfig struct { func Test_RemoteReadCapabilityWithoutConsensus(t *testing.T) { t.Skip("no longer supported") ctx := t.Context() - lggr := logger.TestLogger(t) + lggr := logger.Test(t) - defer func() { - utils.CleanupCapabilitiesDir(lggr) - }() + t.Cleanup(utils.RemoveCapabilitiesDir(t)) targetSink := readValueFromContractFunction(ctx, t, lggr, "GetValue", 4) @@ -62,11 +60,9 @@ func Test_RemoteReadCapabilityMisconfiguredContractError(t *testing.T) { beholderTester := tests.Beholder(t) //nolint:staticcheck ctx := t.Context() - lggr := logger.TestLogger(t) + lggr := logger.Test(t) - defer func() { - utils.CleanupCapabilitiesDir(lggr) - }() + t.Cleanup(utils.RemoveCapabilitiesDir(t)) numOfWorkflowNodes := 4 readValueFromContractFunction(ctx, t, lggr, "GetValue2", numOfWorkflowNodes) diff --git a/integration_tests/utils/deploy.go b/integration_tests/utils/deploy.go index 1dff056d7..28da66bc9 100644 --- a/integration_tests/utils/deploy.go +++ b/integration_tests/utils/deploy.go @@ -6,6 +6,7 @@ import ( "path/filepath" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink-common/pkg/logger" @@ -31,9 +32,18 @@ func DeployCapability(t *testing.T, capabilityName string) (string, error) { } // CleanupCapabilitiesDir removes any capabilities built by the test +// Deprecated: Use RemoveCapabilitiesDir func CleanupCapabilitiesDir(lggr logger.Logger) { err := os.RemoveAll(CapabilitiesDir) if err != nil { lggr.Errorf("Failed to remove directory: %v", err) } } + +// RemoveCapabilitiesDir removes any capabilities built by the test. +// To be scheduled on t.CleanUp. +func RemoveCapabilitiesDir(t *testing.T) func() { + return func() { + assert.NoError(t, os.RemoveAll(CapabilitiesDir)) + } +}