diff --git a/pkg/commands/compute/metadata_test.go b/pkg/commands/compute/metadata_test.go index dd276a5a9..d3ac994cb 100644 --- a/pkg/commands/compute/metadata_test.go +++ b/pkg/commands/compute/metadata_test.go @@ -1,7 +1,6 @@ package compute_test import ( - "bytes" "os" "path/filepath" "testing" @@ -13,6 +12,7 @@ import ( "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/revision" "github.com/fastly/cli/pkg/testutil" + "github.com/fastly/cli/pkg/threadsafe" ) func TestMetadata(t *testing.T) { @@ -47,7 +47,7 @@ func TestMetadata(t *testing.T) { }, }, WantOutput: "SUCCESS: configuration updated", - Validator: func(t *testing.T, _ *testutil.TestScenario, opts *global.Data, _ bytes.Buffer) { + Validator: func(t *testing.T, _ *testutil.TestScenario, opts *global.Data, _ *threadsafe.Buffer) { data, err := os.ReadFile(opts.ConfigPath) if err != nil { t.Error(err) @@ -80,7 +80,7 @@ func TestMetadata(t *testing.T) { }, }, WantOutput: "SUCCESS: configuration updated", - Validator: func(t *testing.T, _ *testutil.TestScenario, opts *global.Data, _ bytes.Buffer) { + Validator: func(t *testing.T, _ *testutil.TestScenario, opts *global.Data, _ *threadsafe.Buffer) { data, err := os.ReadFile(opts.ConfigPath) if err != nil { t.Error(err) @@ -116,7 +116,7 @@ func TestMetadata(t *testing.T) { "INFO: We will enable all metadata except for the specified `--disable-*` flags", "SUCCESS: configuration updated", }, - Validator: func(t *testing.T, _ *testutil.TestScenario, opts *global.Data, _ bytes.Buffer) { + Validator: func(t *testing.T, _ *testutil.TestScenario, opts *global.Data, _ *threadsafe.Buffer) { data, err := os.ReadFile(opts.ConfigPath) if err != nil { t.Error(err) @@ -152,7 +152,7 @@ func TestMetadata(t *testing.T) { "INFO: We will disable all metadata except for the specified `--enable-*` flags", "SUCCESS: configuration updated", }, - Validator: func(t *testing.T, _ *testutil.TestScenario, opts *global.Data, _ bytes.Buffer) { + Validator: func(t *testing.T, _ *testutil.TestScenario, opts *global.Data, _ *threadsafe.Buffer) { data, err := os.ReadFile(opts.ConfigPath) if err != nil { t.Error(err) diff --git a/pkg/commands/sso/sso_test.go b/pkg/commands/sso/sso_test.go index aa9bb82cf..2d9a66953 100644 --- a/pkg/commands/sso/sso_test.go +++ b/pkg/commands/sso/sso_test.go @@ -1,7 +1,6 @@ package sso_test import ( - "bytes" "errors" "testing" "time" @@ -13,6 +12,7 @@ import ( "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" + "github.com/fastly/cli/pkg/threadsafe" ) func TestSSO(t *testing.T) { @@ -99,7 +99,7 @@ func TestSSO(t *testing.T) { "We need to open your browser to authenticate you.", "Session token (persisted to your local configuration): 123", }, - Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout bytes.Buffer) { + Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout *threadsafe.Buffer) { const expectedToken = "123" userProfile := opts.Config.Profiles["user"] if userProfile.Token != expectedToken { @@ -139,7 +139,7 @@ func TestSSO(t *testing.T) { "We need to open your browser to authenticate you.", "Session token (persisted to your local configuration): 123", }, - Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout bytes.Buffer) { + Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout *threadsafe.Buffer) { const expectedToken = "123" userProfile := opts.Config.Profiles["test_user"] if userProfile.Token != expectedToken { @@ -191,7 +191,7 @@ func TestSSO(t *testing.T) { // "is not a Fastly SSO (Single Sign-On) generated token", "{Latitude:1 Longtitude:2 X:3 Y:4}", }, - Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout bytes.Buffer) { + Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout *threadsafe.Buffer) { const expectedToken = "mock-token" userProfile := opts.Config.Profiles["user"] if userProfile.Token != expectedToken { @@ -221,7 +221,7 @@ func TestSSO(t *testing.T) { }, WantOutput: "Your access token has expired and so has your refresh token.", DontWantOutput: "{Latitude:1 Longtitude:2 X:3 Y:4}", - Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout bytes.Buffer) { + Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout *threadsafe.Buffer) { const expectedToken = "mock-token" userProfile := opts.Config.Profiles["user"] if userProfile.Token != expectedToken { @@ -283,7 +283,7 @@ func TestSSO(t *testing.T) { "Session token (persisted to your local configuration): 123", "{Latitude:1 Longtitude:2 X:3 Y:4}", }, - Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout bytes.Buffer) { + Validator: func(t *testing.T, scenario *testutil.TestScenario, opts *global.Data, stdout *threadsafe.Buffer) { const expectedToken = "123" userProfile := opts.Config.Profiles["user"] if userProfile.Token != expectedToken { diff --git a/pkg/testutil/scenarios.go b/pkg/testutil/scenarios.go index 4504ffe27..1a2c08460 100644 --- a/pkg/testutil/scenarios.go +++ b/pkg/testutil/scenarios.go @@ -1,12 +1,12 @@ package testutil import ( - "bytes" "fmt" "github.com/fastly/cli/pkg/app" "github.com/fastly/cli/pkg/config" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/mock" + "github.com/fastly/cli/pkg/threadsafe" "io" "os" "slices" @@ -54,7 +54,7 @@ type TestScenario struct { Stdin []string // Validator function can perform additional validation on the results // of the scenario - Validator func(t *testing.T, scenario *TestScenario, opts *global.Data, stdout bytes.Buffer) + Validator func(t *testing.T, scenario *TestScenario, opts *global.Data, stdout *threadsafe.Buffer) // WantError will cause the scenario to fail if this string // does not appear in an Error WantError string @@ -95,7 +95,7 @@ func RunScenario(t *testing.T, command []string, scenario TestScenario) { err error fullargs []string rootdir string - stdout bytes.Buffer + stdout threadsafe.Buffer ) if len(scenario.Arg) > 0 { @@ -233,7 +233,7 @@ func RunScenario(t *testing.T, command []string, scenario TestScenario) { } if scenario.Validator != nil { - scenario.Validator(t, &scenario, opts, stdout) + scenario.Validator(t, &scenario, opts, &stdout) } }) }