diff --git a/build/ci/golangci.yml b/build/ci/golangci.yml index 78fcad6952..74def5c96a 100644 --- a/build/ci/golangci.yml +++ b/build/ci/golangci.yml @@ -102,6 +102,10 @@ linters-settings: exhaustive: check-generated: true default-signifies-exhaustive: true + testifylint: + disable: + - error-is-as + - go-require # https://golangci-lint.run/usage/linters linters: @@ -147,6 +151,7 @@ linters: - staticcheck - stylecheck - tagliatelle + - testifylint - thelper - tparallel - paralleltest diff --git a/internal/pkg/diff/diff_test.go b/internal/pkg/diff/diff_test.go index cccf414608..6d891e6a24 100644 --- a/internal/pkg/diff/diff_test.go +++ b/internal/pkg/diff/diff_test.go @@ -8,6 +8,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -23,11 +24,11 @@ func TestDiffOnlyInLocal(t *testing.T) { BranchManifest: &model.BranchManifest{BranchKey: branchKey}, Local: &model.Branch{BranchKey: branchKey}, } - assert.NoError(t, projectState.Set(branchState)) + require.NoError(t, projectState.Set(branchState)) d := NewDiffer(projectState) results, err := d.Diff() - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, results.Results, 1) result := results.Results[0] assert.Equal(t, ResultOnlyInLocal, result.State) @@ -43,11 +44,11 @@ func TestDiffOnlyInRemote(t *testing.T) { BranchManifest: &model.BranchManifest{BranchKey: branchKey}, Remote: &model.Branch{BranchKey: branchKey}, } - assert.NoError(t, projectState.Set(branchState)) + require.NoError(t, projectState.Set(branchState)) d := NewDiffer(projectState) results, err := d.Diff() - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, results.Results, 1) result := results.Results[0] assert.Equal(t, ResultOnlyInRemote, result.State) @@ -74,11 +75,11 @@ func TestDiffEqual(t *testing.T) { IsDefault: false, }, } - assert.NoError(t, projectState.Set(branchState)) + require.NoError(t, projectState.Set(branchState)) d := NewDiffer(projectState) results, err := d.Diff() - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, results.Results, 1) result := results.Results[0] assert.Equal(t, ResultEqual, result.State) @@ -106,11 +107,11 @@ func TestDiffNotEqual(t *testing.T) { IsDefault: true, }, } - assert.NoError(t, projectState.Set(branchState)) + require.NoError(t, projectState.Set(branchState)) d := NewDiffer(projectState) results, err := d.Diff() - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, results.Results, 1) result := results.Results[0] assert.Equal(t, ResultNotEqual, result.State) @@ -141,7 +142,7 @@ func TestDiffEqualConfig(t *testing.T) { IsDefault: false, }, } - assert.NoError(t, projectState.Set(branchState)) + require.NoError(t, projectState.Set(branchState)) configKey := model.ConfigKey{ BranchID: 123, @@ -161,11 +162,11 @@ func TestDiffEqualConfig(t *testing.T) { Description: "description", }, } - assert.NoError(t, projectState.Set(configState)) + require.NoError(t, projectState.Set(configState)) d := NewDiffer(projectState) results, err := d.Diff() - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, results.Results, 2) result1 := results.Results[0] assert.Equal(t, ResultEqual, result1.State) @@ -199,7 +200,7 @@ func TestDiffNotEqualConfig(t *testing.T) { IsDefault: false, }, } - assert.NoError(t, projectState.Set(branchState)) + require.NoError(t, projectState.Set(branchState)) configKey := model.ConfigKey{ BranchID: 123, @@ -219,11 +220,11 @@ func TestDiffNotEqualConfig(t *testing.T) { Description: "changed", }, } - assert.NoError(t, projectState.Set(configState)) + require.NoError(t, projectState.Set(configState)) d := NewDiffer(projectState) results, err := d.Diff() - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, results.Results, 2) result1 := results.Results[0] @@ -259,7 +260,7 @@ func TestDiffNotEqualConfigConfiguration(t *testing.T) { IsDefault: false, }, } - assert.NoError(t, projectState.Set(branchState)) + require.NoError(t, projectState.Set(branchState)) configKey := model.ConfigKey{ BranchID: 123, @@ -295,11 +296,11 @@ func TestDiffNotEqualConfigConfiguration(t *testing.T) { }), }, } - assert.NoError(t, projectState.Set(configState)) + require.NoError(t, projectState.Set(configState)) d := NewDiffer(projectState) results, err := d.Diff() - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, results.Results, 2) result1 := results.Results[0] @@ -330,7 +331,7 @@ func TestDiffRelations(t *testing.T) { PathValue: `path/to/target`, }, } - assert.NoError(t, projectState.Set(targetState)) + require.NoError(t, projectState.Set(targetState)) objectKey := fixtures.MockedKey{ ID: `345`, @@ -369,7 +370,7 @@ func TestDiffRelations(t *testing.T) { }, }, } - assert.NoError(t, projectState.Set(objectState)) + require.NoError(t, projectState.Set(objectState)) differ := NewDiffer(projectState) reporter := differ.diffValues(objectState, objectState.Remote.Relations, objectState.Local.Relations, differ.newOptions) @@ -451,7 +452,7 @@ func TestDiffTransformation(t *testing.T) { }, }, } - assert.NoError(t, projectState.Set(configState)) + require.NoError(t, projectState.Set(configState)) // Transformation differ := NewDiffer(projectState) @@ -514,7 +515,7 @@ func TestDiffSharedCode(t *testing.T) { }, }, } - assert.NoError(t, projectState.Set(configRowState)) + require.NoError(t, projectState.Set(configRowState)) // Transformation differ := NewDiffer(projectState) @@ -679,7 +680,7 @@ func TestDiffOrchestration(t *testing.T) { }, }, } - assert.NoError(t, projectState.Set(configState)) + require.NoError(t, projectState.Set(configState)) differ := NewDiffer(projectState) reporter := differ.diffValues(configState, configState.Remote.Orchestration, configState.Local.Orchestration, differ.newOptions) @@ -763,7 +764,7 @@ func TestDiffMap(t *testing.T) { }), }, } - assert.NoError(t, projectState.Set(configState)) + require.NoError(t, projectState.Set(configState)) differ := NewDiffer(projectState) reporter := differ.diffValues(configState, configState.Remote.Content, configState.Local.Content, differ.newOptions) diff --git a/internal/pkg/diff/reporter_test.go b/internal/pkg/diff/reporter_test.go index eec5e061ee..a5aa71de88 100644 --- a/internal/pkg/diff/reporter_test.go +++ b/internal/pkg/diff/reporter_test.go @@ -1,7 +1,6 @@ package diff import ( - "fmt" "reflect" "strings" "testing" @@ -76,7 +75,7 @@ func TestReporterStringsDiff(t *testing.T) { } for i, c := range cases { result := stringsDiff(c.remote, c.local) - assert.Equal(t, c.result, result, fmt.Sprintf(`case "%d"`, i)) + assert.Equal(t, c.result, result, `case "%d"`, i) } } diff --git a/internal/pkg/encoding/json/schema/generate_test.go b/internal/pkg/encoding/json/schema/generate_test.go index baae61c8a8..e01fc75058 100644 --- a/internal/pkg/encoding/json/schema/generate_test.go +++ b/internal/pkg/encoding/json/schema/generate_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" ) @@ -13,7 +14,7 @@ func TestGenerateDocument(t *testing.T) { t.Parallel() document, err := GenerateDocument(getSampleSchema()) documentJSON := json.MustEncodeString(document, true) - assert.NoError(t, err) + require.NoError(t, err) expected := ` { @@ -50,7 +51,7 @@ func TestGenerateDocumentEmptySchema(t *testing.T) { t.Parallel() document, err := GenerateDocument([]byte(`{}`)) documentJSON := json.MustEncodeString(document, true) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "{}\n", documentJSON) } diff --git a/internal/pkg/encoding/json/schema/meta_test.go b/internal/pkg/encoding/json/schema/meta_test.go index fee58125e9..af9ee726c0 100644 --- a/internal/pkg/encoding/json/schema/meta_test.go +++ b/internal/pkg/encoding/json/schema/meta_test.go @@ -5,6 +5,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json/schema" ) @@ -14,7 +15,7 @@ func TestFieldMeta_Empty(t *testing.T) { meta, found, err := schema.FieldMeta([]byte(""), orderedmap.Path{}) assert.Empty(t, meta) assert.False(t, found) - assert.Nil(t, err) + require.NoError(t, err) } func TestFieldMeta_Complex(t *testing.T) { @@ -54,39 +55,39 @@ func TestFieldMeta_Complex(t *testing.T) { meta, found, err := schema.FieldMeta([]byte(componentSchema), orderedmap.Path{}) assert.Empty(t, meta) assert.False(t, found) - assert.Nil(t, err) + require.NoError(t, err) // Not found meta, found, err = schema.FieldMeta([]byte(componentSchema), orderedmap.PathFromStr("foo.bar")) assert.Empty(t, meta) assert.False(t, found) - assert.Nil(t, err) + require.NoError(t, err) // Found object meta, found, err = schema.FieldMeta([]byte(componentSchema), orderedmap.PathFromStr("parameters.db")) assert.NotEmpty(t, meta) assert.True(t, found) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "Database", meta.Title) assert.Equal(t, "", meta.Description) - assert.Equal(t, nil, meta.Default) + assert.Nil(t, meta.Default) assert.False(t, meta.Required) // Found string, required field meta, found, err = schema.FieldMeta([]byte(componentSchema), orderedmap.PathFromStr("parameters.db.#connectionString")) assert.NotEmpty(t, meta) assert.True(t, found) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "Connection String", meta.Title) assert.Equal(t, `Eg. "DefaultEndpointsProtocol=https;...". The value will be encrypted when saved.`, meta.Description) - assert.Equal(t, nil, meta.Default) + assert.Nil(t, meta.Default) assert.True(t, meta.Required) // Found int, default field meta, found, err = schema.FieldMeta([]byte(componentSchema), orderedmap.PathFromStr("parameters.db.limit")) assert.NotEmpty(t, meta) assert.True(t, found) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, "Query Limit", meta.Title) assert.Equal(t, "", meta.Description) assert.Equal(t, "1234", meta.Default) diff --git a/internal/pkg/encoding/json/schema/schema_test.go b/internal/pkg/encoding/json/schema/schema_test.go index 2d0abd0d24..6c6b683a1d 100644 --- a/internal/pkg/encoding/json/schema/schema_test.go +++ b/internal/pkg/encoding/json/schema/schema_test.go @@ -8,6 +8,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" . "github.com/keboola/keboola-as-code/internal/pkg/encoding/json/schema" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/knownpaths" @@ -27,7 +28,7 @@ func TestValidateObjects_Ok(t *testing.T) { }) content := orderedmap.New() content.Set(`parameters`, parameters) - assert.NoError(t, ValidateContent(schema, content)) + require.NoError(t, ValidateContent(schema, content)) } func TestValidateObjects_Error(t *testing.T) { @@ -46,7 +47,7 @@ func TestValidateObjects_Error(t *testing.T) { content := orderedmap.New() content.Set(`parameters`, parameters) err := ValidateContent(schema, content) - assert.Error(t, err) + require.Error(t, err) expectedErr := ` - missing properties: "firstName" - "address": missing properties: "street" @@ -68,7 +69,7 @@ func TestValidateObjects_InvalidSchema_InvalidJSON(t *testing.T) { }), }, })) - assert.Error(t, err) + require.Error(t, err) expected := ` invalid JSON schema: - invalid character '.' looking for beginning of object key string, offset: 2 @@ -209,7 +210,7 @@ func TestValidateObjects_InvalidSchema_InvalidType(t *testing.T) { Value: orderedmap.FromPairs([]orderedmap.Pair{{Key: "key", Value: "value"}}), }, })) - assert.Error(t, err) + require.Error(t, err) expected := ` invalid JSON schema: - allOf failed: @@ -227,7 +228,7 @@ func TestValidateObjects_BooleanRequired(t *testing.T) { // But, for historical reasons, in Keboola components, "required: true" is also used. // In the UI, this causes the drop-down list to not have an empty value. // For this reason,the error should be ignored. - assert.NoError(t, ValidateContent(invalidSchema, orderedmap.FromPairs([]orderedmap.Pair{ + require.NoError(t, ValidateContent(invalidSchema, orderedmap.FromPairs([]orderedmap.Pair{ { Key: "parameters", Value: orderedmap.FromPairs([]orderedmap.Pair{ @@ -242,7 +243,7 @@ func TestValidateObjects_SkipEmpty(t *testing.T) { t.Parallel() schema := getTestSchema() content := orderedmap.New() - assert.NoError(t, ValidateContent(schema, content)) + require.NoError(t, ValidateContent(schema, content)) } func TestValidateObjects_InvalidSchema_Warning1(t *testing.T) { @@ -321,11 +322,11 @@ func testInvalidComponentSchema(t *testing.T, invalidSchema []byte, expectedLogs }, }) registry := state.NewRegistry(knownpaths.NewNop(context.Background()), naming.NewRegistry(), components, model.SortByID) - assert.NoError(t, registry.Set(&model.ConfigState{ + require.NoError(t, registry.Set(&model.ConfigState{ ConfigManifest: &model.ConfigManifest{ConfigKey: model.ConfigKey{ComponentID: componentID}}, Local: &model.Config{Content: someContent}, })) - assert.NoError(t, registry.Set(&model.ConfigRowState{ + require.NoError(t, registry.Set(&model.ConfigRowState{ ConfigRowManifest: &model.ConfigRowManifest{ConfigRowKey: model.ConfigRowKey{ComponentID: componentID}}, Local: &model.ConfigRow{Content: someContent}, })) @@ -333,7 +334,7 @@ func testInvalidComponentSchema(t *testing.T, invalidSchema []byte, expectedLogs // Validate, no error content := orderedmap.New() content.Set(`parameters`, orderedmap.New()) - assert.NoError(t, ValidateObjects(context.Background(), logger, registry)) + require.NoError(t, ValidateObjects(context.Background(), logger, registry)) assert.Equal(t, strings.TrimLeft(expectedLogs, "\n"), logger.AllMessagesTxt()) } diff --git a/internal/pkg/encoding/jsonnet/context_test.go b/internal/pkg/encoding/jsonnet/context_test.go index 4f857202fa..7ec55d8915 100644 --- a/internal/pkg/encoding/jsonnet/context_test.go +++ b/internal/pkg/encoding/jsonnet/context_test.go @@ -11,12 +11,13 @@ import ( "github.com/google/go-jsonnet" "github.com/google/go-jsonnet/ast" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestVmContext_Nil(t *testing.T) { t.Parallel() output, err := Evaluate(`{foo: "bar"}`, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", output) } @@ -24,7 +25,7 @@ func TestVmContext_Empty(t *testing.T) { t.Parallel() ctx := NewContext() output, err := Evaluate(`{foo: "bar"}`, ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", output) } @@ -32,7 +33,7 @@ func TestVmContext_Pretty_False(t *testing.T) { t.Parallel() ctx := NewContext().WithPretty(false) output, err := Evaluate(`{foo: "bar"}`, ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `{"foo":"bar"}`, output) } @@ -87,7 +88,7 @@ func TestVmContext_Complex(t *testing.T) { ` output, err := Evaluate(code, ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, strings.TrimLeft(expected, "\n"), output) } @@ -121,7 +122,7 @@ func TestVmContext_VariablesTypes(t *testing.T) { ` output, err := Evaluate(code, ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, strings.TrimLeft(expected, "\n"), output) } @@ -136,11 +137,11 @@ func TestVmContext_ValueToLiteral_MapArray(t *testing.T) { ctx.registerTo(vm) jsonContent, err := vm.Evaluate(result) - assert.NoError(t, err) + require.NoError(t, err) var evaluatedResult bytes.Buffer err = json.Indent(&evaluatedResult, []byte(jsonContent), "", " ") - assert.NoError(t, err) + require.NoError(t, err) expected := `{ "five": [ @@ -342,7 +343,7 @@ Do() // Evaluate and assert actual, err := Evaluate(code, ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expected, actual) assert.Equal(t, expectedNotifications, notifier.values) } diff --git a/internal/pkg/encoding/jsonnet/fsimporter/fsimporter_test.go b/internal/pkg/encoding/jsonnet/fsimporter/fsimporter_test.go index b2cada40dc..ca339de012 100644 --- a/internal/pkg/encoding/jsonnet/fsimporter/fsimporter_test.go +++ b/internal/pkg/encoding/jsonnet/fsimporter/fsimporter_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet" "github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet/fsimporter" @@ -22,14 +23,14 @@ func TestImporter(t *testing.T) { // File is missing _, err := jsonnet.Evaluate(`import "abc.jsonnet"`, jsonnetCtx) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `jsonnet error: RUNTIME ERROR: missing file "abc.jsonnet"`, err.Error()) // File is found - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("foo/bar/A.jsonnet", `import "B.jsonnet"`))) // relative - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("foo/bar/B.jsonnet", `import "/foo/bar/C.jsonnet"`))) // absolute - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("foo/bar/C.jsonnet", `{some: "value"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("foo/bar/A.jsonnet", `import "B.jsonnet"`))) // relative + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("foo/bar/B.jsonnet", `import "/foo/bar/C.jsonnet"`))) // absolute + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("foo/bar/C.jsonnet", `{some: "value"}`))) out, err := jsonnet.Evaluate(`import "foo/bar/A.jsonnet"`, jsonnetCtx) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "{\n \"some\": \"value\"\n}\n", out) } diff --git a/internal/pkg/encoding/jsonnet/jsonnet_test.go b/internal/pkg/encoding/jsonnet/jsonnet_test.go index 9b4eb810f0..5322102a54 100644 --- a/internal/pkg/encoding/jsonnet/jsonnet_test.go +++ b/internal/pkg/encoding/jsonnet/jsonnet_test.go @@ -5,13 +5,14 @@ import ( "github.com/google/go-jsonnet/ast" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestEvaluate(t *testing.T) { t.Parallel() code := `{ foo: "bar" }` json, err := Evaluate(code, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", json) } @@ -28,7 +29,7 @@ func TestEvaluateAst(t *testing.T) { }, } json, err := EvaluateAst(astNode, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", json) } @@ -36,7 +37,7 @@ func TestFormat(t *testing.T) { t.Parallel() code := `{"foo":"bar"}` jsonnetStr, err := Format(code) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "{ foo: \"bar\" }\n", jsonnetStr) } @@ -60,6 +61,6 @@ func TestToAst(t *testing.T) { t.Parallel() code := `{ foo: "bar" }` astNode, err := ToAst(code, "") - assert.NoError(t, err) + require.NoError(t, err) assert.NotEmpty(t, astNode) } diff --git a/internal/pkg/encoding/jsonnet/nopimporter_test.go b/internal/pkg/encoding/jsonnet/nopimporter_test.go index a9a07966f2..dbd481d3ee 100644 --- a/internal/pkg/encoding/jsonnet/nopimporter_test.go +++ b/internal/pkg/encoding/jsonnet/nopimporter_test.go @@ -4,11 +4,12 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNopImporter(t *testing.T) { t.Parallel() _, err := Evaluate(`import "foo/bar.jsonnet"`, nil) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, "jsonnet error: RUNTIME ERROR: imports are not enabled", err.Error()) } diff --git a/internal/pkg/encoding/jsonnet/visit_test.go b/internal/pkg/encoding/jsonnet/visit_test.go index 42beec7f91..4a683a9a61 100644 --- a/internal/pkg/encoding/jsonnet/visit_test.go +++ b/internal/pkg/encoding/jsonnet/visit_test.go @@ -6,6 +6,7 @@ import ( "github.com/google/go-jsonnet/ast" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestVisitAst(t *testing.T) { @@ -40,7 +41,7 @@ func TestVisitAst(t *testing.T) { // Visit & modify node, err := ToAst(code, "") - assert.NoError(t, err) + require.NoError(t, err) VisitAst(&node, func(nodePtr *ast.Node) { switch v := (*nodePtr).(type) { case *ast.LiteralString: diff --git a/internal/pkg/encoding/jsonnet/vm_test.go b/internal/pkg/encoding/jsonnet/vm_test.go index 0db2e082d2..f3252c8989 100644 --- a/internal/pkg/encoding/jsonnet/vm_test.go +++ b/internal/pkg/encoding/jsonnet/vm_test.go @@ -6,6 +6,7 @@ import ( "github.com/google/go-jsonnet" "github.com/google/go-jsonnet/ast" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestVM_Evaluate(t *testing.T) { @@ -23,11 +24,11 @@ func TestVM_Evaluate(t *testing.T) { vm := pool.Get() out, err := vm.Evaluate("local test = 0; {a: test}", nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `{"a":0}`, out) _, err = vm.Evaluate("{a: test}", nil) - assert.EqualError(t, err, "1:5-9 Unknown variable: test") + require.EqualError(t, err, "1:5-9 Unknown variable: test") } func TestVM_Validate_Simple(t *testing.T) { @@ -44,10 +45,10 @@ func TestVM_Validate_Simple(t *testing.T) { vm := pool.Get() err := vm.Validate("{a: test()}") - assert.EqualError(t, err, "1:5-9 Unknown variable: test") + require.EqualError(t, err, "1:5-9 Unknown variable: test") err = vm.Validate("local test = 0; {a: test()}") - assert.NoError(t, err) + require.NoError(t, err) } func TestVM_Validate_ShadowedGlobal(t *testing.T) { @@ -72,8 +73,8 @@ func TestVM_Validate_ShadowedGlobal(t *testing.T) { vm := pool.Get() err := vm.Validate("{a: test()}") - assert.NoError(t, err) + require.NoError(t, err) err = vm.Validate("local test = 0; {a: test()}") - assert.NoError(t, err) + require.NoError(t, err) } diff --git a/internal/pkg/env/loader_test.go b/internal/pkg/env/loader_test.go index 3bb8500e07..7f721e1e64 100644 --- a/internal/pkg/env/loader_test.go +++ b/internal/pkg/env/loader_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -22,8 +23,8 @@ func TestLoadDotEnv(t *testing.T) { osEnvs := Empty() osEnvs.Set(`FOO1`, `BAR1`) osEnvs.Set(`OS_ONLY`, `123`) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(".env.local", "FOO1=BAR2\nFOO2=BAR2\n"))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(".env", "FOO1=BAZ\nFOO3=BAR3\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(".env.local", "FOO1=BAR2\nFOO2=BAR2\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(".env", "FOO1=BAZ\nFOO3=BAR3\n"))) // Load envs logger.Truncate() @@ -53,7 +54,7 @@ func TestLoadDotEnv_Invalid(t *testing.T) { fs := aferofs.NewMemoryFs(filesystem.WithLogger(logger)) // Write envs to file - assert.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile(".env.local", "invalid"))) + require.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile(".env.local", "invalid"))) // Load envs logger.Truncate() diff --git a/internal/pkg/env/map_test.go b/internal/pkg/env/map_test.go index 61ff61224c..801d7ecd7e 100644 --- a/internal/pkg/env/map_test.go +++ b/internal/pkg/env/map_test.go @@ -5,12 +5,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestEnvMap(t *testing.T) { t.Parallel() m := Empty() - assert.Len(t, m.Keys(), 0) + assert.Empty(t, m.Keys()) // Set m.Set(`abc_def`, `123`) @@ -43,16 +44,16 @@ func TestEnvMap(t *testing.T) { // Unset m.Unset(`ABC_def`) - assert.Len(t, m.Keys(), 0) + assert.Empty(t, m.Keys()) str, err := m.ToString() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, ``, str) // ToString m.Set(`A`, `123`) m.Set(`X`, `Y`) str, err = m.ToString() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "A=123\nX=\"Y\"", str) } @@ -73,12 +74,12 @@ func TestEnvMapFromMap(t *testing.T) { // nolint paralleltest func TestEnvMapFromOs(t *testing.T) { - assert.NoError(t, os.Setenv(`Foo`, `bar`)) // nolint forbidigo + require.NoError(t, os.Setenv(`Foo`, `bar`)) // nolint forbidigo m, err := FromOs() assert.NotNil(t, m) - assert.NoError(t, err) + require.NoError(t, err) str, err := m.ToString() - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, str, `FOO="bar"`) } @@ -96,7 +97,7 @@ func TestEnvMapMerge(t *testing.T) { m1.Merge(m2, false) // overwrite = false str, err := m1.ToString() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "A=1\nB=2\nC=30", str) } @@ -114,6 +115,6 @@ func TestEnvMapMergeOverwrite(t *testing.T) { m1.Merge(m2, true) // overwrite = true str, err := m1.ToString() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "A=1\nB=20\nC=30", str) } diff --git a/internal/pkg/filesystem/aferofs/filesystem_test.go b/internal/pkg/filesystem/aferofs/filesystem_test.go index 037ddb50db..0f270b107f 100644 --- a/internal/pkg/filesystem/aferofs/filesystem_test.go +++ b/internal/pkg/filesystem/aferofs/filesystem_test.go @@ -12,6 +12,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" . "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -24,7 +25,7 @@ func TestLocalFilesystem(t *testing.T) { createFs := func() (filesystem.Fs, log.DebugLogger) { logger := log.NewDebugLogger() fs, err := NewLocalFs(t.TempDir(), filesystem.WithLogger(logger), filesystem.WithWorkingDir(filesystem.Join("my", "dir"))) - assert.NoError(t, err) + require.NoError(t, err) return fs, logger } cases := &testCases{createFs} @@ -48,7 +49,7 @@ func TestMountFilesystem_WithoutMountPoint(t *testing.T) { logger := log.NewDebugLogger() rootFs := NewMemoryFs(filesystem.WithLogger(logger), filesystem.WithWorkingDir(filesystem.Join("my", "dir"))) fs, err := NewMountFs(rootFs, nil) - assert.NoError(t, err) + require.NoError(t, err) return fs, logger } cases := &testCases{createFs} @@ -62,7 +63,7 @@ func TestMountFilesystem_WithMountPoint(t *testing.T) { rootFs := NewMemoryFs(filesystem.WithLogger(logger), filesystem.WithWorkingDir(filesystem.Join("my", "dir"))) mountPointFs := NewMemoryFs(filesystem.WithLogger(logger)) fs, err := NewMountFs(rootFs, []mountfs.MountPoint{mountfs.NewMountPoint(filesystem.Join("sub", "dir1"), mountPointFs)}) - assert.NoError(t, err) + require.NoError(t, err) return fs, logger } cases := &testCases{createFs} @@ -83,7 +84,7 @@ func TestMountFilesystem_WithNestedMountPoint(t *testing.T) { mountfs.NewMountPoint("sub/dir1/dir2", mountPoint2Fs), }, ) - assert.NoError(t, err) + require.NoError(t, err) return fs, logger } cases := &testCases{createFs} @@ -127,7 +128,7 @@ func (*testCases) TestBasePath(t *testing.T, fs filesystem.Fs, _ log.DebugLogger func (*testCases) TestWorkingDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() assert.Equal(t, "my/dir", fs.WorkingDir()) - assert.NoError(t, fs.Mkdir(ctx, "some/dir")) + require.NoError(t, fs.Mkdir(ctx, "some/dir")) fs.SetWorkingDir(ctx, "some/dir") assert.Equal(t, "some/dir", fs.WorkingDir()) fs.SetWorkingDir(ctx, "some/missing") @@ -136,63 +137,63 @@ func (*testCases) TestWorkingDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogg func (*testCases) TestSubDirFs(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("sub/dir1/dir2/file.txt", "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("sub/dir1/dir2/file.txt", "foo\n"))) assert.True(t, fs.IsFile(ctx, `sub/dir1/dir2/file.txt`)) // Empty path is not allowed _, err := fs.SubDirFs(" ") - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `cannot get sub directory " ": path cannot be empty`, err.Error()) // /sub/dir1 subDirFs1, err := fs.SubDirFs(`/sub/dir1`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `/`, subDirFs1.WorkingDir()) assert.Equal(t, filepath.Join(fs.BasePath(), `sub`, `dir1`), subDirFs1.BasePath()) // nolint: forbidigo assert.False(t, subDirFs1.IsFile(ctx, `sub/dir1/dir2/file.txt`)) assert.True(t, subDirFs1.IsFile(ctx, `dir2/file.txt`)) file1, err := subDirFs1.ReadFile(ctx, filesystem.NewFileDef(`dir2/file.txt`)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\n", file1.Content) // /sub/dir1/dir2 subDirFs2, err := subDirFs1.SubDirFs(`/dir2`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `/`, subDirFs2.WorkingDir()) assert.False(t, subDirFs2.IsFile(ctx, `sub/dir1/dir2/file.txt`)) assert.False(t, subDirFs2.IsFile(ctx, `dir2/file.txt`)) assert.True(t, subDirFs2.IsFile(ctx, `file.txt`)) file2, err := subDirFs2.ReadFile(ctx, filesystem.NewFileDef(`file.txt`)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\n", file2.Content) // file subDirFs3, err := subDirFs2.SubDirFs(`/file.txt`) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `cannot get sub directory "file.txt": path "file.txt" is not directory`, err.Error()) assert.Nil(t, subDirFs3) // not found subDirFs4, err := subDirFs2.SubDirFs(`/abc`) - assert.Error(t, err) // msg differs between backends + require.Error(t, err) // msg differs between backends assert.Nil(t, subDirFs4) // check working dir inheritance // original FS has working dir "my/dir" assert.Equal(t, filesystem.Join(`my`, `dir`), fs.WorkingDir()) // create directory "my/dir/foo/bar" - assert.NoError(t, fs.Mkdir(ctx, filesystem.Join(`my`, `dir`, `foo`, `bar`))) + require.NoError(t, fs.Mkdir(ctx, filesystem.Join(`my`, `dir`, `foo`, `bar`))) // get sub FS for "my" dir -> working dir is inherited "dir" subDirFs5, err := fs.SubDirFs(`my`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `dir`, subDirFs5.WorkingDir()) // get sub FS for "my/dir" dir -> working dir is "/" subDirFs6, err := fs.SubDirFs(filesystem.Join(`my`, `dir`)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, ``, subDirFs6.WorkingDir()) // get sub FS for "my/dir/foo/bar" dir -> working dir is "/" subDirFs7, err := fs.SubDirFs(filesystem.Join(`my`, `dir`, `foo`, `bar`)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `/`, subDirFs7.WorkingDir()) } @@ -205,8 +206,8 @@ func (*testCases) TestSetLogger(t *testing.T, fs filesystem.Fs, _ log.DebugLogge func (*testCases) TestWalk(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "sub/dir1/dir2/dir3")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("sub/dir2/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "sub/dir1/dir2/dir3")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("sub/dir2/file.txt", "foo\n"))) paths := make([]string, 0) root := "." @@ -216,11 +217,11 @@ func (*testCases) TestWalk(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { return nil } - assert.NoError(t, err) + require.NoError(t, err) paths = append(paths, path) return err }) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []string{ `sub`, `sub/dir1`, @@ -233,41 +234,41 @@ func (*testCases) TestWalk(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { func (*testCases) TestGlob(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "foo\n"))) matches, err := fs.Glob(ctx, `my/abc/*`) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, matches) matches, err = fs.Glob(ctx, `my/*`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []string{`my/dir1`, `my/dir2`}, matches) matches, err = fs.Glob(ctx, `my/*/*`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []string{`my/dir2/file.txt`}, matches) matches, err = fs.Glob(ctx, `my/*/*.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []string{`my/dir2/file.txt`}, matches) } func (*testCases) TestStat(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir/file.txt", "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir/file.txt", "foo\n"))) s, err := fs.Stat(ctx, `my/dir/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, s.IsDir()) } func (*testCases) TestReadDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir/subdir")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir/subdir")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir/file.txt", "foo\n"))) items, err := fs.ReadDir(ctx, `my/dir`) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, items, 2) } @@ -275,7 +276,7 @@ func (*testCases) TestExists(t *testing.T, fs filesystem.Fs, logger log.DebugLog ctx := context.Background() // Create file filePath := "file.txt" - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filePath, "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filePath, "foo\n"))) // Assert logger.Truncate() @@ -286,8 +287,8 @@ func (*testCases) TestExists(t *testing.T, fs filesystem.Fs, logger log.DebugLog func (*testCases) TestIsFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir/file.txt", "foo\n"))) // Assert assert.True(t, fs.IsFile(ctx, "my/dir/file.txt")) @@ -297,8 +298,8 @@ func (*testCases) TestIsFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) func (*testCases) TestIsDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir/file.txt", "foo\n"))) // Assert assert.True(t, fs.IsDir(ctx, "my/dir")) @@ -309,63 +310,63 @@ func (*testCases) TestIsDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { func (*testCases) TestCreate(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() fd, err := fs.Create(ctx, `file.txt`) - assert.NoError(t, err) + require.NoError(t, err) n, err := fd.WriteString("foo\n") assert.Equal(t, 4, n) - assert.NoError(t, err) - assert.NoError(t, fd.Close()) + require.NoError(t, err) + require.NoError(t, fd.Close()) file, err := fs.ReadFile(ctx, filesystem.NewFileDef("file.txt")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\n", file.Content) } func (*testCases) TestOpen(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`file.txt`, "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`file.txt`, "foo\n"))) fd, err := fs.Open(ctx, `file.txt`) - assert.NoError(t, err) + require.NoError(t, err) content, err := io.ReadAll(fd) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\n", string(content)) - assert.NoError(t, fd.Close()) + require.NoError(t, fd.Close()) } func (*testCases) TestOpenFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`file.txt`, "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`file.txt`, "foo\n"))) fd, err := fs.OpenFile(ctx, `file.txt`, os.O_RDONLY, 0o600) - assert.NoError(t, err) + require.NoError(t, err) content, err := io.ReadAll(fd) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\n", string(content)) - assert.NoError(t, fd.Close()) + require.NoError(t, fd.Close()) } func (*testCases) TestMkdir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() assert.False(t, fs.Exists(ctx, "my/dir")) - assert.NoError(t, fs.Mkdir(ctx, "my/dir")) + require.NoError(t, fs.Mkdir(ctx, "my/dir")) assert.True(t, fs.Exists(ctx, "my/dir")) - assert.NoError(t, fs.Mkdir(ctx, "my/dir")) + require.NoError(t, fs.Mkdir(ctx, "my/dir")) assert.True(t, fs.Exists(ctx, "my/dir")) } func (*testCases) TestCopyFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.Mkdir(ctx, "my/dir2")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.Mkdir(ctx, "my/dir2")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.False(t, fs.Exists(ctx, "my/dir2/file.txt")) - assert.NoError(t, fs.Copy(ctx, "my/dir1/file.txt", "my/dir2/file.txt")) + require.NoError(t, fs.Copy(ctx, "my/dir1/file.txt", "my/dir2/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) @@ -373,31 +374,31 @@ func (*testCases) TestCopyFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger func (*testCases) TestCopyFileExists(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.Mkdir(ctx, "my/dir2")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "bar\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.Mkdir(ctx, "my/dir2")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "bar\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) err := fs.Copy(ctx, "my/dir1/file.txt", "my/dir2/file.txt") - assert.Error(t, err) + require.Error(t, err) assert.True(t, strings.HasPrefix(err.Error(), `cannot copy "my/dir1/file.txt" -> "my/dir2/file.txt": destination exists`)) } func (*testCases) TestCopyForce(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.Mkdir(ctx, "my/dir2")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "bar\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.Mkdir(ctx, "my/dir2")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "bar\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) - assert.NoError(t, fs.CopyForce(ctx, "my/dir1/file.txt", "my/dir2/file.txt")) + require.NoError(t, fs.CopyForce(ctx, "my/dir1/file.txt", "my/dir2/file.txt")) file, err := fs.ReadFile(ctx, filesystem.NewFileDef("my/dir2/file.txt")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\n", file.Content) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) @@ -405,13 +406,13 @@ func (*testCases) TestCopyForce(t *testing.T, fs filesystem.Fs, _ log.DebugLogge func (*testCases) TestCopyDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.False(t, fs.Exists(ctx, "my/dir2/file.txt")) - assert.NoError(t, fs.Copy(ctx, "my/dir1", "my/dir2")) + require.NoError(t, fs.Copy(ctx, "my/dir1", "my/dir2")) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) @@ -419,9 +420,9 @@ func (*testCases) TestCopyDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) func (*testCases) TestCopyDirExists(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) - assert.NoError(t, fs.Mkdir(ctx, "my/dir2")) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir2")) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2")) @@ -431,14 +432,14 @@ func (*testCases) TestCopyDirExists(t *testing.T, fs filesystem.Fs, _ log.DebugL func (*testCases) TestMoveFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.Mkdir(ctx, "my/dir2")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.Mkdir(ctx, "my/dir2")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.False(t, fs.Exists(ctx, "my/dir2/file.txt")) - assert.NoError(t, fs.Move(ctx, "my/dir1/file.txt", "my/dir2/file.txt")) + require.NoError(t, fs.Move(ctx, "my/dir1/file.txt", "my/dir2/file.txt")) assert.False(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) @@ -446,31 +447,31 @@ func (*testCases) TestMoveFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger func (*testCases) TestMoveFileExists(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.Mkdir(ctx, "my/dir2")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "bar\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.Mkdir(ctx, "my/dir2")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "bar\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) err := fs.Move(ctx, "my/dir1/file.txt", "my/dir2/file.txt") - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `cannot move "my/{dir1/file.txt -> dir2/file.txt}": destination exists`, err.Error()) } func (*testCases) TestMoveForce(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.Mkdir(ctx, "my/dir2")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "bar\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.Mkdir(ctx, "my/dir2")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir2/file.txt", "bar\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) - assert.NoError(t, fs.MoveForce(ctx, "my/dir1/file.txt", "my/dir2/file.txt")) + require.NoError(t, fs.MoveForce(ctx, "my/dir1/file.txt", "my/dir2/file.txt")) file, err := fs.ReadFile(ctx, filesystem.NewFileDef("my/dir2/file.txt")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\n", file.Content) assert.False(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) @@ -478,13 +479,13 @@ func (*testCases) TestMoveForce(t *testing.T, fs filesystem.Fs, _ log.DebugLogge func (*testCases) TestMoveDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.False(t, fs.Exists(ctx, "my/dir2/file.txt")) - assert.NoError(t, fs.Move(ctx, "my/dir1", "my/dir2")) + require.NoError(t, fs.Move(ctx, "my/dir1", "my/dir2")) assert.False(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2/file.txt")) @@ -492,9 +493,9 @@ func (*testCases) TestMoveDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) func (*testCases) TestMoveDirExists(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) - assert.NoError(t, fs.Mkdir(ctx, "my/dir2")) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir2")) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) assert.True(t, fs.Exists(ctx, "my/dir2")) @@ -504,39 +505,39 @@ func (*testCases) TestMoveDirExists(t *testing.T, fs filesystem.Fs, _ log.DebugL func (*testCases) TestRemoveFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) assert.True(t, fs.Exists(ctx, "my/dir1/file.txt")) - assert.NoError(t, fs.Remove(ctx, "my/dir1/file.txt")) + require.NoError(t, fs.Remove(ctx, "my/dir1/file.txt")) assert.False(t, fs.Exists(ctx, "my/dir1/file.txt")) } func (*testCases) TestRemoveDir(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Mkdir(ctx, "my/dir1")) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) + require.NoError(t, fs.Mkdir(ctx, "my/dir1")) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("my/dir1/file.txt", "foo\n"))) assert.True(t, fs.Exists(ctx, "my/dir1")) - assert.NoError(t, fs.Remove(ctx, "my/dir1")) + require.NoError(t, fs.Remove(ctx, "my/dir1")) assert.False(t, fs.Exists(ctx, "my/dir1")) } func (*testCases) TestRemoveNotExist(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { ctx := context.Background() - assert.NoError(t, fs.Remove(ctx, "my/dir1/file.txt")) + require.NoError(t, fs.Remove(ctx, "my/dir1/file.txt")) } func (*testCases) TestReadFile(t *testing.T, fs filesystem.Fs, logger log.DebugLogger) { ctx := context.Background() // Create file filePath := "file.txt" - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filePath, "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filePath, "foo\n"))) // Read logger.Truncate() file, err := fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, file) assert.Equal(t, "foo\n", file.Content) logger.AssertJSONMessages(t, `{"level":"debug","message":"Loaded \"file.txt\""}`) @@ -546,7 +547,7 @@ func (*testCases) TestReadFileNotFound(t *testing.T, fs filesystem.Fs, logger lo ctx := context.Background() filePath := "file.txt" file, err := fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, file) assert.True(t, strings.HasPrefix(err.Error(), `missing file "file.txt"`)) assert.Equal(t, "", logger.AllMessages()) @@ -557,12 +558,12 @@ func (*testCases) TestWriteFile(t *testing.T, fs filesystem.Fs, logger log.Debug filePath := "file.txt" // Write - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filePath, "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filePath, "foo\n"))) logger.AssertJSONMessages(t, `{"level":"debug","message":"Saved \"file.txt\""}`) // Read file, err := fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, file) assert.Equal(t, "foo\n", file.Content) } @@ -572,7 +573,7 @@ func (*testCases) TestWriteFileDirNotFound(t *testing.T, fs filesystem.Fs, logge filePath := "my/dir/file.txt" // Write - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filePath, "foo\n"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filePath, "foo\n"))) expectedLogs := ` {"level":"debug","message":"Created directory \"my/dir\""} {"level":"debug","message":"Saved \"my/dir/file.txt\""} @@ -581,7 +582,7 @@ func (*testCases) TestWriteFileDirNotFound(t *testing.T, fs filesystem.Fs, logge // Read - dir is auto created file, err := fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, file) assert.Equal(t, "foo\n", file.Content) } @@ -593,12 +594,12 @@ func (*testCases) TestWriteFile_JsonFile(t *testing.T, fs filesystem.Fs, logger // Write data := orderedmap.New() data.Set(`foo`, `bar`) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewJSONFile(filePath, data))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewJSONFile(filePath, data))) logger.AssertJSONMessages(t, `{"level":"debug","message":"Saved \"file.json\""}`) // Read file, err := fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, file) assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", file.Content) } @@ -610,10 +611,10 @@ func (*testCases) TestCreateOrUpdateFile(t *testing.T, fs filesystem.Fs, _ log.D // Create empty file updated, err := fs.CreateOrUpdateFile(ctx, filesystem.NewFileDef(filePath), []filesystem.FileLine{}) assert.False(t, updated) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, fs.Exists(ctx, filePath)) file, err := fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "", file.Content) // Add some lines @@ -623,11 +624,11 @@ func (*testCases) TestCreateOrUpdateFile(t *testing.T, fs filesystem.Fs, _ log.D {Line: "BAZ1=123\n", Regexp: "^BAZ1="}, {Line: "BAZ2=456\n", Regexp: "^BAZ2=.*$"}, }) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, updated) assert.True(t, fs.Exists(ctx, filePath)) file, err = fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\nbar\nBAZ1=123\nBAZ2=456\n", file.Content) // Update some lines @@ -636,9 +637,9 @@ func (*testCases) TestCreateOrUpdateFile(t *testing.T, fs filesystem.Fs, _ log.D {Line: "BAZ2=new456\n", Regexp: "^BAZ2=.*$"}, }) assert.True(t, updated) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, fs.Exists(ctx, filePath)) file, err = fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "foo\nbar\nBAZ1=new123\nBAZ2=new456\n", file.Content) } diff --git a/internal/pkg/filesystem/aferofs/localfs/localfs_test.go b/internal/pkg/filesystem/aferofs/localfs/localfs_test.go index 3c9ca5f583..1e59ed5cae 100644 --- a/internal/pkg/filesystem/aferofs/localfs/localfs_test.go +++ b/internal/pkg/filesystem/aferofs/localfs/localfs_test.go @@ -4,12 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewLocalFs(t *testing.T) { t.Parallel() projectDir := t.TempDir() fs, err := New(projectDir) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, projectDir, fs.BasePath()) } diff --git a/internal/pkg/filesystem/aferofs/mountfs/mountfs_test.go b/internal/pkg/filesystem/aferofs/mountfs/mountfs_test.go index 9211caafce..bfe9cfdf73 100644 --- a/internal/pkg/filesystem/aferofs/mountfs/mountfs_test.go +++ b/internal/pkg/filesystem/aferofs/mountfs/mountfs_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -33,19 +34,19 @@ func TestMountFs_Rename(t *testing.T) { NewMountPoint(filesystem.Join("/sub/dir1/dir2"), dir2), }, ) - assert.NoError(t, err) + require.NoError(t, err) // Create file - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("/sub/dir1/foo", "abc"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("/sub/dir1/foo", "abc"))) // Move file within mount point - no error - assert.NoError(t, fs.Move(ctx, "/sub/dir1/foo", "/sub/dir1/bar")) + require.NoError(t, fs.Move(ctx, "/sub/dir1/foo", "/sub/dir1/bar")) assert.False(t, fs.IsFile(ctx, "/sub/dir1/foo")) assert.True(t, fs.IsFile(ctx, "/sub/dir1/bar")) // Move file outside mount point - error - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("/sub/dir1/foo", "abc"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("/sub/dir1/foo", "abc"))) err = fs.Move(ctx, "/sub/dir1/foo", "/bar") - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `path "/sub/dir1/foo" cannot be moved outside mount dir "/sub/dir1" to "/bar"`, err.Error()) } diff --git a/internal/pkg/filesystem/aferofs/utils_test.go b/internal/pkg/filesystem/aferofs/utils_test.go index 60260a3629..d0dcf4594c 100644 --- a/internal/pkg/filesystem/aferofs/utils_test.go +++ b/internal/pkg/filesystem/aferofs/utils_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" ) @@ -14,22 +15,22 @@ func TestCopyFs2FsRootToRoot_LocalToMemory(t *testing.T) { ctx := context.Background() tempDir := t.TempDir() localFs, err := NewLocalFs(tempDir) - assert.NoError(t, err) + require.NoError(t, err) memoryFs := NewMemoryFs() // Create files - assert.NoError(t, localFs.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) - assert.NoError(t, localFs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) + require.NoError(t, localFs.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) + require.NoError(t, localFs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) // Copy - assert.NoError(t, CopyFs2Fs(localFs, "", memoryFs, "")) + require.NoError(t, CopyFs2Fs(localFs, "", memoryFs, "")) // Assert file1, err := memoryFs.ReadFile(ctx, filesystem.NewFileDef("foo.txt")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content1", file1.Content) file2, err := memoryFs.ReadFile(ctx, filesystem.NewFileDef(filesystem.Join("my-dir", "bar.txt"))) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content2", file2.Content) } @@ -38,24 +39,24 @@ func TestCopyFs2FsRootToRoot_LocalToLocal(t *testing.T) { ctx := context.Background() tempDir1 := t.TempDir() localFs1, err := NewLocalFs(tempDir1) - assert.NoError(t, err) + require.NoError(t, err) tempDir2 := t.TempDir() localFs2, err := NewLocalFs(tempDir2) - assert.NoError(t, err) + require.NoError(t, err) // Create files - assert.NoError(t, localFs1.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) - assert.NoError(t, localFs1.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) + require.NoError(t, localFs1.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) + require.NoError(t, localFs1.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) // Copy - assert.NoError(t, CopyFs2Fs(localFs1, "", localFs2, "")) + require.NoError(t, CopyFs2Fs(localFs1, "", localFs2, "")) // Assert file1, err := localFs2.ReadFile(ctx, filesystem.NewFileDef("foo.txt")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content1", file1.Content) file2, err := localFs2.ReadFile(ctx, filesystem.NewFileDef(filesystem.Join("my-dir", "bar.txt"))) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content2", file2.Content) } @@ -65,33 +66,33 @@ func TestCopyFs2FsRootToRoot_BaseToBase(t *testing.T) { ctx := context.Background() tempDir1 := t.TempDir() localFs1, err := NewLocalFs(tempDir1) - assert.NoError(t, err) + require.NoError(t, err) subDir1 := filesystem.Join("sub", "dir", "1") - assert.NoError(t, localFs1.Mkdir(ctx, subDir1)) + require.NoError(t, localFs1.Mkdir(ctx, subDir1)) base1, err := localFs1.SubDirFs(subDir1) - assert.NoError(t, err) + require.NoError(t, err) tempDir2 := t.TempDir() localFs2, err := NewLocalFs(tempDir2) - assert.NoError(t, err) + require.NoError(t, err) subDir2 := filesystem.Join("sub", "dir", "2") - assert.NoError(t, localFs2.Mkdir(ctx, subDir2)) + require.NoError(t, localFs2.Mkdir(ctx, subDir2)) base2, err := localFs2.SubDirFs(subDir2) - assert.NoError(t, err) + require.NoError(t, err) // Create files - assert.NoError(t, base1.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) - assert.NoError(t, base1.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) + require.NoError(t, base1.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) + require.NoError(t, base1.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) // Copy - assert.NoError(t, CopyFs2Fs(base1, "", base2, "")) + require.NoError(t, CopyFs2Fs(base1, "", base2, "")) // Assert file1, err := localFs2.ReadFile(ctx, filesystem.NewFileDef(filesystem.Join(subDir2, "foo.txt"))) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content1", file1.Content) file2, err := localFs2.ReadFile(ctx, filesystem.NewFileDef(filesystem.Join(subDir2, "my-dir", "bar.txt"))) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content2", file2.Content) } @@ -102,21 +103,21 @@ func TestCopyFs2FsRootToRoot_MemoryToLocal(t *testing.T) { memoryFs := NewMemoryFs() tempDir := t.TempDir() localFs, err := NewLocalFs(tempDir) - assert.NoError(t, err) + require.NoError(t, err) // Create files - assert.NoError(t, memoryFs.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) - assert.NoError(t, memoryFs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) + require.NoError(t, memoryFs.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) + require.NoError(t, memoryFs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) // Copy - assert.NoError(t, CopyFs2Fs(memoryFs, "/", localFs, "/")) + require.NoError(t, CopyFs2Fs(memoryFs, "/", localFs, "/")) // Assert file1, err := localFs.ReadFile(ctx, filesystem.NewFileDef("foo.txt")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content1", file1.Content) file2, err := localFs.ReadFile(ctx, filesystem.NewFileDef(filesystem.Join("my-dir", "bar.txt"))) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content2", file2.Content) } @@ -128,18 +129,18 @@ func TestCopyFs2FsRootToRoot_MemoryToMemory(t *testing.T) { memoryFs2 := NewMemoryFs() // Create files - assert.NoError(t, memoryFs1.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) - assert.NoError(t, memoryFs1.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) + require.NoError(t, memoryFs1.WriteFile(ctx, filesystem.NewRawFile("foo.txt", "content1"))) + require.NoError(t, memoryFs1.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content2"))) // Copy - assert.NoError(t, CopyFs2Fs(memoryFs1, "/", memoryFs2, "/")) + require.NoError(t, CopyFs2Fs(memoryFs1, "/", memoryFs2, "/")) // Assert file1, err := memoryFs2.ReadFile(ctx, filesystem.NewFileDef("foo.txt")) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content1", file1.Content) file2, err := memoryFs2.ReadFile(ctx, filesystem.NewFileDef(filesystem.Join("my-dir", "bar.txt"))) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content2", file2.Content) } @@ -149,17 +150,17 @@ func TestCopyFs2FsDirToDir(t *testing.T) { ctx := context.Background() tempDir := t.TempDir() localFs, err := NewLocalFs(tempDir) - assert.NoError(t, err) + require.NoError(t, err) memoryFs := NewMemoryFs() // Create files - assert.NoError(t, localFs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content"))) + require.NoError(t, localFs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join("my-dir", "bar.txt"), "content"))) // Copy - assert.NoError(t, CopyFs2Fs(localFs, "my-dir", memoryFs, "my-dir-2")) + require.NoError(t, CopyFs2Fs(localFs, "my-dir", memoryFs, "my-dir-2")) // Assert file, err := memoryFs.ReadFile(ctx, filesystem.NewFileDef(filesystem.Join("my-dir-2", "bar.txt"))) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "content", file.Content) } diff --git a/internal/pkg/filesystem/clifs/clifs_test.go b/internal/pkg/filesystem/clifs/clifs_test.go index 58076fa42d..7eeac63e41 100644 --- a/internal/pkg/filesystem/clifs/clifs_test.go +++ b/internal/pkg/filesystem/clifs/clifs_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/dbt" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" @@ -19,14 +20,14 @@ func TestFindProjectDir(t *testing.T) { projectDir := t.TempDir() metadataDir := filepath.Join(projectDir, filesystem.MetadataDir) - assert.NoError(t, os.MkdirAll(metadataDir, 0o755)) + require.NoError(t, os.MkdirAll(metadataDir, 0o755)) // Working dir is a sub-dir of the project dir workingDir := filepath.Join(projectDir, `foo`, `bar`) - assert.NoError(t, os.MkdirAll(workingDir, 0o755)) + require.NoError(t, os.MkdirAll(workingDir, 0o755)) dir, err := find(context.Background(), log.NewNopLogger(), workingDir) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, projectDir, dir) } @@ -35,14 +36,14 @@ func TestFindDbtDir(t *testing.T) { projectDir := t.TempDir() dbtProjectFile := filepath.Join(projectDir, dbt.ProjectFilePath) - assert.NoError(t, os.WriteFile(dbtProjectFile, []byte("\n"), 0o700)) + require.NoError(t, os.WriteFile(dbtProjectFile, []byte("\n"), 0o700)) // Working dir is a sub-dir of the dbt project dir workingDir := filepath.Join(projectDir, `foo`, `bar`) - assert.NoError(t, os.MkdirAll(workingDir, 0o755)) + require.NoError(t, os.MkdirAll(workingDir, 0o755)) dir, err := find(context.Background(), log.NewNopLogger(), workingDir) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, projectDir, dir) } @@ -50,6 +51,6 @@ func TestFindNothingFound(t *testing.T) { t.Parallel() workingDir := t.TempDir() dir, err := find(context.Background(), log.NewNopLogger(), workingDir) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, workingDir, dir) } diff --git a/internal/pkg/filesystem/file_test.go b/internal/pkg/filesystem/file_test.go index 2f7c370a12..6e16c7a6bc 100644 --- a/internal/pkg/filesystem/file_test.go +++ b/internal/pkg/filesystem/file_test.go @@ -6,6 +6,7 @@ import ( "github.com/google/go-jsonnet/ast" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet" ) @@ -22,7 +23,7 @@ func TestNewRawFile(t *testing.T) { func TestRawFile_ToJsonFile(t *testing.T) { t.Parallel() f, err := NewRawFile(`path`, `{"foo": "bar"}`).ToJSONFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `path`, f.Path()) assert.Equal(t, orderedmap.FromPairs([]orderedmap.Pair{{Key: "foo", Value: "bar"}}), f.Content) } @@ -30,7 +31,7 @@ func TestRawFile_ToJsonFile(t *testing.T) { func TestRawFile_ToJsonnetFile(t *testing.T) { t.Parallel() f, err := NewRawFile(`path`, `{foo:"bar"}`).ToJSONNetFile(nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `path`, f.Path()) assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", jsonnet.MustEvaluateAst(f.Content, nil)) } @@ -50,7 +51,7 @@ func TestJsonFile_ToRawFile(t *testing.T) { m := orderedmap.New() m.Set(`foo`, `bar`) f, err := NewJSONFile(`path`, m).SetDescription(`desc`).ToRawFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `path`, f.Path()) assert.Equal(t, `desc`, f.Description()) assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", f.Content) @@ -61,7 +62,7 @@ func TestJsonFile_ToJsonnetFile(t *testing.T) { m := orderedmap.New() m.Set(`foo`, `bar`) f, err := NewJSONFile(`path.json`, m).ToJsonnetFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `path.jsonnet`, f.Path()) assert.Equal(t, "{\n foo: \"bar\",\n}\n", jsonnet.FormatAst(f.Content)) } @@ -90,7 +91,7 @@ func TestJsonnetFile_ToRawFile(t *testing.T) { } jsonnetFile := NewJsonnetFile(`path`, astNode, nil).SetDescription(`desc`) file, err := jsonnetFile.ToRawFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `path`, file.Path()) assert.Equal(t, `desc`, file.Description()) assert.Equal(t, "{ foo: \"bar\" }\n", file.Content) @@ -111,7 +112,7 @@ func TestJsonnetFile_ToJsonFile(t *testing.T) { jsonnetFile := NewJsonnetFile(`path`, astNode, nil) jsonnetFile.SetDescription(`desc`) jsonFile, err := jsonnetFile.ToJSONFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `path`, jsonFile.Path()) assert.Equal(t, `desc`, jsonFile.Description()) assert.Equal(t, orderedmap.FromPairs([]orderedmap.Pair{{Key: "foo", Value: "bar"}}), jsonFile.Content) @@ -123,7 +124,7 @@ func TestJsonnetFile_ToJsonFile_Variables(t *testing.T) { ctx.ExtVar("myKey", "bar") jsonnetFile := NewJsonnetFile(`path`, jsonnet.MustToAst(`{foo: std.extVar("myKey")}`, ""), ctx) jsonFile, err := jsonnetFile.ToJSONFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, orderedmap.FromPairs([]orderedmap.Pair{{Key: "foo", Value: "bar"}}), jsonFile.Content) } @@ -142,7 +143,7 @@ func TestJsonnetFile_ToRawJsonFile(t *testing.T) { jsonnetFile := NewJsonnetFile(`path`, astNode, nil) jsonnetFile.SetDescription(`desc`) rawJSONFile, err := jsonnetFile.ToJSONRawFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `path`, rawJSONFile.Path()) assert.Equal(t, `desc`, rawJSONFile.Description()) assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", rawJSONFile.Content) diff --git a/internal/pkg/filesystem/filesystem_test.go b/internal/pkg/filesystem/filesystem_test.go index e391f9dce5..3e16d6cb04 100644 --- a/internal/pkg/filesystem/filesystem_test.go +++ b/internal/pkg/filesystem/filesystem_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFromSlash(t *testing.T) { @@ -21,38 +22,38 @@ func TestToSlash(t *testing.T) { func TestRel(t *testing.T) { t.Parallel() out, err := Rel(`foo/bar`, `foo/bar/abc/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "abc/file.txt", out) out, err = Rel(`/foo/bar/../abc`, `/foo/bar/../abc/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file.txt", out) out, err = Rel(`foo/bar/../abc`, `/foo/bar/../abc/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file.txt", out) out, err = Rel(`/foo/bar/../abc`, `foo/bar/../abc/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file.txt", out) } func TestRelFromRootDir(t *testing.T) { t.Parallel() out, err := Rel(`/`, `/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file.txt", out) out, err = Rel(`/`, `/dir/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "dir/file.txt", out) out, err = Rel(``, `/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file.txt", out) out, err = Rel(``, `/dir/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "dir/file.txt", out) out, err = Rel(``, `file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "file.txt", out) out, err = Rel(``, `dir/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "dir/file.txt", out) } @@ -81,11 +82,11 @@ func TestBase(t *testing.T) { func TestMatch(t *testing.T) { t.Parallel() m, err := Match(`foo/*/*/*`, `foo/bar/abc/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, m) m, err = Match(`abc/**`, `foo/bar/abc/file.txt`) - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, m) } diff --git a/internal/pkg/filesystem/knownpaths/paths_test.go b/internal/pkg/filesystem/knownpaths/paths_test.go index eca8fefc44..75dc1441b8 100644 --- a/internal/pkg/filesystem/knownpaths/paths_test.go +++ b/internal/pkg/filesystem/knownpaths/paths_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -17,7 +18,7 @@ func TestKnownPathsEmpty(t *testing.T) { t.Parallel() paths, err := loadKnownPaths(t, "empty") assert.NotNil(t, paths) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, paths.TrackedPaths()) assert.Empty(t, paths.UntrackedPaths()) @@ -31,7 +32,7 @@ func TestKnownPathsIgnoredFile(t *testing.T) { t.Parallel() paths, err := loadKnownPaths(t, "ignored-file") assert.NotNil(t, paths) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, paths.TrackedPaths()) assert.Equal(t, []string{`dir`}, paths.UntrackedPaths()) @@ -51,7 +52,7 @@ func TestKnownPathsFilter(t *testing.T) { // All paths that contain "123-branch" or "extractor" are ignored. // Compare result with result of the TestKnownPathsComplex. - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []string{ "description.md", "main", @@ -64,7 +65,7 @@ func TestKnownPathsComplex(t *testing.T) { t.Parallel() paths, err := loadKnownPaths(t, "complex") assert.NotNil(t, paths) - assert.NoError(t, err) + require.NoError(t, err) // All untracked + hidden nodes ignored assert.Empty(t, paths.TrackedPaths()) @@ -270,7 +271,7 @@ func TestKnownPathsClone(t *testing.T) { paths, err := loadKnownPaths(t, "complex") assert.NotNil(t, paths) - assert.NoError(t, err) + require.NoError(t, err) clone := paths.Clone() assert.NotSame(t, paths, clone) @@ -284,15 +285,15 @@ func TestKnownPathsStateMethods(t *testing.T) { t.Parallel() paths, err := loadKnownPaths(t, "complex") assert.NotNil(t, paths) - assert.NoError(t, err) + require.NoError(t, err) path := `123-branch/extractor/ex-generic-v2` - assert.Equal(t, paths.State(path), Untracked) + assert.Equal(t, Untracked, paths.State(path)) assert.False(t, paths.IsTracked(path)) assert.True(t, paths.IsUntracked(path)) paths.MarkTracked(path) - assert.Equal(t, paths.State(path), Tracked) + assert.Equal(t, Tracked, paths.State(path)) assert.True(t, paths.IsTracked(path)) assert.False(t, paths.IsUntracked(path)) } @@ -301,7 +302,7 @@ func TestKnownPathsUntrackedDirs(t *testing.T) { t.Parallel() paths, err := loadKnownPaths(t, "complex") assert.NotNil(t, paths) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []string{ "123-branch", @@ -326,7 +327,7 @@ func TestKnownPathsUntrackedDirsFrom(t *testing.T) { t.Parallel() paths, err := loadKnownPaths(t, "complex") assert.NotNil(t, paths) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []string{ "main/extractor/ex-generic-v2", @@ -340,6 +341,6 @@ func loadKnownPaths(t *testing.T, fixture string, options ...Option) (*Paths, er testDir := filesystem.Dir(testFile) projectDir := filesystem.Join(testDir, "..", "..", "fixtures", "local", fixture) fs, err := aferofs.NewLocalFs(projectDir) - assert.NoError(t, err) + require.NoError(t, err) return New(context.Background(), fs, options...) } diff --git a/internal/pkg/fixtures/sharedcode.go b/internal/pkg/fixtures/sharedcode.go index a2cda80820..f4966e28bf 100644 --- a/internal/pkg/fixtures/sharedcode.go +++ b/internal/pkg/fixtures/sharedcode.go @@ -5,7 +5,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -23,7 +23,7 @@ func CreateSharedCode(t *testing.T, state model.ObjectStates) (model.ConfigKey, Local: &model.Branch{BranchKey: branchKey}, Remote: &model.Branch{BranchKey: branchKey}, } - assert.NoError(t, state.Set(branchState)) + require.NoError(t, state.Set(branchState)) // Shared code sharedCodeKey := model.ConfigKey{ @@ -53,7 +53,7 @@ func CreateSharedCode(t *testing.T, state model.ObjectStates) (model.ConfigKey, }, }, } - assert.NoError(t, state.Set(sharedCodeState)) + require.NoError(t, state.Set(sharedCodeState)) // Shared code row 1 row1Key := model.ConfigRowKey{ @@ -72,7 +72,7 @@ func CreateSharedCode(t *testing.T, state model.ObjectStates) (model.ConfigKey, Local: &model.ConfigRow{ConfigRowKey: row1Key, Content: orderedmap.New()}, Remote: &model.ConfigRow{ConfigRowKey: row1Key, Content: orderedmap.New()}, } - assert.NoError(t, state.Set(row1State)) + require.NoError(t, state.Set(row1State)) // Shared code row 2 row2Key := model.ConfigRowKey{ @@ -91,6 +91,6 @@ func CreateSharedCode(t *testing.T, state model.ObjectStates) (model.ConfigKey, Local: &model.ConfigRow{ConfigRowKey: row2Key, Content: orderedmap.New()}, Remote: &model.ConfigRow{ConfigRowKey: row2Key, Content: orderedmap.New()}, } - assert.NoError(t, state.Set(row2State)) + require.NoError(t, state.Set(row2State)) return sharedCodeKey, []model.ConfigRowKey{row1Key, row2Key} } diff --git a/internal/pkg/git/remote_test.go b/internal/pkg/git/remote_test.go index 0008478737..dd77b11374 100644 --- a/internal/pkg/git/remote_test.go +++ b/internal/pkg/git/remote_test.go @@ -14,6 +14,7 @@ import ( "github.com/keboola/go-utils/pkg/wildcards" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -32,8 +33,8 @@ func TestGit_Checkout(t *testing.T) { // Copy the git repository to temp tmpDir := t.TempDir() - assert.NoError(t, aferofs.CopyFs2Fs(nil, filepath.Join("test", "repository"), nil, tmpDir)) - assert.NoError(t, os.Rename(filepath.Join(tmpDir, ".gittest"), filepath.Join(tmpDir, ".git"))) + require.NoError(t, aferofs.CopyFs2Fs(nil, filepath.Join("test", "repository"), nil, tmpDir)) + require.NoError(t, os.Rename(filepath.Join(tmpDir, ".gittest"), filepath.Join(tmpDir, ".git"))) gitRepo := fmt.Sprintf("file://%s", tmpDir) // Ctx @@ -43,26 +44,26 @@ func TestGit_Checkout(t *testing.T) { // Checkout fail from a missing repo ref := model.TemplateRepository{URL: "file://some/missing/repo", Ref: "main"} _, err := Checkout(ctx, ref, true, logger) - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, err.Error(), `git repository could not be checked out from "file://some/missing/repo"`) // Checkout fail from a non-existing branch ref = model.TemplateRepository{URL: gitRepo, Ref: "non-existing-ref"} _, err = Checkout(ctx, ref, false, logger) - assert.Error(t, err) + require.Error(t, err) wildcards.Assert(t, `reference "non-existing-ref" not found in the git repository "%s"`, err.Error(), "unexpected output") // Success ref = model.TemplateRepository{URL: gitRepo, Ref: "main"} r, err := Checkout(ctx, ref, false, logger) - assert.NoError(t, err) + require.NoError(t, err) // Get repository FS fs1, unlockFS1 := r.Fs() // Full checkout -> directory is not empty subDirs, err := filesystem.ReadSubDirs(ctx, fs1, "/") - assert.NoError(t, err) + require.NoError(t, err) assert.Greater(t, len(subDirs), 1) // Check if the hash equals to a commit - the git command should return a "commit" message @@ -72,7 +73,7 @@ func TestGit_Checkout(t *testing.T) { cmd.Dir = fs1.BasePath() cmd.Stdout = &stdOut err = cmd.Run() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "commit\n", stdOut.String()) // Test parallel access to FS @@ -81,7 +82,7 @@ func TestGit_Checkout(t *testing.T) { // Test pull _, err = r.Pull(ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, fs1.Exists(ctx, "example-file.txt")) // Test free @@ -102,8 +103,8 @@ func TestGit_Checkout_Sparse(t *testing.T) { // Copy the git repository to temp tmpDir := t.TempDir() - assert.NoError(t, aferofs.CopyFs2Fs(nil, filepath.Join("test", "repository"), nil, tmpDir)) - assert.NoError(t, os.Rename(filepath.Join(tmpDir, ".gittest"), filepath.Join(tmpDir, ".git"))) + require.NoError(t, aferofs.CopyFs2Fs(nil, filepath.Join("test", "repository"), nil, tmpDir)) + require.NoError(t, os.Rename(filepath.Join(tmpDir, ".gittest"), filepath.Join(tmpDir, ".git"))) gitRepo := fmt.Sprintf("file://%s", tmpDir) // Ctx @@ -113,26 +114,26 @@ func TestGit_Checkout_Sparse(t *testing.T) { // Checkout fail from a missing repo ref := model.TemplateRepository{URL: "file://some/missing/repo", Ref: "main"} _, err := Checkout(ctx, ref, true, logger) - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, err.Error(), `git repository could not be checked out from "file://some/missing/repo"`) // Checkout fail from a non-existing branch ref = model.TemplateRepository{URL: gitRepo, Ref: "non-existing-ref"} _, err = Checkout(ctx, ref, true, logger) - assert.Error(t, err) + require.Error(t, err) wildcards.Assert(t, `reference "non-existing-ref" not found in the git repository "%s"`, err.Error(), "unexpected output") // Success ref = model.TemplateRepository{URL: gitRepo, Ref: "main"} r, err := Checkout(ctx, ref, true, logger) - assert.NoError(t, err) + require.NoError(t, err) // Get repository FS fs1, unlockFS1 := r.Fs() // Sparse checkout -> directory is empty subDirs, err := filesystem.ReadSubDirs(ctx, fs1, "/") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, []string{".git"}, subDirs) // Check if the hash equals to a commit - the git command should return a "commit" message @@ -142,7 +143,7 @@ func TestGit_Checkout_Sparse(t *testing.T) { cmd.Dir = fs1.BasePath() cmd.Stdout = &stdOut err = cmd.Run() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "commit\n", stdOut.String()) // Test parallel access to FS @@ -151,7 +152,7 @@ func TestGit_Checkout_Sparse(t *testing.T) { // Test pull _, err = r.Pull(ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, fs1.Exists(ctx, ".git")) // Test free diff --git a/internal/pkg/log/assert_test.go b/internal/pkg/log/assert_test.go index 908c58fdaa..f91e4499ec 100644 --- a/internal/pkg/log/assert_test.go +++ b/internal/pkg/log/assert_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/utils/errors" ) @@ -204,9 +205,9 @@ func TestCompareJsonMessages(t *testing.T) { err := CompareJSONMessages(c.expected, c.actual) if c.err == nil { - assert.NoError(t, err, c.name) + require.NoError(t, err, c.name) } else { - assert.Error(t, err, c.name) + require.Error(t, err, c.name) assert.Equal(t, c.err.Error(), err.Error(), c.name) } } diff --git a/internal/pkg/log/cli_test.go b/internal/pkg/log/cli_test.go index 044cd1fcf3..8fe1d050e7 100644 --- a/internal/pkg/log/cli_test.go +++ b/internal/pkg/log/cli_test.go @@ -9,6 +9,7 @@ import ( "github.com/keboola/go-utils/pkg/wildcards" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/attribute" "github.com/keboola/keboola-as-code/internal/pkg/service/common/ctxattr" @@ -28,7 +29,7 @@ func TestCliLogger_File(t *testing.T) { tempDir := t.TempDir() filePath := filepath.Join(tempDir, "log-file.txt") file, err := NewLogFile(filePath) - assert.NoError(t, err) + require.NoError(t, err) stdout := ioutil.NewAtomicWriter() stderr := ioutil.NewAtomicWriter() @@ -38,7 +39,7 @@ func TestCliLogger_File(t *testing.T) { logger.Info(context.Background(), "Info msg") logger.Warn(context.Background(), "Warn msg") logger.Error(context.Background(), "Error msg") - assert.NoError(t, file.File().Close()) + require.NoError(t, file.File().Close()) // Assert, all levels logged with the level prefix expected := ` @@ -49,7 +50,7 @@ func TestCliLogger_File(t *testing.T) { ` content, err := os.ReadFile(filePath) - assert.NoError(t, err) + require.NoError(t, err) wildcards.Assert(t, expected, string(content)) } @@ -158,7 +159,7 @@ func TestCliLogger_AttributeReplace(t *testing.T) { tempDir := t.TempDir() filePath := filepath.Join(tempDir, "log-file.txt") file, err := NewLogFile(filePath) - assert.NoError(t, err) + require.NoError(t, err) stdout := ioutil.NewAtomicWriter() stderr := ioutil.NewAtomicWriter() @@ -174,7 +175,7 @@ func TestCliLogger_AttributeReplace(t *testing.T) { logger.Infof(ctx, "Info %s ()", "message") logger.Warnf(ctx, "Warn %s ()", "message") logger.Errorf(ctx, "Error %s ()", "message") - assert.NoError(t, file.File().Close()) + require.NoError(t, file.File().Close()) // Assert, all levels logged with the level prefix expected := ` @@ -189,7 +190,7 @@ func TestCliLogger_AttributeReplace(t *testing.T) { ` content, err := os.ReadFile(filePath) - assert.NoError(t, err) + require.NoError(t, err) wildcards.Assert(t, expected, string(content)) expectedOut := "DEBUG\tDebug msg value (4)\nINFO\tInfo msg value (4)\nDEBUG\tDebug message value (4)\nINFO\tInfo message value (4)\n" @@ -204,7 +205,7 @@ func TestCliLogger_WithComponent(t *testing.T) { tempDir := t.TempDir() filePath := filepath.Join(tempDir, "log-file.txt") file, err := NewLogFile(filePath) - assert.NoError(t, err) + require.NoError(t, err) stdout := ioutil.NewAtomicWriter() stderr := ioutil.NewAtomicWriter() @@ -218,7 +219,7 @@ func TestCliLogger_WithComponent(t *testing.T) { logger.Info(ctx, "Info msg") logger.Warn(ctx, "Warn msg") logger.Error(ctx, "Error msg") - assert.NoError(t, file.File().Close()) + require.NoError(t, file.File().Close()) // Assert, all levels logged with the level prefix expected := ` @@ -229,7 +230,7 @@ func TestCliLogger_WithComponent(t *testing.T) { ` content, err := os.ReadFile(filePath) - assert.NoError(t, err) + require.NoError(t, err) wildcards.Assert(t, expected, string(content)) expectedOut := "DEBUG\tDebug msg\nINFO\tInfo msg\n" diff --git a/internal/pkg/mapper/branchmetadata/local_load_test.go b/internal/pkg/mapper/branchmetadata/local_load_test.go index f9d20e044b..ed2204344d 100644 --- a/internal/pkg/mapper/branchmetadata/local_load_test.go +++ b/internal/pkg/mapper/branchmetadata/local_load_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/branchmetadata" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -35,7 +36,7 @@ func TestConfigMetadataMapper_MapAfterLocalLoad(t *testing.T) { } recipe := model.NewLocalLoadRecipe(mockedState.FileLoader(), state.Manifest(), state.Local) - assert.NoError(t, mockedState.Mapper().MapAfterLocalLoad(context.Background(), recipe)) + require.NoError(t, mockedState.Mapper().MapAfterLocalLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) branch := recipe.Object.(*model.Branch) diff --git a/internal/pkg/mapper/branchmetadata/local_save_test.go b/internal/pkg/mapper/branchmetadata/local_save_test.go index ef8c4b3bca..e6be2ac8ab 100644 --- a/internal/pkg/mapper/branchmetadata/local_save_test.go +++ b/internal/pkg/mapper/branchmetadata/local_save_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/branchmetadata" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -32,7 +33,7 @@ func TestConfigMetadataMapper_MapBeforeLocalSave(t *testing.T) { } recipe := model.NewLocalSaveRecipe(state.Manifest(), state.Local, model.NewChangedFields()) - assert.NoError(t, mockedState.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, mockedState.Mapper().MapBeforeLocalSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) branchManifest := recipe.ObjectManifest.(*model.BranchManifest) diff --git a/internal/pkg/mapper/configmetadata/local_load_test.go b/internal/pkg/mapper/configmetadata/local_load_test.go index 7c13e67e65..7a0ca87594 100644 --- a/internal/pkg/mapper/configmetadata/local_load_test.go +++ b/internal/pkg/mapper/configmetadata/local_load_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/configmetadata" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -41,7 +42,7 @@ func TestConfigMetadataMapper_MapAfterLocalLoad(t *testing.T) { } recipe := model.NewLocalLoadRecipe(mockedState.FileLoader(), configState.Manifest(), configState.Local) - assert.NoError(t, mockedState.Mapper().MapAfterLocalLoad(context.Background(), recipe)) + require.NoError(t, mockedState.Mapper().MapAfterLocalLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) config := recipe.Object.(*model.Config) diff --git a/internal/pkg/mapper/configmetadata/local_save_test.go b/internal/pkg/mapper/configmetadata/local_save_test.go index 681eb276ff..11c83ce818 100644 --- a/internal/pkg/mapper/configmetadata/local_save_test.go +++ b/internal/pkg/mapper/configmetadata/local_save_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/configmetadata" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -38,7 +39,7 @@ func TestConfigMetadataMapper_MapBeforeLocalSave(t *testing.T) { } recipe := model.NewLocalSaveRecipe(configState.Manifest(), configState.Local, model.NewChangedFields()) - assert.NoError(t, mockedState.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, mockedState.Mapper().MapBeforeLocalSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) configManifest := recipe.ObjectManifest.(*model.ConfigManifest) diff --git a/internal/pkg/mapper/corefiles/local_load_test.go b/internal/pkg/mapper/corefiles/local_load_test.go index 6236bdcb51..bcc06b4a53 100644 --- a/internal/pkg/mapper/corefiles/local_load_test.go +++ b/internal/pkg/mapper/corefiles/local_load_test.go @@ -8,6 +8,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -33,13 +34,13 @@ func TestLoadCoreFiles(t *testing.T) { // Save files object := &fixtures.MockedObject{} manifest := &fixtures.MockedManifest{} - assert.NoError(t, fs.Mkdir(ctx, manifest.Path())) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(state.NamingGenerator().MetaFilePath(manifest.Path()), metaFile))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(state.NamingGenerator().ConfigFilePath(manifest.Path()), configFile))) + require.NoError(t, fs.Mkdir(ctx, manifest.Path())) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(state.NamingGenerator().MetaFilePath(manifest.Path()), metaFile))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(state.NamingGenerator().ConfigFilePath(manifest.Path()), configFile))) // Call mapper recipe := model.NewLocalLoadRecipe(state.FileLoader(), manifest, object) - assert.NoError(t, state.Mapper().MapAfterLocalLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterLocalLoad(context.Background(), recipe)) // Values are loaded and set assert.Equal(t, &fixtures.MockedObject{ @@ -68,7 +69,7 @@ func TestLoadCoreFiles_SkipChildrenLoadIfParentIsInvalid(t *testing.T) { _, testFile, _, _ := runtime.Caller(0) testDir := filesystem.Dir(testFile) inputDir := filesystem.Join(testDir, `..`, `..`, `fixtures`, `local`, `branch-invalid-meta-json`) - assert.NoError(t, aferofs.CopyFs2Fs(nil, inputDir, fs, ``)) + require.NoError(t, aferofs.CopyFs2Fs(nil, inputDir, fs, ``)) // Setup manifest branchManifest := &model.BranchManifest{ @@ -89,7 +90,7 @@ func TestLoadCoreFiles_SkipChildrenLoadIfParentIsInvalid(t *testing.T) { assert.False(t, configManifest.State().IsInvalid()) assert.False(t, branchManifest.State().IsNotFound()) assert.False(t, configManifest.State().IsNotFound()) - assert.NoError(t, manifest.Records.SetRecords([]model.ObjectManifest{ + require.NoError(t, manifest.Records.SetRecords([]model.ObjectManifest{ branchManifest, configManifest, })) @@ -104,7 +105,7 @@ func TestLoadCoreFiles_SkipChildrenLoadIfParentIsInvalid(t *testing.T) { branch metadata file "main/meta.json" is invalid: - invalid character 'f' looking for beginning of object key string, offset: 3 ` - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, strings.Trim(expectedErr, "\n"), err.Error()) // Check manifest records diff --git a/internal/pkg/mapper/corefiles/local_save_test.go b/internal/pkg/mapper/corefiles/local_save_test.go index 5212db49fc..a05476a0ef 100644 --- a/internal/pkg/mapper/corefiles/local_save_test.go +++ b/internal/pkg/mapper/corefiles/local_save_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" @@ -36,7 +37,7 @@ func TestSaveCoreFiles(t *testing.T) { assert.Empty(t, recipe.Files.All()) // Call mapper - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) // Files are generated expectedFiles := model.NewFilesToSave() diff --git a/internal/pkg/mapper/defaultbucket/local_load_test.go b/internal/pkg/mapper/defaultbucket/local_load_test.go index 1371785503..e31e4ea7d4 100644 --- a/internal/pkg/mapper/defaultbucket/local_load_test.go +++ b/internal/pkg/mapper/defaultbucket/local_load_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -58,7 +59,7 @@ func TestDefaultBucketMapper_MapBeforeLocalLoadConfig(t *testing.T) { }, Local: &model.Branch{BranchKey: branchKey}, } - assert.NoError(t, state.Set(branchState)) + require.NoError(t, state.Set(branchState)) // Config referenced by the default bucket configKey1 := model.ConfigKey{ @@ -85,7 +86,7 @@ func TestDefaultBucketMapper_MapBeforeLocalLoadConfig(t *testing.T) { }), }, } - assert.NoError(t, state.Set(configState1)) + require.NoError(t, state.Set(configState1)) // Config with the input mapping configKey2 := model.ConfigKey{ @@ -105,13 +106,13 @@ func TestDefaultBucketMapper_MapBeforeLocalLoadConfig(t *testing.T) { Content: content, }, } - assert.NoError(t, state.Set(configState2)) + require.NoError(t, state.Set(configState2)) // Invoke changes := model.NewLocalChanges() changes.AddLoaded(configState2) recipe := model.NewLocalLoadRecipe(state.FileLoader(), configState2.ConfigManifest, configState2.Local) - assert.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) // Check warning of missing default bucket config expectedWarnings := ` @@ -139,7 +140,7 @@ func TestDefaultBucketMapper_MapBeforeLocalLoadRow(t *testing.T) { }, Local: &model.Branch{BranchKey: branchKey}, } - assert.NoError(t, state.Set(branchState)) + require.NoError(t, state.Set(branchState)) // Config referenced by the default bucket configKey1 := model.ConfigKey{ @@ -166,7 +167,7 @@ func TestDefaultBucketMapper_MapBeforeLocalLoadRow(t *testing.T) { }), }, } - assert.NoError(t, state.Set(configState1)) + require.NoError(t, state.Set(configState1)) // Config with the input mapping configKey2 := model.ConfigKey{ @@ -184,7 +185,7 @@ func TestDefaultBucketMapper_MapBeforeLocalLoadRow(t *testing.T) { Content: orderedmap.New(), }, } - assert.NoError(t, state.Set(configState2)) + require.NoError(t, state.Set(configState2)) rowKey := model.ConfigRowKey{ BranchID: 123, @@ -209,13 +210,13 @@ func TestDefaultBucketMapper_MapBeforeLocalLoadRow(t *testing.T) { Content: content, }, } - assert.NoError(t, state.Set(rowState)) + require.NoError(t, state.Set(rowState)) // Invoke changes := model.NewLocalChanges() changes.AddLoaded(rowState) recipe := model.NewLocalLoadRecipe(state.FileLoader(), rowState.ConfigRowManifest, rowState.Local) - assert.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) // Check warning of missing default bucket config expectedWarnings := ` diff --git a/internal/pkg/mapper/defaultbucket/local_save_test.go b/internal/pkg/mapper/defaultbucket/local_save_test.go index 6a3ee11cba..6ec5ddb8f5 100644 --- a/internal/pkg/mapper/defaultbucket/local_save_test.go +++ b/internal/pkg/mapper/defaultbucket/local_save_test.go @@ -8,6 +8,7 @@ import ( "github.com/keboola/go-utils/pkg/deepcopy" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -75,7 +76,7 @@ func TestDefaultBucketMapper_MapBeforeLocalSaveConfig(t *testing.T) { }), }, } - assert.NoError(t, state.Set(configState1)) + require.NoError(t, state.Set(configState1)) // Config with the input mapping configKey2 := model.ConfigKey{ @@ -95,12 +96,12 @@ func TestDefaultBucketMapper_MapBeforeLocalSaveConfig(t *testing.T) { Content: content, }, } - assert.NoError(t, state.Set(configState2)) + require.NoError(t, state.Set(configState2)) // Invoke object := deepcopy.Copy(configState2.Local).(*model.Config) recipe := model.NewLocalSaveRecipe(configState2.ConfigManifest, object, model.NewChangedFields()) - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) // Check warning of missing default bucket config expectedWarnings := ` @@ -145,7 +146,7 @@ func TestDefaultBucketMapper_MapBeforeLocalSaveRow(t *testing.T) { }), }, } - assert.NoError(t, state.Set(configState1)) + require.NoError(t, state.Set(configState1)) // Config with the input mapping configKey2 := model.ConfigKey{ @@ -163,7 +164,7 @@ func TestDefaultBucketMapper_MapBeforeLocalSaveRow(t *testing.T) { Content: orderedmap.New(), }, } - assert.NoError(t, state.Set(configState2)) + require.NoError(t, state.Set(configState2)) rowKey := model.ConfigRowKey{ BranchID: 123, @@ -188,13 +189,13 @@ func TestDefaultBucketMapper_MapBeforeLocalSaveRow(t *testing.T) { Content: content, }, } - assert.NoError(t, state.Set(rowState)) + require.NoError(t, state.Set(rowState)) // Invoke object := deepcopy.Copy(rowState.Local).(*model.ConfigRow) recipe := model.NewLocalSaveRecipe(rowState.ConfigRowManifest, object, model.NewChangedFields()) object.Content = content - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) // Check warning of missing default bucket config expectedWarnings := ` diff --git a/internal/pkg/mapper/description/remote_load_test.go b/internal/pkg/mapper/description/remote_load_test.go index 0b0007647c..94ddd2b26f 100644 --- a/internal/pkg/mapper/description/remote_load_test.go +++ b/internal/pkg/mapper/description/remote_load_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -17,6 +18,6 @@ func TestDescriptionMapAfterRemoteLoad(t *testing.T) { object := &model.Config{Description: "foo\nbar\n\r\t ", Content: orderedmap.New()} recipe := model.NewRemoteLoadRecipe(&model.ConfigManifest{}, object) - assert.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) assert.Equal(t, "foo\nbar", object.Description) } diff --git a/internal/pkg/mapper/ignore/remote_test.go b/internal/pkg/mapper/ignore/remote_test.go index 4061b8ad63..81fa4bc07c 100644 --- a/internal/pkg/mapper/ignore/remote_test.go +++ b/internal/pkg/mapper/ignore/remote_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -21,7 +22,7 @@ func TestIgnoreMapper_AfterRemoteOperation_Variables(t *testing.T) { ConfigManifest: &model.ConfigManifest{ConfigKey: targetKey}, Remote: &model.Config{ConfigKey: targetKey}, } - assert.NoError(t, state.Set(targetConfig)) + require.NoError(t, state.Set(targetConfig)) // Variables for target targetVarsKey := model.ConfigKey{BranchID: 1, ComponentID: keboola.VariablesComponentID, ID: "2"} @@ -37,7 +38,7 @@ func TestIgnoreMapper_AfterRemoteOperation_Variables(t *testing.T) { }, }, } - assert.NoError(t, state.Set(targetVars)) + require.NoError(t, state.Set(targetVars)) // Unattached variables unattachedVarsKey := model.ConfigKey{BranchID: 1, ComponentID: keboola.VariablesComponentID, ID: "3"} @@ -45,14 +46,14 @@ func TestIgnoreMapper_AfterRemoteOperation_Variables(t *testing.T) { ConfigManifest: &model.ConfigManifest{ConfigKey: unattachedVarsKey}, Remote: &model.Config{ConfigKey: unattachedVarsKey}, } - assert.NoError(t, state.Set(unattachedVars)) + require.NoError(t, state.Set(unattachedVars)) // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(targetConfig) changes.AddLoaded(targetVars) changes.AddLoaded(unattachedVars) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) logger.AssertJSONMessages(t, `{"level":"debug","message":"Ignored unattached variables config \"branch:1/component:keboola.variables/config:3\""}`) // Unattached variables are removed @@ -73,7 +74,7 @@ func TestIgnoreMapper_AfterRemoteOperation_Scheduler(t *testing.T) { ConfigManifest: &model.ConfigManifest{ConfigKey: targetKey}, Remote: &model.Config{ConfigKey: targetKey}, } - assert.NoError(t, state.Set(targetConfig)) + require.NoError(t, state.Set(targetConfig)) // Valid scheduler validSchedulerKey := model.ConfigKey{BranchID: 1, ComponentID: keboola.SchedulerComponentID, ID: "2"} @@ -89,7 +90,7 @@ func TestIgnoreMapper_AfterRemoteOperation_Scheduler(t *testing.T) { }, }, } - assert.NoError(t, state.Set(validScheduler)) + require.NoError(t, state.Set(validScheduler)) // Ignored scheduler missingTargetKey := model.ConfigKey{BranchID: 1, ComponentID: "keboola.foo-bar", ID: "789"} @@ -106,14 +107,14 @@ func TestIgnoreMapper_AfterRemoteOperation_Scheduler(t *testing.T) { }, }, } - assert.NoError(t, state.Set(ignoredScheduler)) + require.NoError(t, state.Set(ignoredScheduler)) // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(targetConfig) changes.AddLoaded(ignoredScheduler) changes.AddLoaded(validScheduler) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) logger.AssertJSONMessages(t, `{"level":"debug","message":"Ignored scheduler config \"branch:1/component:keboola.scheduler/config:3\", target config \"branch:1/component:keboola.foo-bar/config:789\" not found"}`) // Unattached variables are removed diff --git a/internal/pkg/mapper/mapper_test.go b/internal/pkg/mapper/mapper_test.go index 1fe6fda973..088f39bcff 100644 --- a/internal/pkg/mapper/mapper_test.go +++ b/internal/pkg/mapper/mapper_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -20,7 +21,7 @@ func TestMappers_ForEach_StopOnFailure(t *testing.T) { callOrder = append(callOrder, mapper.(string)) return errors.Errorf(`error %s`, mapper.(string)) }) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `error 1`, err.Error()) assert.Equal(t, []string{`1`}, callOrder) } @@ -33,7 +34,7 @@ func TestMappers_ForEach_DontStopOnFailure(t *testing.T) { callOrder = append(callOrder, mapper.(string)) return errors.Errorf(`error %s`, mapper.(string)) }) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, "- error 1\n- error 2\n- error 3\n- error 4\n- error 5", err.Error()) assert.Equal(t, []string{`1`, `2`, `3`, `4`, `5`}, callOrder) } @@ -46,7 +47,7 @@ func TestMappers_ForEachReverse_StopOnFailure(t *testing.T) { callOrder = append(callOrder, mapper.(string)) return errors.Errorf(`error %s`, mapper.(string)) }) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `error 5`, err.Error()) assert.Equal(t, []string{`5`}, callOrder) } @@ -59,7 +60,7 @@ func TestMappers_ForEachReverse_DontStopOnFailure(t *testing.T) { callOrder = append(callOrder, mapper.(string)) return errors.Errorf(`error %s`, mapper.(string)) }) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, "- error 5\n- error 4\n- error 3\n- error 2\n- error 1", err.Error()) assert.Equal(t, []string{`5`, `4`, `3`, `2`, `1`}, callOrder) } @@ -135,7 +136,7 @@ func invokeLoadLocalFile(t *testing.T, input *filesystem.FileDef, expected files // Default file fs := aferofs.NewMemoryFs(filesystem.WithLogger(logger)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("file.txt", "default"))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("file.txt", "default"))) logger.Truncate() // Create mapper @@ -148,7 +149,7 @@ func invokeLoadLocalFile(t *testing.T, input *filesystem.FileDef, expected files // Invoke output, err := mapper.NewFileLoader(fs).ReadRawFile(ctx, input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expected, output) logger.AssertJSONMessages(t, expectedLogs) } diff --git a/internal/pkg/mapper/orchestrator/local_load_test.go b/internal/pkg/mapper/orchestrator/local_load_test.go index 50c419be47..0368634e90 100644 --- a/internal/pkg/mapper/orchestrator/local_load_test.go +++ b/internal/pkg/mapper/orchestrator/local_load_test.go @@ -8,6 +8,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -62,14 +63,14 @@ func TestMapAfterLocalLoad(t *testing.T) { ), } for _, file := range files { - assert.NoError(t, fs.WriteFile(context.Background(), file)) + require.NoError(t, fs.WriteFile(context.Background(), file)) } logger.Truncate() // Load changes := model.NewLocalChanges() changes.AddLoaded(orchestratorConfigState) - assert.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) // Logs expectedLogs := ` @@ -85,13 +86,13 @@ func TestMapAfterLocalLoad(t *testing.T) { // Check target configs relation rel1, err := target1.Local.Relations.GetOneByType(model.UsedInOrchestratorRelType) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, orchestratorConfigState.ID, rel1.(*model.UsedInOrchestratorRelation).ConfigID) rel2, err := target2.Local.Relations.GetOneByType(model.UsedInOrchestratorRelType) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, orchestratorConfigState.ID, rel2.(*model.UsedInOrchestratorRelation).ConfigID) rel3, err := target3.Local.Relations.GetOneByType(model.UsedInOrchestratorRelType) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, orchestratorConfigState.ID, rel3.(*model.UsedInOrchestratorRelation).ConfigID) // Orchestration @@ -259,16 +260,16 @@ func TestMapAfterLocalLoadError(t *testing.T) { SetDescription(`task config file`), } for _, file := range files { - assert.NoError(t, fs.WriteFile(ctx, file)) + require.NoError(t, fs.WriteFile(ctx, file)) } - assert.NoError(t, fs.Mkdir(ctx, phasesDir+`/002-phase-with-deps`)) + require.NoError(t, fs.Mkdir(ctx, phasesDir+`/002-phase-with-deps`)) logger.Truncate() // Load changes := model.NewLocalChanges() changes.AddLoaded(orchestratorConfigState) err := state.Mapper().AfterLocalOperation(context.Background(), changes) - assert.Error(t, err) + require.Error(t, err) // Assert error expectedError := ` @@ -323,7 +324,7 @@ func TestMapAfterLocalLoadDepsCycle(t *testing.T) { SetDescription(`phase config file`), } for _, file := range files { - assert.NoError(t, fs.WriteFile(ctx, file)) + require.NoError(t, fs.WriteFile(ctx, file)) } logger.Truncate() @@ -331,7 +332,7 @@ func TestMapAfterLocalLoadDepsCycle(t *testing.T) { changes := model.NewLocalChanges() changes.AddLoaded(orchestratorConfigState) err := state.Mapper().AfterLocalOperation(context.Background(), changes) - assert.Error(t, err) + require.Error(t, err) // Assert error expectedError := ` diff --git a/internal/pkg/mapper/orchestrator/local_save_test.go b/internal/pkg/mapper/orchestrator/local_save_test.go index 7b2d13a0c9..96321e36a6 100644 --- a/internal/pkg/mapper/orchestrator/local_save_test.go +++ b/internal/pkg/mapper/orchestrator/local_save_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" @@ -22,7 +23,7 @@ func TestOrchestratorMapper_MapBeforeLocalSave(t *testing.T) { recipe := model.NewLocalSaveRecipe(orchestratorConfigState.Manifest(), orchestratorConfigState.Remote, model.NewChangedFields()) // Save - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Minify JSON + remove file description @@ -36,7 +37,7 @@ func TestOrchestratorMapper_MapBeforeLocalSave(t *testing.T) { } else { var err error fileRaw, err = file.ToRawFile() - assert.NoError(t, err) + require.NoError(t, err) fileRaw.SetDescription(``) } files = append(files, fileRaw) @@ -121,7 +122,7 @@ func TestMapBeforeLocalSaveWarnings(t *testing.T) { recipe := model.NewLocalSaveRecipe(orchestratorConfigState.Manifest(), orchestratorConfigState.Remote, model.NewChangedFields()) // Save - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) expectedWarnings := ` WARN Warning: - Cannot save orchestrator config "branch/other/orchestrator": diff --git a/internal/pkg/mapper/orchestrator/orchestrator_test.go b/internal/pkg/mapper/orchestrator/orchestrator_test.go index 11cc963a30..39c1baad95 100644 --- a/internal/pkg/mapper/orchestrator/orchestrator_test.go +++ b/internal/pkg/mapper/orchestrator/orchestrator_test.go @@ -6,7 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/corefiles" "github.com/keboola/keboola-as-code/internal/pkg/mapper/orchestrator" @@ -43,7 +43,7 @@ func createTargetConfigs(t *testing.T, state *state.State) (*model.ConfigState, Local: &model.Config{ConfigKey: targetConfigKey1}, Remote: &model.Config{ConfigKey: targetConfigKey1}, } - assert.NoError(t, state.Set(targetConfigState1)) + require.NoError(t, state.Set(targetConfigState1)) // Target config 2 targetConfigKey2 := model.ConfigKey{ @@ -61,7 +61,7 @@ func createTargetConfigs(t *testing.T, state *state.State) (*model.ConfigState, Local: &model.Config{ConfigKey: targetConfigKey2}, Remote: &model.Config{ConfigKey: targetConfigKey2}, } - assert.NoError(t, state.Set(targetConfigState2)) + require.NoError(t, state.Set(targetConfigState2)) // Target config 3 targetConfigKey3 := model.ConfigKey{ @@ -79,7 +79,7 @@ func createTargetConfigs(t *testing.T, state *state.State) (*model.ConfigState, Local: &model.Config{ConfigKey: targetConfigKey3}, Remote: &model.Config{ConfigKey: targetConfigKey3}, } - assert.NoError(t, state.Set(targetConfigState3)) + require.NoError(t, state.Set(targetConfigState3)) return targetConfigState1, targetConfigState2, targetConfigState3 } @@ -100,7 +100,7 @@ func createLocalLoadFixtures(t *testing.T, state *state.State) *model.ConfigStat }, Local: &model.Branch{BranchKey: branchKey}, } - assert.NoError(t, state.Set(branchState)) + require.NoError(t, state.Set(branchState)) // Orchestrator config configKey := model.ConfigKey{ @@ -118,7 +118,7 @@ func createLocalLoadFixtures(t *testing.T, state *state.State) *model.ConfigStat Local: &model.Config{ConfigKey: configKey, Content: orderedmap.New()}, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) return configState } @@ -262,7 +262,7 @@ func createLocalSaveFixtures(t *testing.T, state *state.State, createTargets boo }, Local: &model.Branch{BranchKey: branchKey}, } - assert.NoError(t, state.Set(branchState)) + require.NoError(t, state.Set(branchState)) // Orchestrator config configKey := model.ConfigKey{ @@ -284,7 +284,7 @@ func createLocalSaveFixtures(t *testing.T, state *state.State, createTargets boo Orchestration: orchestration, }, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Create targets if !createTargets { @@ -306,7 +306,7 @@ func createLocalSaveFixtures(t *testing.T, state *state.State, createTargets boo }, Remote: &model.Config{ConfigKey: targetConfigKey1}, } - assert.NoError(t, state.Set(targetConfigState1)) + require.NoError(t, state.Set(targetConfigState1)) // Target config 2 targetConfigKey2 := model.ConfigKey{ @@ -323,7 +323,7 @@ func createLocalSaveFixtures(t *testing.T, state *state.State, createTargets boo }, Remote: &model.Config{ConfigKey: targetConfigKey2}, } - assert.NoError(t, state.Set(targetConfigState2)) + require.NoError(t, state.Set(targetConfigState2)) // Target config 3 targetConfigKey3 := model.ConfigKey{ @@ -340,7 +340,7 @@ func createLocalSaveFixtures(t *testing.T, state *state.State, createTargets boo }, Remote: &model.Config{ConfigKey: targetConfigKey3}, } - assert.NoError(t, state.Set(targetConfigState3)) + require.NoError(t, state.Set(targetConfigState3)) return configState } diff --git a/internal/pkg/mapper/orchestrator/parse_phase_test.go b/internal/pkg/mapper/orchestrator/parse_phase_test.go index 8d84cc8384..1ad85feaf7 100644 --- a/internal/pkg/mapper/orchestrator/parse_phase_test.go +++ b/internal/pkg/mapper/orchestrator/parse_phase_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/utils/errors" @@ -161,9 +162,9 @@ func TestParsePhase(t *testing.T) { assert.Equal(t, c.expected, value, desc) assert.Equal(t, c.after, json.MustEncodeString(p.content, false), desc) if c.err == nil { - assert.NoError(t, err, desc) + require.NoError(t, err, desc) } else { - assert.Error(t, err, desc) + require.Error(t, err, desc) assert.Equal(t, c.err.Error(), err.Error(), desc) } } diff --git a/internal/pkg/mapper/orchestrator/parse_task_test.go b/internal/pkg/mapper/orchestrator/parse_task_test.go index a463d9ebe2..dec53a8fd4 100644 --- a/internal/pkg/mapper/orchestrator/parse_task_test.go +++ b/internal/pkg/mapper/orchestrator/parse_task_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/utils/errors" @@ -288,9 +289,9 @@ func TestParseTask(t *testing.T) { assert.Equal(t, c.expected, value, desc) assert.Equal(t, c.after, json.MustEncodeString(p.content, false), desc) if c.err == nil { - assert.NoError(t, err, desc) + require.NoError(t, err, desc) } else { - assert.Error(t, err, desc) + require.Error(t, err, desc) assert.Equal(t, c.err.Error(), err.Error(), desc) } } diff --git a/internal/pkg/mapper/orchestrator/remote_load_test.go b/internal/pkg/mapper/orchestrator/remote_load_test.go index ac77e413be..90dd9da74d 100644 --- a/internal/pkg/mapper/orchestrator/remote_load_test.go +++ b/internal/pkg/mapper/orchestrator/remote_load_test.go @@ -8,6 +8,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -106,7 +107,7 @@ func TestOrchestratorMapAfterRemoteLoad(t *testing.T) { ConfigManifest: configManifest, Remote: config, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Target configs target1, target2, target3 := createTargetConfigs(t, state) @@ -114,18 +115,18 @@ func TestOrchestratorMapAfterRemoteLoad(t *testing.T) { // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(configState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Check target configs relation rel1, err := target1.Remote.Relations.GetOneByType(model.UsedInOrchestratorRelType) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, config.ID, rel1.(*model.UsedInOrchestratorRelation).ConfigID) rel2, err := target2.Remote.Relations.GetOneByType(model.UsedInOrchestratorRelType) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, config.ID, rel2.(*model.UsedInOrchestratorRelation).ConfigID) rel3, err := target3.Remote.Relations.GetOneByType(model.UsedInOrchestratorRelType) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, config.ID, rel3.(*model.UsedInOrchestratorRelation).ConfigID) // Assert orchestration @@ -306,7 +307,7 @@ func TestMapAfterRemoteLoadWarnings(t *testing.T) { ConfigManifest: configManifest, Remote: config, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Target configs createTargetConfigs(t, state) @@ -314,7 +315,7 @@ func TestMapAfterRemoteLoadWarnings(t *testing.T) { // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(configState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) // Warnings expectedWarnings := ` @@ -431,12 +432,12 @@ func TestMapAfterRemoteLoadSortByDeps(t *testing.T) { ConfigManifest: configManifest, Remote: config, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(configState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Internal object @@ -612,12 +613,12 @@ func TestMapAfterRemoteLoadDepsCycles(t *testing.T) { ConfigManifest: configManifest, Remote: config, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(configState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) // Warnings expectedWarnings := ` diff --git a/internal/pkg/mapper/orchestrator/remote_save_test.go b/internal/pkg/mapper/orchestrator/remote_save_test.go index e56dcfa791..cb1d05700a 100644 --- a/internal/pkg/mapper/orchestrator/remote_save_test.go +++ b/internal/pkg/mapper/orchestrator/remote_save_test.go @@ -8,6 +8,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -129,7 +130,7 @@ func TestMapBeforeRemoteSave(t *testing.T) { recipe := model.NewRemoteSaveRecipe(manifest, object, model.NewChangedFields("orchestration")) // Save - assert.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Orchestration is stored in API object content diff --git a/internal/pkg/mapper/relations/link_test.go b/internal/pkg/mapper/relations/link_test.go index 9e1528b4b5..d02cd24d54 100644 --- a/internal/pkg/mapper/relations/link_test.go +++ b/internal/pkg/mapper/relations/link_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -34,7 +35,7 @@ func TestRelationsMapperLinkRelations(t *testing.T) { }, }, } - assert.NoError(t, state.Set(object1)) + require.NoError(t, state.Set(object1)) // API side object2 := &fixtures.MockedObjectState{ @@ -47,7 +48,7 @@ func TestRelationsMapperLinkRelations(t *testing.T) { Relations: model.Relations{}, }, } - assert.NoError(t, state.Set(object2)) + require.NoError(t, state.Set(object2)) // No other side relation assert.Empty(t, object2.Local.Relations) @@ -55,7 +56,7 @@ func TestRelationsMapperLinkRelations(t *testing.T) { // Call AfterLocalOperation changes := model.NewLocalChanges() changes.AddLoaded(object1) - assert.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Other side relation has been created @@ -86,12 +87,12 @@ func TestRelationsMapperOtherSideMissing(t *testing.T) { }, }, } - assert.NoError(t, state.Set(object1)) + require.NoError(t, state.Set(object1)) // Call AfterLocalOperation changes := model.NewLocalChanges() changes.AddLoaded(object1) - assert.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) // Warning is logged expected := ` diff --git a/internal/pkg/mapper/relations/local_load_test.go b/internal/pkg/mapper/relations/local_load_test.go index faee0c59e9..5032878797 100644 --- a/internal/pkg/mapper/relations/local_load_test.go +++ b/internal/pkg/mapper/relations/local_load_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -24,7 +25,7 @@ func TestRelationsMapperLocalLoad(t *testing.T) { assert.NotEmpty(t, manifest.Relations) assert.Empty(t, object.Relations) - assert.NoError(t, state.Mapper().MapAfterLocalLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterLocalLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Copied, manifest.Relations -> object.Relations diff --git a/internal/pkg/mapper/relations/local_save_test.go b/internal/pkg/mapper/relations/local_save_test.go index e1f8a8a2dc..9169026070 100644 --- a/internal/pkg/mapper/relations/local_save_test.go +++ b/internal/pkg/mapper/relations/local_save_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -26,7 +27,7 @@ func TestRelationsMapperSaveLocal(t *testing.T) { assert.Empty(t, objectManifest.Relations) assert.NotEmpty(t, object.Relations) - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // ManifestSide relations copied from object.Relations -> manifest.Relations diff --git a/internal/pkg/mapper/scheduler/persist_test.go b/internal/pkg/mapper/scheduler/persist_test.go index db57be992d..0fd8d8f5d4 100644 --- a/internal/pkg/mapper/scheduler/persist_test.go +++ b/internal/pkg/mapper/scheduler/persist_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -34,7 +35,7 @@ func TestVariablesMapBeforePersist(t *testing.T) { // Invoke assert.Empty(t, configManifest.Relations) - assert.NoError(t, state.Mapper().MapBeforePersist(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforePersist(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Relation has been created diff --git a/internal/pkg/mapper/scheduler/remote_activate_test.go b/internal/pkg/mapper/scheduler/remote_activate_test.go index 52b801dd51..a24fe5df20 100644 --- a/internal/pkg/mapper/scheduler/remote_activate_test.go +++ b/internal/pkg/mapper/scheduler/remote_activate_test.go @@ -10,6 +10,7 @@ import ( "github.com/jarcoal/httpmock" "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -32,7 +33,7 @@ func TestSchedulerMapperRemoteActivate(t *testing.T) { IsDefault: true, }, } - assert.NoError(t, state.Set(branchState)) + require.NoError(t, state.Set(branchState)) // Scheduler config schedulerKey := model.ConfigKey{ @@ -48,7 +49,7 @@ func TestSchedulerMapperRemoteActivate(t *testing.T) { ConfigKey: schedulerKey, }, } - assert.NoError(t, state.Set(schedulerConfigState)) + require.NoError(t, state.Set(schedulerConfigState)) // Expected HTTP call var httpRequest *http.Request @@ -75,12 +76,12 @@ func TestSchedulerMapperRemoteActivate(t *testing.T) { // Invoke changes := model.NewRemoteChanges() changes.AddUpdated(schedulerConfigState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Check API request reqBody, err := io.ReadAll(httpRequest.Body) - assert.NoError(t, err) - assert.NoError(t, err) - assert.Equal(t, string(reqBody), `{"configurationId":"456"}`) + require.NoError(t, err) + require.NoError(t, err) + assert.Equal(t, `{"configurationId":"456"}`, string(reqBody)) } diff --git a/internal/pkg/mapper/scheduler/remote_deactivate_test.go b/internal/pkg/mapper/scheduler/remote_deactivate_test.go index 0ec8f36b5e..f03e26f9b6 100644 --- a/internal/pkg/mapper/scheduler/remote_deactivate_test.go +++ b/internal/pkg/mapper/scheduler/remote_deactivate_test.go @@ -9,6 +9,7 @@ import ( "github.com/jarcoal/httpmock" "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -31,7 +32,7 @@ func TestSchedulerMapperRemoteDeactivate(t *testing.T) { IsDefault: true, }, } - assert.NoError(t, state.Set(branchState)) + require.NoError(t, state.Set(branchState)) // Scheduler config schedulerKey := model.ConfigKey{ @@ -47,7 +48,7 @@ func TestSchedulerMapperRemoteDeactivate(t *testing.T) { ConfigKey: schedulerKey, }, } - assert.NoError(t, state.Set(schedulerConfigState)) + require.NoError(t, state.Set(schedulerConfigState)) // Expected HTTP call var httpRequest *http.Request @@ -74,7 +75,7 @@ func TestSchedulerMapperRemoteDeactivate(t *testing.T) { // Invoke changes := model.NewRemoteChanges() changes.AddDeleted(schedulerConfigState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Check API request diff --git a/internal/pkg/mapper/scheduler/remote_load_test.go b/internal/pkg/mapper/scheduler/remote_load_test.go index 380009383f..b0a2903691 100644 --- a/internal/pkg/mapper/scheduler/remote_load_test.go +++ b/internal/pkg/mapper/scheduler/remote_load_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -33,7 +34,7 @@ func TestSchedulerMapAfterRemoteLoad(t *testing.T) { // Invoke assert.Empty(t, object.Relations) - assert.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Internal object has new relation diff --git a/internal/pkg/mapper/scheduler/remote_save_test.go b/internal/pkg/mapper/scheduler/remote_save_test.go index 2c62e81370..10ce230ca6 100644 --- a/internal/pkg/mapper/scheduler/remote_save_test.go +++ b/internal/pkg/mapper/scheduler/remote_save_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -28,7 +29,7 @@ func TestSchedulerMapBeforeRemoteSave(t *testing.T) { // Invoke assert.NotEmpty(t, object.Relations) - assert.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // All relations have been mapped diff --git a/internal/pkg/mapper/sharedcode/codes/codes_test.go b/internal/pkg/mapper/sharedcode/codes/codes_test.go index 4a34c5af8b..768c3d4823 100644 --- a/internal/pkg/mapper/sharedcode/codes/codes_test.go +++ b/internal/pkg/mapper/sharedcode/codes/codes_test.go @@ -6,7 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/sharedcode/codes" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -49,7 +49,7 @@ func createRemoteSharedCode(t *testing.T, state *state.State) (*model.ConfigStat Content: configContent, }, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Row rowKey := model.ConfigRowKey{ @@ -73,7 +73,7 @@ func createRemoteSharedCode(t *testing.T, state *state.State) (*model.ConfigStat Content: orderedmap.New(), }, } - assert.NoError(t, state.Set(rowState)) + require.NoError(t, state.Set(rowState)) return configState, rowState } @@ -104,7 +104,7 @@ func createLocalSharedCode(t *testing.T, targetComponentID keboola.ComponentID, Content: configContent, }, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Row rowKey := model.ConfigRowKey{ @@ -128,7 +128,7 @@ func createLocalSharedCode(t *testing.T, targetComponentID keboola.ComponentID, Content: orderedmap.New(), }, } - assert.NoError(t, state.Set(rowState)) + require.NoError(t, state.Set(rowState)) return configState, rowState } @@ -168,7 +168,7 @@ func createInternalSharedCode(t *testing.T, targetComponentID keboola.ComponentI }, }, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Row rowKey := model.ConfigRowKey{ @@ -210,7 +210,7 @@ func createInternalSharedCode(t *testing.T, targetComponentID keboola.ComponentI }, }, } - assert.NoError(t, state.Set(rowState)) + require.NoError(t, state.Set(rowState)) return configState, rowState } diff --git a/internal/pkg/mapper/sharedcode/codes/local_load_test.go b/internal/pkg/mapper/sharedcode/codes/local_load_test.go index caaedfe2ea..252421fb74 100644 --- a/internal/pkg/mapper/sharedcode/codes/local_load_test.go +++ b/internal/pkg/mapper/sharedcode/codes/local_load_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -22,19 +23,19 @@ func TestSharedCodeLocalLoad(t *testing.T) { // Write file codeFilePath := filesystem.Join(state.NamingGenerator().SharedCodeFilePath(rowState.ConfigRowManifest.Path(), targetComponentID)) - assert.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile(codeFilePath, `foo bar`))) + require.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile(codeFilePath, `foo bar`))) logger.Truncate() // Load config configRecipe := model.NewLocalLoadRecipe(state.FileLoader(), configState.Manifest(), configState.Local) err := state.Mapper().MapAfterLocalLoad(context.Background(), configRecipe) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, logger.WarnAndErrorMessages()) // Load row rowRecipe := model.NewLocalLoadRecipe(state.FileLoader(), rowState.Manifest(), rowState.Local) err = state.Mapper().MapAfterLocalLoad(context.Background(), rowRecipe) - assert.NoError(t, err) + require.NoError(t, err) logger.AssertJSONMessages(t, `{"level":"debug","message":"Loaded \"branch/config/row/code.py\""}`) // Structs are set @@ -64,13 +65,13 @@ func TestSharedCodeLocalLoad_MissingCodeFile(t *testing.T) { // Load config configRecipe := model.NewLocalLoadRecipe(state.FileLoader(), configState.Manifest(), configState.Local) err := state.Mapper().MapAfterLocalLoad(context.Background(), configRecipe) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, logger.WarnAndErrorMessages()) // Load row rowRecipe := model.NewLocalLoadRecipe(state.FileLoader(), rowState.Manifest(), rowState.Local) err = state.Mapper().MapAfterLocalLoad(context.Background(), rowRecipe) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `missing shared code file "branch/config/row/code.py"`, err.Error()) assert.Empty(t, logger.WarnAndErrorMessages()) } diff --git a/internal/pkg/mapper/sharedcode/codes/local_save_test.go b/internal/pkg/mapper/sharedcode/codes/local_save_test.go index 7163de3fc9..a9fe6383ad 100644 --- a/internal/pkg/mapper/sharedcode/codes/local_save_test.go +++ b/internal/pkg/mapper/sharedcode/codes/local_save_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -23,17 +24,17 @@ func TestSharedCodeLocalSave(t *testing.T) { codeFilePath := filesystem.Join(state.NamingGenerator().SharedCodeFilePath(recipe.ObjectManifest.Path(), targetComponentID)) // Create dir - assert.NoError(t, state.ObjectsRoot().Mkdir(context.Background(), filesystem.Dir(codeFilePath))) + require.NoError(t, state.ObjectsRoot().Mkdir(context.Background(), filesystem.Dir(codeFilePath))) // Save to file - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Assert sharedCodeFileRaw := recipe.Files.GetOneByTag(model.FileKindNativeSharedCode) assert.NotNil(t, sharedCodeFileRaw) sharedCodeFile, err := sharedCodeFileRaw.ToRawFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, codeFilePath, sharedCodeFile.Path()) assert.Equal(t, "foo\nbar\n", sharedCodeFile.Content) } diff --git a/internal/pkg/mapper/sharedcode/codes/remote_load_test.go b/internal/pkg/mapper/sharedcode/codes/remote_load_test.go index 5e1e87988c..078429afe3 100644 --- a/internal/pkg/mapper/sharedcode/codes/remote_load_test.go +++ b/internal/pkg/mapper/sharedcode/codes/remote_load_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -26,7 +27,7 @@ func TestSharedCodeRemoteLoad(t *testing.T) { changes := model.NewRemoteChanges() changes.AddLoaded(configState) changes.AddLoaded(rowState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Check config @@ -61,7 +62,7 @@ func TestSharedCodeRemoteLoad_Legacy(t *testing.T) { changes := model.NewRemoteChanges() changes.AddLoaded(configState) changes.AddLoaded(rowState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Check config @@ -96,7 +97,7 @@ func TestSharedCodeRemoteLoad_UnexpectedTypeInConfig(t *testing.T) { changes := model.NewRemoteChanges() changes.AddLoaded(configState) changes.AddLoaded(rowState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) // Check logs expectedLogs := ` @@ -124,7 +125,7 @@ func TestSharedCodeRemoteLoad_UnexpectedTypeInRow(t *testing.T) { changes := model.NewRemoteChanges() changes.AddLoaded(configState) changes.AddLoaded(rowState) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) // Check logs expectedLogs := ` diff --git a/internal/pkg/mapper/sharedcode/codes/remote_save_test.go b/internal/pkg/mapper/sharedcode/codes/remote_save_test.go index ba9fb463ea..76a54a1283 100644 --- a/internal/pkg/mapper/sharedcode/codes/remote_save_test.go +++ b/internal/pkg/mapper/sharedcode/codes/remote_save_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -21,13 +22,13 @@ func TestSharedCodeRemoteSave(t *testing.T) { // Map config configRecipe := model.NewRemoteSaveRecipe(configState.Manifest(), configState.Remote, model.NewChangedFields(`configuration`)) err := state.Mapper().MapBeforeRemoteSave(context.Background(), configRecipe) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, logger.WarnAndErrorMessages()) // Map row rowRecipe := model.NewRemoteSaveRecipe(rowState.Manifest(), rowState.Remote, model.NewChangedFields(`configuration`)) err = state.Mapper().MapBeforeRemoteSave(context.Background(), rowRecipe) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, logger.WarnAndErrorMessages()) // Assert diff --git a/internal/pkg/mapper/sharedcode/helper/helper_test.go b/internal/pkg/mapper/sharedcode/helper/helper_test.go index dc28e462eb..9a63532b5e 100644 --- a/internal/pkg/mapper/sharedcode/helper/helper_test.go +++ b/internal/pkg/mapper/sharedcode/helper/helper_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" . "github.com/keboola/keboola-as-code/internal/pkg/mapper/sharedcode/helper" @@ -23,20 +24,20 @@ func TestGetSharedCodeByPath(t *testing.T) { // Found result, err := helper.GetSharedCodeByPath(`branch`, `_shared/keboola.python-transformation-v2`) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, result) assert.Equal(t, sharedCodeKey, result.Key()) // Different branch result, err = helper.GetSharedCodeByPath(`branch123`, `_shared/keboola.python-transformation-v2`) assert.Nil(t, result) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `missing shared code "branch123/_shared/keboola.python-transformation-v2"`, err.Error()) // Not found result, err = helper.GetSharedCodeByPath(`branch`, `foo/bar`) assert.Nil(t, result) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `missing shared code "branch/foo/bar"`, err.Error()) } @@ -52,7 +53,7 @@ func TestGetSharedCodeRowByPath(t *testing.T) { // Found result, err := helper.GetSharedCodeRowByPath(sharedCode, `codes/code1`) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, result) assert.Equal(t, model.ConfigRowKey{ BranchID: 123, @@ -64,7 +65,7 @@ func TestGetSharedCodeRowByPath(t *testing.T) { // Not found result, err = helper.GetSharedCodeRowByPath(sharedCode, `foo/bar`) assert.Nil(t, result) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `missing shared code "branch/_shared/keboola.python-transformation-v2/foo/bar"`, err.Error()) } diff --git a/internal/pkg/mapper/sharedcode/links/id_test.go b/internal/pkg/mapper/sharedcode/links/id_test.go index eed6daf8d9..152f121c63 100644 --- a/internal/pkg/mapper/sharedcode/links/id_test.go +++ b/internal/pkg/mapper/sharedcode/links/id_test.go @@ -1,7 +1,6 @@ package links import ( - "fmt" "testing" "github.com/keboola/go-client/pkg/keboola" @@ -27,7 +26,7 @@ func TestSharedCodeLinksMatchId(t *testing.T) { } idUtils := newIDUtils() for i, c := range cases { - assert.Equal(t, keboola.RowID(c.expected), idUtils.match(c.input), fmt.Sprintf(`Case "%d"`, i)) + assert.Equal(t, keboola.RowID(c.expected), idUtils.match(c.input), `Case "%d"`, i) } } diff --git a/internal/pkg/mapper/sharedcode/links/links_test.go b/internal/pkg/mapper/sharedcode/links/links_test.go index 921533aadc..63f8b5d442 100644 --- a/internal/pkg/mapper/sharedcode/links/links_test.go +++ b/internal/pkg/mapper/sharedcode/links/links_test.go @@ -6,7 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/sharedcode/links" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -80,7 +80,7 @@ func createLocalTranWithSharedCode(t *testing.T, state *state.State) *model.Conf }, }, } - assert.NoError(t, state.Set(transformation)) + require.NoError(t, state.Set(transformation)) return transformation } @@ -142,7 +142,7 @@ func createInternalTranWithSharedCode(t *testing.T, sharedCodeKey model.ConfigKe }, } - assert.NoError(t, state.Set(transformation)) + require.NoError(t, state.Set(transformation)) return transformation } @@ -175,6 +175,6 @@ func createRemoteTranWithSharedCode(t *testing.T, sharedCodeKey model.ConfigKey, }, } - assert.NoError(t, state.Set(transformation)) + require.NoError(t, state.Set(transformation)) return transformation } diff --git a/internal/pkg/mapper/sharedcode/links/local_load_test.go b/internal/pkg/mapper/sharedcode/links/local_load_test.go index 350a9a74a2..20153e513b 100644 --- a/internal/pkg/mapper/sharedcode/links/local_load_test.go +++ b/internal/pkg/mapper/sharedcode/links/local_load_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -23,7 +24,7 @@ func TestLocalLoadTranWithSharedCode(t *testing.T) { // Invoke changes := model.NewLocalChanges() changes.AddLoaded(transformation) - assert.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Paths in transformation blocks are replaced by IDs @@ -105,7 +106,7 @@ missing shared code "branch/missing": - referenced from config "branch:123/component:keboola.python-transformation-v2/config:789" ` err := state.Mapper().AfterLocalOperation(context.Background(), changes) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, strings.TrimSpace(expectedErr), err.Error()) assert.Empty(t, logger.WarnAndErrorMessages()) @@ -135,7 +136,7 @@ missing shared code "branch/_shared/keboola.python-transformation-v2/codes/missi - referenced from "branch/transformation/blocks/block-1/code-2" ` err := state.Mapper().AfterLocalOperation(context.Background(), changes) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, strings.TrimSpace(expectedErr), err.Error()) assert.Empty(t, logger.WarnAndErrorMessages()) diff --git a/internal/pkg/mapper/sharedcode/links/local_save_test.go b/internal/pkg/mapper/sharedcode/links/local_save_test.go index 60c62c4ae2..6b4910ae9d 100644 --- a/internal/pkg/mapper/sharedcode/links/local_save_test.go +++ b/internal/pkg/mapper/sharedcode/links/local_save_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -25,13 +26,13 @@ func TestLocalSaveTranWithSharedCode(t *testing.T) { // Invoke recipe := model.NewLocalSaveRecipe(transformation.ConfigManifest, transformation.Local, model.NewChangedFields()) - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // path to shared code is part of the Content sharedCodePath, found := transformation.Local.Content.Get(model.SharedCodePathContentKey) assert.True(t, found) - assert.Equal(t, sharedCodePath, `_shared/keboola.python-transformation-v2`) + assert.Equal(t, `_shared/keboola.python-transformation-v2`, sharedCodePath) // IDs in transformation blocks are replaced by paths assert.Equal(t, []*model.Block{ @@ -80,7 +81,7 @@ func TestLocalSaveTranWithSharedCode_SharedCodeConfigNotFound(t *testing.T) { // Invoke recipe := model.NewLocalSaveRecipe(transformation.ConfigManifest, transformation.Local, model.NewChangedFields()) - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) expectedLogs := ` WARN Warning: - Missing shared code config "branch:123/component:keboola.shared-code/config:missing": @@ -145,7 +146,7 @@ func TestLocalSaveTranWithSharedCode_SharedCodeRowNotFound(t *testing.T) { // Invoke recipe := model.NewLocalSaveRecipe(transformation.ConfigManifest, transformation.Local, model.NewChangedFields()) - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) expectedLogs := ` WARN Warning: - Missing shared code config row "branch:123/component:keboola.shared-code/config:456/row:missing": @@ -156,7 +157,7 @@ WARN Warning: // Link to shared code is set, but without missing row sharedCodeID, found := transformation.Local.Content.Get(model.SharedCodePathContentKey) assert.True(t, found) - assert.Equal(t, sharedCodeID, `_shared/keboola.python-transformation-v2`) + assert.Equal(t, `_shared/keboola.python-transformation-v2`, sharedCodeID) // IDs in transformation blocks are replaced by paths, except missing row assert.Equal(t, []*model.Block{ diff --git a/internal/pkg/mapper/sharedcode/links/path_test.go b/internal/pkg/mapper/sharedcode/links/path_test.go index a46ea365cf..e63adde6e4 100644 --- a/internal/pkg/mapper/sharedcode/links/path_test.go +++ b/internal/pkg/mapper/sharedcode/links/path_test.go @@ -1,7 +1,6 @@ package links import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -29,7 +28,7 @@ func TestSharedCodeLinksMatchPath(t *testing.T) { } pathUtils := newPathUtils() for i, c := range cases { - assert.Equal(t, c.expected, pathUtils.match(c.input, `keboola.snowflake-transformation`), fmt.Sprintf(`Case "%d"`, i)) + assert.Equal(t, c.expected, pathUtils.match(c.input, `keboola.snowflake-transformation`), `Case "%d"`, i) } } diff --git a/internal/pkg/mapper/sharedcode/links/remote_load_test.go b/internal/pkg/mapper/sharedcode/links/remote_load_test.go index bec635578b..966b9915c5 100644 --- a/internal/pkg/mapper/sharedcode/links/remote_load_test.go +++ b/internal/pkg/mapper/sharedcode/links/remote_load_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -25,7 +26,7 @@ func TestRemoteLoadTranWithSharedCode(t *testing.T) { // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(transformation) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Values from content are converted to struct @@ -53,7 +54,7 @@ func TestRemoteLoadTranWithSharedCode_InvalidSharedCodeId(t *testing.T) { // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(transformation) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) expectedLogs := ` WARN Warning: - Missing shared code config "branch:123/component:keboola.shared-code/config:missing": @@ -86,7 +87,7 @@ func TestRemoteLoadTranWithSharedCode_InvalidSharedCodeRowId(t *testing.T) { // Invoke changes := model.NewRemoteChanges() changes.AddLoaded(transformation) - assert.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterRemoteOperation(context.Background(), changes)) expectedLogs := ` WARN Warning: - Missing shared code config row "branch:123/component:keboola.shared-code/config:456/row:missing": diff --git a/internal/pkg/mapper/sharedcode/links/remote_save_test.go b/internal/pkg/mapper/sharedcode/links/remote_save_test.go index 48c21bcc23..8be247ff91 100644 --- a/internal/pkg/mapper/sharedcode/links/remote_save_test.go +++ b/internal/pkg/mapper/sharedcode/links/remote_save_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -24,7 +25,7 @@ func TestRemoteSaveTranWithSharedCode(t *testing.T) { // Invoke object := transformation.Local recipe := model.NewRemoteSaveRecipe(transformation.Manifest(), object, model.NewChangedFields()) - assert.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Config ID and rows ID are set in Content diff --git a/internal/pkg/mapper/sharedcode/variables/persist_test.go b/internal/pkg/mapper/sharedcode/variables/persist_test.go index 6574b69dfe..753d8e6cfe 100644 --- a/internal/pkg/mapper/sharedcode/variables/persist_test.go +++ b/internal/pkg/mapper/sharedcode/variables/persist_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -35,7 +36,7 @@ func TestSharedCodeMapBeforePersist(t *testing.T) { // Invoke assert.Empty(t, configManifest.Relations) - assert.NoError(t, state.Mapper().MapBeforePersist(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforePersist(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Relation has been created diff --git a/internal/pkg/mapper/sharedcode/variables/remote_load_test.go b/internal/pkg/mapper/sharedcode/variables/remote_load_test.go index 2d013e7e70..42bb8d9bfc 100644 --- a/internal/pkg/mapper/sharedcode/variables/remote_load_test.go +++ b/internal/pkg/mapper/sharedcode/variables/remote_load_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -27,7 +28,7 @@ func TestSharedCodeMapAfterRemoteLoad(t *testing.T) { // Invoke assert.Empty(t, object.Relations) - assert.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Object has new relation + content without variables ID diff --git a/internal/pkg/mapper/sharedcode/variables/remote_save_test.go b/internal/pkg/mapper/sharedcode/variables/remote_save_test.go index 458fbe5533..8f97cbaae7 100644 --- a/internal/pkg/mapper/sharedcode/variables/remote_save_test.go +++ b/internal/pkg/mapper/sharedcode/variables/remote_save_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -29,7 +30,7 @@ func TestSharedCodeMapBeforeRemoteSave(t *testing.T) { // Invoke assert.NotEmpty(t, object.Relations) assert.NotEmpty(t, object.Relations) - assert.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // All relations have been mapped diff --git a/internal/pkg/mapper/template/jsonnetfiles/load_test.go b/internal/pkg/mapper/template/jsonnetfiles/load_test.go index 08688fabc7..08bf82c0b9 100644 --- a/internal/pkg/mapper/template/jsonnetfiles/load_test.go +++ b/internal/pkg/mapper/template/jsonnetfiles/load_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" @@ -26,7 +27,7 @@ func TestJsonnetMapper_LoadLocalFile(t *testing.T) { // Write Jsonnet file with a variable fs := state.ObjectsRoot() jsonnetContent := `{ foo: std.extVar("myKey")}` - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`my/dir/file.jsonnet`, jsonnetContent))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`my/dir/file.jsonnet`, jsonnetContent))) // Create file loader fileLoader := state.Mapper().NewFileLoader(fs) @@ -35,7 +36,7 @@ func TestJsonnetMapper_LoadLocalFile(t *testing.T) { fileDef := filesystem.NewFileDef(`my/dir/file.json`) fileDef.AddTag(model.FileTypeJSON) jsonFile, err := fileLoader.ReadJSONFile(ctx, fileDef) - assert.NoError(t, err) + require.NoError(t, err) // Jsonnet file is loaded and converted to a Json file assert.Equal(t, `my/dir/file.jsonnet`, jsonFile.Path()) diff --git a/internal/pkg/mapper/template/jsonnetfiles/save_test.go b/internal/pkg/mapper/template/jsonnetfiles/save_test.go index 1841f4ce40..81d0c60d1c 100644 --- a/internal/pkg/mapper/template/jsonnetfiles/save_test.go +++ b/internal/pkg/mapper/template/jsonnetfiles/save_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/jsonnet" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" @@ -30,11 +31,11 @@ func TestJsonnetMapper_MapBeforeLocalSave(t *testing.T) { AddTag(model.FileTypeMarkdown) // Run mapper - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) // Json file is converted to Jsonnet expectedAst, err := jsonnet.ToAst("{\n \"key\": \"value\"\n}\n", "foo.jsonnet") - assert.NoError(t, err) + require.NoError(t, err) expected := model.NewFilesToSave() expected. Add(filesystem.NewJsonnetFile(`foo.jsonnet`, expectedAst, nil)). // <<<<<<< @@ -46,6 +47,6 @@ func TestJsonnetMapper_MapBeforeLocalSave(t *testing.T) { // Jsonnet file content f, err := recipe.Files.GetOneByTag(model.FileTypeJsonnet).ToRawFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "{\n key: \"value\",\n}\n", f.Content) } diff --git a/internal/pkg/mapper/template/metadata/local_test.go b/internal/pkg/mapper/template/metadata/local_test.go index af2c85b290..0053e94e6a 100644 --- a/internal/pkg/mapper/template/metadata/local_test.go +++ b/internal/pkg/mapper/template/metadata/local_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/template/metadata" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -44,7 +45,7 @@ func TestMetadataMapper_AfterLocalOperation(t *testing.T) { Metadata: map[string]string{}, }, } - assert.NoError(t, mockedState.Set(configState)) + require.NoError(t, mockedState.Set(configState)) rowState := &model.ConfigRowState{ ConfigRowManifest: &model.ConfigRowManifest{ ConfigRowKey: configRowKey, @@ -55,12 +56,12 @@ func TestMetadataMapper_AfterLocalOperation(t *testing.T) { Content: orderedmap.New(), }, } - assert.NoError(t, mockedState.Set(rowState)) + require.NoError(t, mockedState.Set(rowState)) changes := model.NewLocalChanges() changes.AddLoaded(configState) changes.AddLoaded(rowState) - assert.NoError(t, mockedState.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, mockedState.Mapper().AfterLocalOperation(context.Background(), changes)) config := configState.Local assert.NotEmpty(t, config.Metadata) diff --git a/internal/pkg/mapper/template/replacevalues/mapper_test.go b/internal/pkg/mapper/template/replacevalues/mapper_test.go index 606d38d25b..41207a1a66 100644 --- a/internal/pkg/mapper/template/replacevalues/mapper_test.go +++ b/internal/pkg/mapper/template/replacevalues/mapper_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/template/replacevalues" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -67,7 +68,7 @@ func TestReplaceKeysMapper_OnRemoteChange(t *testing.T) { // Run mapper changes := model.NewRemoteChanges() changes.AddLoaded(config, row) - assert.NoError(t, s.Mapper().AfterRemoteOperation(context.Background(), changes)) + require.NoError(t, s.Mapper().AfterRemoteOperation(context.Background(), changes)) // Check result state assert.Equal(t, []model.ObjectState{ diff --git a/internal/pkg/mapper/template/replacevalues/replace_test.go b/internal/pkg/mapper/template/replacevalues/replace_test.go index 1f41d4d73b..bb2b54c9ca 100644 --- a/internal/pkg/mapper/template/replacevalues/replace_test.go +++ b/internal/pkg/mapper/template/replacevalues/replace_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -143,7 +144,7 @@ func TestValues_Validate_DuplicateOld(t *testing.T) { ) err := replacements.validate() - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `the old ID "12" is defined 2x`, err.Error()) } @@ -179,7 +180,7 @@ func TestValues_Validate_DuplicateNew(t *testing.T) { ) err := replacements.validate() - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `the new ID "23" is defined 2x`, err.Error()) } @@ -319,7 +320,7 @@ func TestValues_Replace(t *testing.T) { } replaced, err := replacements.Replace(input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expected, replaced) } diff --git a/internal/pkg/mapper/transformation/local_load_test.go b/internal/pkg/mapper/transformation/local_load_test.go index be5d00a773..1c0729b15c 100644 --- a/internal/pkg/mapper/transformation/local_load_test.go +++ b/internal/pkg/mapper/transformation/local_load_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/mapper/corefiles" @@ -44,25 +45,25 @@ func TestLoadTransformationInvalidConfigAndMeta(t *testing.T) { ConfigKey: configKey, Paths: model.Paths{AbsPath: model.AbsPath{RelativePath: "config"}}, } - assert.NoError(t, fs.Mkdir(ctx, record.Path())) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.MetaFilePath(record.Path()), metaFile))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.DescriptionFilePath(record.Path()), descFile))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.ConfigFilePath(record.Path()), configFile))) + require.NoError(t, fs.Mkdir(ctx, record.Path())) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.MetaFilePath(record.Path()), metaFile))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.DescriptionFilePath(record.Path()), descFile))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.ConfigFilePath(record.Path()), configFile))) blocksDir := namingGenerator.BlocksDir(record.Path()) - assert.NoError(t, fs.Mkdir(ctx, blocksDir)) + require.NoError(t, fs.Mkdir(ctx, blocksDir)) block := &model.Block{BlockKey: model.BlockKey{Index: 123}, Name: `block`} block.AbsPath = namingGenerator.BlockPath(blocksDir, block) - assert.NoError(t, fs.Mkdir(ctx, block.Path())) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.MetaFilePath(block.Path()), blockMeta))) + require.NoError(t, fs.Mkdir(ctx, block.Path())) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.MetaFilePath(block.Path()), blockMeta))) code := &model.Code{CodeKey: model.CodeKey{Index: 123}, Name: `code`} code.AbsPath = namingGenerator.CodePath(block.Path(), code) code.CodeFileName = namingGenerator.CodeFileName("foo.bar") - assert.NoError(t, fs.Mkdir(ctx, code.Path())) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.MetaFilePath(code.Path()), codeMeta))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.CodeFilePath(code), codeContent))) + require.NoError(t, fs.Mkdir(ctx, code.Path())) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.MetaFilePath(code.Path()), codeMeta))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(namingGenerator.CodeFilePath(code), codeContent))) // Set parent - assert.NoError(t, state.Set(&model.BranchState{ + require.NoError(t, state.Set(&model.BranchState{ BranchManifest: &model.BranchManifest{BranchKey: configKey.BranchKey()}, Local: &model.Branch{BranchKey: configKey.BranchKey()}, })) @@ -73,7 +74,7 @@ func TestLoadTransformationInvalidConfigAndMeta(t *testing.T) { err := uow.Invoke() // Error is reported - assert.Error(t, err) + require.Error(t, err) expectedErr := ` - config metadata file "config/meta.json" is invalid: - invalid character 'f' looking for beginning of object key string, offset: 2 @@ -99,13 +100,13 @@ func TestLoadTransformationMissingBlockMetaSql(t *testing.T) { // Create files/dirs blocksDir := filesystem.Join(`branch`, `config`, `blocks`) - assert.NoError(t, fs.Mkdir(ctx, blocksDir)) + require.NoError(t, fs.Mkdir(ctx, blocksDir)) block1 := filesystem.Join(blocksDir, `001-block-1`) - assert.NoError(t, fs.Mkdir(ctx, block1)) + require.NoError(t, fs.Mkdir(ctx, block1)) // Load, assert err := state.Mapper().MapAfterLocalLoad(context.Background(), recipe) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `missing block metadata file "branch/config/blocks/001-block-1/meta.json"`, err.Error()) assert.Empty(t, logger.WarnAndErrorMessages()) } @@ -122,16 +123,16 @@ func TestLoadTransformationMissingCodeMeta(t *testing.T) { // Create files/dirs blocksDir := filesystem.Join(`branch`, `config`, `blocks`) - assert.NoError(t, fs.Mkdir(ctx, blocksDir)) + require.NoError(t, fs.Mkdir(ctx, blocksDir)) block1 := filesystem.Join(blocksDir, `001-block-1`) - assert.NoError(t, fs.Mkdir(ctx, block1)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1, `meta.json`), `{"name": "001"}`))) + require.NoError(t, fs.Mkdir(ctx, block1)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1, `meta.json`), `{"name": "001"}`))) block1Code1 := filesystem.Join(block1, `001-code-1`) - assert.NoError(t, fs.Mkdir(ctx, block1Code1)) + require.NoError(t, fs.Mkdir(ctx, block1Code1)) // Load, assert err := state.Mapper().MapAfterLocalLoad(context.Background(), recipe) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, strings.Join([]string{ `- missing code metadata file "branch/config/blocks/001-block-1/001-code-1/meta.json"`, `- missing code file in "branch/config/blocks/001-block-1/001-code-1"`, @@ -151,31 +152,31 @@ func TestLoadLocalTransformationSql(t *testing.T) { // Create files/dirs blocksDir := filesystem.Join(`branch`, `config`, `blocks`) - assert.NoError(t, fs.Mkdir(ctx, blocksDir)) + require.NoError(t, fs.Mkdir(ctx, blocksDir)) block1 := filesystem.Join(blocksDir, `001-block-1`) - assert.NoError(t, fs.Mkdir(ctx, block1)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1, `meta.json`), `{"name": "001"}`))) + require.NoError(t, fs.Mkdir(ctx, block1)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1, `meta.json`), `{"name": "001"}`))) block1Code1 := filesystem.Join(block1, `001-code-1`) - assert.NoError(t, fs.Mkdir(ctx, block1Code1)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code1, `meta.json`), `{"name": "001-001"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code1, `code.sql`), `SELECT 1`))) + require.NoError(t, fs.Mkdir(ctx, block1Code1)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code1, `meta.json`), `{"name": "001-001"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code1, `code.sql`), `SELECT 1`))) block1Code2 := filesystem.Join(blocksDir, `001-block-1`, `002-code-2`) - assert.NoError(t, fs.Mkdir(ctx, block1Code2)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code2, `meta.json`), `{"name": "001-002"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code2, `code.sql`), `SELECT 1; SELECT 2;`))) + require.NoError(t, fs.Mkdir(ctx, block1Code2)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code2, `meta.json`), `{"name": "001-002"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code2, `code.sql`), `SELECT 1; SELECT 2;`))) block2 := filesystem.Join(blocksDir, `002-block-2`) - assert.NoError(t, fs.Mkdir(ctx, block2)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2, `meta.json`), `{"name": "002"}`))) + require.NoError(t, fs.Mkdir(ctx, block2)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2, `meta.json`), `{"name": "002"}`))) block2Code1 := filesystem.Join(block2, `002-code-1`) - assert.NoError(t, fs.Mkdir(ctx, block2Code1)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2Code1, `meta.json`), `{"name": "002-001"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2Code1, `code.sql`), `SELECT 3`))) + require.NoError(t, fs.Mkdir(ctx, block2Code1)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2Code1, `meta.json`), `{"name": "002-001"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2Code1, `code.sql`), `SELECT 3`))) block3 := filesystem.Join(blocksDir, `003-block-3`) - assert.NoError(t, fs.Mkdir(ctx, block3)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block3, `meta.json`), `{"name": "003"}`))) + require.NoError(t, fs.Mkdir(ctx, block3)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block3, `meta.json`), `{"name": "003"}`))) // Load - assert.NoError(t, state.Mapper().MapAfterLocalLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterLocalLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Assert @@ -295,31 +296,31 @@ func TestLoadLocalTransformationPy(t *testing.T) { // Create files/dirs blocksDir := filesystem.Join(`branch`, `config`, `blocks`) - assert.NoError(t, fs.Mkdir(ctx, blocksDir)) + require.NoError(t, fs.Mkdir(ctx, blocksDir)) block1 := filesystem.Join(blocksDir, `001-block-1`) - assert.NoError(t, fs.Mkdir(ctx, block1)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1, `meta.json`), `{"name": "001"}`))) + require.NoError(t, fs.Mkdir(ctx, block1)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1, `meta.json`), `{"name": "001"}`))) block1Code1 := filesystem.Join(block1, `001-code-1`) - assert.NoError(t, fs.Mkdir(ctx, block1Code1)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code1, `meta.json`), `{"name": "001-001"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code1, `code.py`), `print('1')`))) + require.NoError(t, fs.Mkdir(ctx, block1Code1)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code1, `meta.json`), `{"name": "001-001"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code1, `code.py`), `print('1')`))) block1Code2 := filesystem.Join(blocksDir, `001-block-1`, `002-code-2`) - assert.NoError(t, fs.Mkdir(ctx, block1Code2)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code2, `meta.json`), `{"name": "001-002"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code2, `code.py`), "print('1')\nprint('2')"))) + require.NoError(t, fs.Mkdir(ctx, block1Code2)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code2, `meta.json`), `{"name": "001-002"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block1Code2, `code.py`), "print('1')\nprint('2')"))) block2 := filesystem.Join(blocksDir, `002-block-2`) - assert.NoError(t, fs.Mkdir(ctx, block2)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2, `meta.json`), `{"name": "002"}`))) + require.NoError(t, fs.Mkdir(ctx, block2)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2, `meta.json`), `{"name": "002"}`))) block2Code1 := filesystem.Join(block2, `002-code-1`) - assert.NoError(t, fs.Mkdir(ctx, block2Code1)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2Code1, `meta.json`), `{"name": "002-001"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2Code1, `code.py`), `print('3')`))) + require.NoError(t, fs.Mkdir(ctx, block2Code1)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2Code1, `meta.json`), `{"name": "002-001"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block2Code1, `code.py`), `print('3')`))) block3 := filesystem.Join(blocksDir, `003-block-3`) - assert.NoError(t, fs.Mkdir(ctx, block3)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block3, `meta.json`), `{"name": "003"}`))) + require.NoError(t, fs.Mkdir(ctx, block3)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(block3, `meta.json`), `{"name": "003"}`))) // Load - assert.NoError(t, state.Mapper().MapAfterLocalLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterLocalLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Assert diff --git a/internal/pkg/mapper/transformation/local_save_test.go b/internal/pkg/mapper/transformation/local_save_test.go index 860165d60e..eb7bace8af 100644 --- a/internal/pkg/mapper/transformation/local_save_test.go +++ b/internal/pkg/mapper/transformation/local_save_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/deepcopy" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" @@ -28,12 +29,12 @@ func TestLocalSaveTransformationEmpty(t *testing.T) { recipe := model.NewLocalSaveRecipe(configState.Manifest(), object, model.NewChangedFields()) blocksDir := filesystem.Join(`branch`, `config`, `blocks`) - assert.NoError(t, fs.Mkdir(context.Background(), blocksDir)) + require.NoError(t, fs.Mkdir(context.Background(), blocksDir)) // Save err := state.Mapper().MapBeforeLocalSave(context.Background(), recipe) - assert.NoError(t, err) - assert.NoError(t, err) + require.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `{"foo":"bar"}`, json.MustEncodeString(object.Content, false)) } @@ -52,7 +53,7 @@ func TestTransformationMapper_MapBeforeLocalSave(t *testing.T) { configDir := filesystem.Join(`branch`, `config`) blocksDir := filesystem.Join(configDir, `blocks`) - assert.NoError(t, fs.Mkdir(context.Background(), blocksDir)) + require.NoError(t, fs.Mkdir(context.Background(), blocksDir)) // Prepare object.Content.Set(`foo`, `bar`) @@ -144,7 +145,7 @@ func TestTransformationMapper_MapBeforeLocalSave(t *testing.T) { } // Save - assert.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeLocalSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Minify JSON + remove file description @@ -158,7 +159,7 @@ func TestTransformationMapper_MapBeforeLocalSave(t *testing.T) { } else { var err error fileRaw, err = file.ToRawFile() - assert.NoError(t, err) + require.NoError(t, err) fileRaw.SetDescription(``) } files = append(files, fileRaw) diff --git a/internal/pkg/mapper/transformation/remote_load_test.go b/internal/pkg/mapper/transformation/remote_load_test.go index f53e0995cc..d4a113f7e6 100644 --- a/internal/pkg/mapper/transformation/remote_load_test.go +++ b/internal/pkg/mapper/transformation/remote_load_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -64,7 +65,7 @@ func TestLoadRemoteTransformation(t *testing.T) { } json.MustDecodeString(configInAPI, object.Content) recipe := model.NewRemoteLoadRecipe(configState.ConfigManifest, object) - assert.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Internal representation diff --git a/internal/pkg/mapper/transformation/remote_save_test.go b/internal/pkg/mapper/transformation/remote_save_test.go index 15c39c55ae..24082566f8 100644 --- a/internal/pkg/mapper/transformation/remote_save_test.go +++ b/internal/pkg/mapper/transformation/remote_save_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -63,7 +64,7 @@ func TestRemoteSaveTransformation(t *testing.T) { recipe := model.NewRemoteSaveRecipe(configState.Manifest(), object, model.NewChangedFields("transformation")) // Save - assert.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Blocks are stored in API object content diff --git a/internal/pkg/mapper/variables/local_persist_test.go b/internal/pkg/mapper/variables/local_persist_test.go index 27377cbf20..e86e86233f 100644 --- a/internal/pkg/mapper/variables/local_persist_test.go +++ b/internal/pkg/mapper/variables/local_persist_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -34,7 +35,7 @@ func TestVariablesMapBeforePersist(t *testing.T) { // Invoke assert.Empty(t, configManifest.Relations) - assert.NoError(t, state.Mapper().MapBeforePersist(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforePersist(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Relation has been created @@ -83,7 +84,7 @@ func TestVariablesValuesPersistDefaultInName(t *testing.T) { // Invoke changes := model.NewLocalChanges() changes.AddPersisted(state.All()...) - assert.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Row 2 has relation -> contains default variables values, because it has "default" in the name @@ -131,7 +132,7 @@ func TestVariablesValuesPersistFirstRowIsDefault(t *testing.T) { // Invoke changes := model.NewLocalChanges() changes.AddPersisted(state.All()...) - assert.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) + require.NoError(t, state.Mapper().AfterLocalOperation(context.Background(), changes)) assert.Empty(t, logger.WarnAndErrorMessages()) // Row1 has relation -> contains default variables values, because it is first diff --git a/internal/pkg/mapper/variables/remote_load_test.go b/internal/pkg/mapper/variables/remote_load_test.go index bd21be8639..81474bed1c 100644 --- a/internal/pkg/mapper/variables/remote_load_test.go +++ b/internal/pkg/mapper/variables/remote_load_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -26,7 +27,7 @@ func TestVariablesMapAfterRemoteLoad(t *testing.T) { // Invoke assert.Empty(t, object.Relations) - assert.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapAfterRemoteLoad(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // Internal object has new relation + content without variables ID diff --git a/internal/pkg/mapper/variables/remote_save_test.go b/internal/pkg/mapper/variables/remote_save_test.go index c55787a9a7..5bb2cdc0ca 100644 --- a/internal/pkg/mapper/variables/remote_save_test.go +++ b/internal/pkg/mapper/variables/remote_save_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -30,7 +31,7 @@ func TestVariablesMapBeforeRemoteSave(t *testing.T) { // Invoke assert.NotEmpty(t, object.Relations) assert.NotEmpty(t, object.Relations) - assert.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) + require.NoError(t, state.Mapper().MapBeforeRemoteSave(context.Background(), recipe)) assert.Empty(t, logger.WarnAndErrorMessages()) // All relations have been mapped diff --git a/internal/pkg/mapper/variables/variables_test.go b/internal/pkg/mapper/variables/variables_test.go index baaf04282c..a657ac160b 100644 --- a/internal/pkg/mapper/variables/variables_test.go +++ b/internal/pkg/mapper/variables/variables_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/keboola/go-client/pkg/keboola" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/mapper/variables" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -46,7 +46,7 @@ func createTestObjectForPersist(t *testing.T, state model.ObjectStates) { Relations: configRelations, }, } - assert.NoError(t, state.Set(configState)) + require.NoError(t, state.Set(configState)) // Row 1 row1Key := model.ConfigRowKey{ @@ -64,7 +64,7 @@ func createTestObjectForPersist(t *testing.T, state model.ObjectStates) { Name: `first`, }, } - assert.NoError(t, state.Set(row1State)) + require.NoError(t, state.Set(row1State)) // Row 2 row2Key := model.ConfigRowKey{ @@ -82,7 +82,7 @@ func createTestObjectForPersist(t *testing.T, state model.ObjectStates) { Name: `second`, }, } - assert.NoError(t, state.Set(row2State)) + require.NoError(t, state.Set(row2State)) // Row 3 row3Key := model.ConfigRowKey{ @@ -100,5 +100,5 @@ func createTestObjectForPersist(t *testing.T, state model.ObjectStates) { Name: `third`, }, } - assert.NoError(t, state.Set(row3State)) + require.NoError(t, state.Set(row3State)) } diff --git a/internal/pkg/model/component_test.go b/internal/pkg/model/component_test.go index d712aa2b47..748dabfe00 100644 --- a/internal/pkg/model/component_test.go +++ b/internal/pkg/model/component_test.go @@ -63,7 +63,7 @@ func TestComponentDefaultBucket(t *testing.T) { assert.Equal(t, keboola.ComponentID("keboola.ex-aws-s3"), component.ID) assert.Equal(t, "AWS S3", component.Name) assert.IsType(t, keboola.ComponentData{}, component.Data) - assert.Equal(t, true, component.Data.DefaultBucket) + assert.True(t, component.Data.DefaultBucket) assert.Equal(t, "in", component.Data.DefaultBucketStage) m := NewComponentsMap([]*keboola.Component{&component}) diff --git a/internal/pkg/model/mapper_test.go b/internal/pkg/model/mapper_test.go index ebab58fe8d..30d10a3148 100644 --- a/internal/pkg/model/mapper_test.go +++ b/internal/pkg/model/mapper_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -20,7 +21,7 @@ func TestFilesToSave(t *testing.T) { file1 := files.Add(fileRaw1) assert.Same(t, fileRaw1, file1) result, err := fileRaw1.ToRawFile() - assert.NoError(t, err) + require.NoError(t, err) assert.Same(t, fileRaw1, result) assert.Equal(t, fileRaw1.Path(), file1.Path()) @@ -88,11 +89,11 @@ func TestFilesLoader(t *testing.T) { // Create files jsonContent := "{\"field1\": \"foo\", \"field2\": \"bar\"}" jsonMap := orderedmap.FromPairs([]orderedmap.Pair{{Key: "field1", Value: "foo"}, {Key: "field2", Value: "bar"}}) - assert.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo1.json", jsonContent))) - assert.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo2.json", jsonContent))) - assert.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo3.json", jsonContent))) - assert.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo4.json", jsonContent))) - assert.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo5.json", jsonContent))) + require.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo1.json", jsonContent))) + require.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo2.json", jsonContent))) + require.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo3.json", jsonContent))) + require.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo4.json", jsonContent))) + require.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile("foo5.json", jsonContent))) // ReadFile rawFile1, err := files. @@ -101,7 +102,7 @@ func TestFilesLoader(t *testing.T) { AddTag(`tag1`). AddTag(`tag2`). ReadFile(context.Background()) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `foo1.json`, rawFile1.Path()) assert.Equal(t, `my description`, rawFile1.Description()) assert.Equal(t, jsonContent, rawFile1.Content) @@ -113,7 +114,7 @@ func TestFilesLoader(t *testing.T) { AddTag(`tag3`). AddTag(`tag4`). ReadJSONFile(context.Background()) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `foo2.json`, jsonFile1.Path()) assert.Equal(t, `my description`, jsonFile1.Description()) assert.Equal(t, jsonMap, jsonFile1.Content) @@ -127,7 +128,7 @@ func TestFilesLoader(t *testing.T) { AddTag(`tag6`). ReadJSONFieldsTo(context.Background(), target1, `mytag:field`) assert.True(t, tagFound) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `foo3.json`, jsonFile2.Path()) assert.Equal(t, `my description`, jsonFile2.Description()) assert.Equal(t, `foo`, target1.Field1) @@ -142,7 +143,7 @@ func TestFilesLoader(t *testing.T) { AddTag(`tag8`). ReadFileContentTo(context.Background(), target2, `mytag:content`) assert.True(t, tagFound) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `foo4.json`, rawFile2.Path()) assert.Equal(t, `my description`, rawFile2.Description()) assert.Equal(t, jsonContent, target2.Content) @@ -156,7 +157,7 @@ func TestFilesLoader(t *testing.T) { AddTag(`tag10`). ReadJSONMapTo(context.Background(), target3, `mytag:map`) assert.True(t, tagFound) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, `foo5.json`, jsonFile3.Path()) assert.Equal(t, `my description`, jsonFile3.Description()) assert.Equal(t, jsonMap, target3.Map) diff --git a/internal/pkg/model/object_test.go b/internal/pkg/model/object_test.go index bb72f4db6b..f2041a8042 100644 --- a/internal/pkg/model/object_test.go +++ b/internal/pkg/model/object_test.go @@ -6,6 +6,7 @@ import ( "github.com/keboola/go-utils/pkg/wildcards" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" ) @@ -17,7 +18,7 @@ func TestBranchMetadata_UpsertTemplateInstance_New(t *testing.T) { b := BranchMetadata{} // First instance - assert.NoError(t, b.UpsertTemplateInstance(now, "inst1", "Instance 1", "tmpl1", "repo", "1.0.0", "12345", &TemplateMainConfig{ConfigID: "1234", ComponentID: "foo.bar"})) + require.NoError(t, b.UpsertTemplateInstance(now, "inst1", "Instance 1", "tmpl1", "repo", "1.0.0", "12345", &TemplateMainConfig{ConfigID: "1234", ComponentID: "foo.bar"})) assert.Len(t, b, 1) meta, found := b["KBC.KAC.templates.instances"] @@ -26,7 +27,7 @@ func TestBranchMetadata_UpsertTemplateInstance_New(t *testing.T) { wildcards.Assert(t, `[{"instanceId":"inst1","instanceName":"Instance 1","templateId":"tmpl1","repositoryName":"repo","version":"1.0.0","created":{"date":"%s","tokenId":"12345"},"updated":{"date":"%s","tokenId":"12345"},"mainConfig":{"configId":"1234","componentId":"foo.bar"}}]`, meta, "case 1") usages, err := b.TemplatesInstances() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, TemplatesInstances{ { InstanceID: "inst1", @@ -41,9 +42,9 @@ func TestBranchMetadata_UpsertTemplateInstance_New(t *testing.T) { }, usages) // Second instance - assert.NoError(t, b.UpsertTemplateInstance(now, "inst2", "Instance 2", "tmpl2", "repo", "2.0.0", "789", nil)) + require.NoError(t, b.UpsertTemplateInstance(now, "inst2", "Instance 2", "tmpl2", "repo", "2.0.0", "789", nil)) usages, err = b.TemplatesInstances() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, TemplatesInstances{ { InstanceID: "inst1", @@ -67,9 +68,9 @@ func TestBranchMetadata_UpsertTemplateInstance_New(t *testing.T) { }, usages) // First instance - update - assert.NoError(t, b.UpsertTemplateInstance(now, "inst1", "Modified Instance 1", "tmpl1", "repo", "1.2.3", "789", &TemplateMainConfig{ConfigID: "7890", ComponentID: "foo.bar"})) + require.NoError(t, b.UpsertTemplateInstance(now, "inst1", "Modified Instance 1", "tmpl1", "repo", "1.2.3", "789", &TemplateMainConfig{ConfigID: "7890", ComponentID: "foo.bar"})) usages, err = b.TemplatesInstances() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, TemplatesInstances{ { InstanceID: "inst2", @@ -118,24 +119,24 @@ func TestBranchMetadata_DeleteTemplateUsage(t *testing.T) { MainConfig: &TemplateMainConfig{ConfigID: "1234", ComponentID: "foo.bar"}, } encUsages, err := json.EncodeString(TemplatesInstances{usage1, usage2}, false) - assert.NoError(t, err) + require.NoError(t, err) b := BranchMetadata{} b["KBC.KAC.templates.instances"] = encUsages usage, found, err := b.TemplateInstance("inst1") - assert.NoError(t, err) + require.NoError(t, err) assert.True(t, found) assert.Equal(t, &usage1, usage) err = b.DeleteTemplateUsage("inst1") - assert.NoError(t, err) + require.NoError(t, err) usages, err := b.TemplatesInstances() - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, usages, 1) _, found, err = b.TemplateInstance("inst1") - assert.NoError(t, err) + require.NoError(t, err) assert.False(t, found) } diff --git a/internal/pkg/model/relation_test.go b/internal/pkg/model/relation_test.go index 3cc19d68bd..42c772a4d6 100644 --- a/internal/pkg/model/relation_test.go +++ b/internal/pkg/model/relation_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" . "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -16,7 +17,7 @@ func TestRelationsUnmarshalJSON(t *testing.T) { t.Parallel() data := []byte(fmt.Sprintf(`[{"type": "%s"}]`, VariablesForRelType)) var relations Relations - assert.NoError(t, json.Unmarshal(data, &relations)) + require.NoError(t, json.Unmarshal(data, &relations)) assert.Len(t, relations, 1) assert.IsType(t, &VariablesForRelation{}, relations[0]) } @@ -25,7 +26,7 @@ func TestRelationsMarshalJSON(t *testing.T) { t.Parallel() relations := Relations{&VariablesForRelation{}} data, err := json.Marshal(&relations) - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, string(data), fmt.Sprintf(`"type":"%s"`, VariablesForRelType)) } @@ -93,7 +94,7 @@ func TestVariablesForRelation(t *testing.T) { // Check other side key (regular component config, it uses variables) otherSideKey, otherSideRel, err := r.NewOtherSideRelation(definedOn, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, ConfigKey{ BranchID: 123, // from source key ComponentID: `foo.bar`, @@ -105,7 +106,7 @@ func TestVariablesForRelation(t *testing.T) { // ParentKey key, same as target, ... variables config is stored within component config parentKey, err := r.ParentKey(definedOn.Key()) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, ConfigKey{ BranchID: 123, // from source key ComponentID: `foo.bar`, diff --git a/internal/pkg/model/semversion_test.go b/internal/pkg/model/semversion_test.go index 735380814c..a11ac94eba 100644 --- a/internal/pkg/model/semversion_test.go +++ b/internal/pkg/model/semversion_test.go @@ -4,12 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewVersion(t *testing.T) { t.Parallel() v, err := NewSemVersion(`1.2.3`) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, int64(1), v.Major()) assert.Equal(t, int64(2), v.Minor()) assert.Equal(t, int64(3), v.Patch()) @@ -29,6 +30,6 @@ func TestVersion_UnmarshalJSON(t *testing.T) { t.Parallel() v := SemVersion{} err := v.UnmarshalJSON([]byte(`"foo-bar"`)) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `invalid semantic version "foo-bar"`, err.Error()) } diff --git a/internal/pkg/naming/matcher_test.go b/internal/pkg/naming/matcher_test.go index d40ee1185f..4b992bb310 100644 --- a/internal/pkg/naming/matcher_test.go +++ b/internal/pkg/naming/matcher_test.go @@ -5,6 +5,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" . "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -18,7 +19,7 @@ func TestNamingMatchConfigPathNotMatched(t *testing.T) { "parent/path", "foo", )) - assert.NoError(t, err) + require.NoError(t, err) assert.Empty(t, componentID) } @@ -31,7 +32,7 @@ func TestNamingMatchConfigPathOrdinary(t *testing.T) { "parent/path", "extractor/keboola.ex-db-mysql/with-rows", )) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, keboola.ComponentID(`keboola.ex-db-mysql`), componentID) } @@ -44,7 +45,7 @@ func TestNamingMatchConfigPathSharedCode(t *testing.T) { "parent/path", "_shared/keboola.python-transformation-v2", )) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, keboola.SharedCodeComponentID, componentID) } @@ -57,7 +58,7 @@ func TestNamingMatchConfigPathVariables(t *testing.T) { "parent/path", "variables", )) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, keboola.VariablesComponentID, componentID) } @@ -70,7 +71,7 @@ func TestNamingMatchSharedCodeVariables(t *testing.T) { "shared/code/path", "variables", )) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, keboola.VariablesComponentID, componentID) } diff --git a/internal/pkg/naming/registry_test.go b/internal/pkg/naming/registry_test.go index 129dc91839..21b8ab2b78 100644 --- a/internal/pkg/naming/registry_test.go +++ b/internal/pkg/naming/registry_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" . "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -14,9 +15,9 @@ func TestNamingPathsStorage(t *testing.T) { // Attach multiple times with same key key1 := BranchKey{ID: 123} - assert.NoError(t, s.Attach(key1, NewAbsPath("", "my-branch"))) - assert.NoError(t, s.Attach(key1, NewAbsPath("", "my-branch-123"))) - assert.NoError(t, s.Attach(key1, NewAbsPath("", "my-branch-abc"))) + require.NoError(t, s.Attach(key1, NewAbsPath("", "my-branch"))) + require.NoError(t, s.Attach(key1, NewAbsPath("", "my-branch-123"))) + require.NoError(t, s.Attach(key1, NewAbsPath("", "my-branch-abc"))) assert.Len(t, s.byPath, 1) assert.Len(t, s.byKey, 1) assert.Equal(t, key1, s.byPath["my-branch-abc"]) @@ -24,13 +25,13 @@ func TestNamingPathsStorage(t *testing.T) { // Attach another key key2 := BranchKey{ID: 456} - assert.NoError(t, s.Attach(key2, NewAbsPath("", "my-branch-456"))) + require.NoError(t, s.Attach(key2, NewAbsPath("", "my-branch-456"))) assert.Len(t, s.byPath, 2) assert.Len(t, s.byKey, 2) // Attach another key with same path err := s.Attach(BranchKey{ID: 789}, NewAbsPath("", "my-branch-456")) - assert.Error(t, err) + require.Error(t, err) msg := `naming error: path "my-branch-456" is attached to branch "456", but new branch "789" has same path` assert.Equal(t, msg, err.Error()) @@ -40,7 +41,7 @@ func TestNamingPathsStorage(t *testing.T) { assert.Len(t, s.byKey, 1) // Re-use path - assert.NoError(t, s.Attach(BranchKey{ID: 789}, NewAbsPath("", "my-branch-456"))) + require.NoError(t, s.Attach(BranchKey{ID: 789}, NewAbsPath("", "my-branch-456"))) assert.Len(t, s.byPath, 2) assert.Len(t, s.byKey, 2) } diff --git a/internal/pkg/plan/persist/persist_test.go b/internal/pkg/plan/persist/persist_test.go index 21a2ae1d8c..a0fa49f5be 100644 --- a/internal/pkg/plan/persist/persist_test.go +++ b/internal/pkg/plan/persist/persist_test.go @@ -932,14 +932,14 @@ func (tc *testCase) run(t *testing.T) { var ticketResponses []*http.Response for i := 1; i <= tc.expectedNewIds; i++ { response, err := httpmock.NewJsonResponse(200, map[string]any{"id": cast.ToString(1000 + i)}) - assert.NoError(t, err) + require.NoError(t, err) ticketResponses = append(ticketResponses, response) } d.MockedHTTPTransport().RegisterResponder("POST", `=~/storage/tickets`, httpmock.ResponderFromMultipleResponses(ticketResponses)) // Load state projectState, err := d.MockedProject(fs).LoadState(loadState.Options{LoadLocalState: true, IgnoreNotFoundErr: true}, d) - assert.NoError(t, err) + require.NoError(t, err) // Assert state before assert.Equal(t, tc.untrackedPaths, projectState.UntrackedPaths()) @@ -954,7 +954,7 @@ func (tc *testCase) run(t *testing.T) { // Get plan plan, err := NewPlan(ctx, projectState.State()) - assert.NoError(t, err) + require.NoError(t, err) // Delete callbacks for easier comparison (we only check callbacks result) for _, action := range plan.actions { @@ -968,8 +968,8 @@ func (tc *testCase) run(t *testing.T) { // Invoke plan, err = NewPlan(ctx, projectState.State()) // plan with callbacks - assert.NoError(t, err) - assert.NoError(t, plan.Invoke(ctx, d.Logger(), d.KeboolaProjectAPI(), projectState.State())) + require.NoError(t, err) + require.NoError(t, plan.Invoke(ctx, d.Logger(), d.KeboolaProjectAPI(), projectState.State())) // Assert new IDs requests count assert.Equal(t, tc.expectedNewIds, d.MockedHTTPTransport().GetCallCountInfo()["POST =~/storage/tickets"]) diff --git a/internal/pkg/plan/rename/executor_test.go b/internal/pkg/plan/rename/executor_test.go index 7e8c713b1d..239fcdba12 100644 --- a/internal/pkg/plan/rename/executor_test.go +++ b/internal/pkg/plan/rename/executor_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -29,9 +30,9 @@ func TestRename(t *testing.T) { ctx := context.Background() // Dir structure - assert.NoError(t, fs.Mkdir(ctx, `foo1/sub`)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`foo1/sub/file`), `content`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`foo2`), `content`))) + require.NoError(t, fs.Mkdir(ctx, `foo1/sub`)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`foo1/sub/file`), `content`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`foo2`), `content`))) logger.Truncate() // Plan @@ -56,7 +57,7 @@ func TestRename(t *testing.T) { projectState := state.NewRegistry(knownpaths.NewNop(ctx), naming.NewRegistry(), model.NewComponentsMap(nil), model.SortByPath) localManager := local.NewManager(logger, validator, fs, fs.FileLoader(), manifest, nil, projectState, mapper.New()) executor := newRenameExecutor(context.Background(), localManager, plan) - assert.NoError(t, executor.invoke()) + require.NoError(t, executor.invoke()) logsStr := logger.AllMessages() assert.NotContains(t, logsStr, `warn`) assert.True(t, fs.IsFile(ctx, `bar1/sub/file`)) @@ -86,10 +87,10 @@ func TestRenameFailedKeepOldState(t *testing.T) { ctx := context.Background() // Dir structure - assert.NoError(t, fs.Mkdir(ctx, `foo1/sub`)) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`foo1/sub/file`, `content`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`foo2`, `content`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`foo5`, `content`))) + require.NoError(t, fs.Mkdir(ctx, `foo1/sub`)) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`foo1/sub/file`, `content`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`foo2`, `content`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(`foo5`, `content`))) logger.Truncate() // Plan @@ -127,7 +128,7 @@ func TestRenameFailedKeepOldState(t *testing.T) { localManager := local.NewManager(logger, validator, fs, fs.FileLoader(), manifest, nil, projectState, mapper.New()) executor := newRenameExecutor(context.Background(), localManager, plan) err := executor.invoke() - assert.Error(t, err) + require.Error(t, err) logsStr := logger.AllMessages() assert.NotContains(t, logsStr, `warn`) assert.Contains(t, err.Error(), `cannot copy "missing3" -> "missing4"`) diff --git a/internal/pkg/plan/rename/plan_test.go b/internal/pkg/plan/rename/plan_test.go index 476ae7982d..5890448563 100644 --- a/internal/pkg/plan/rename/plan_test.go +++ b/internal/pkg/plan/rename/plan_test.go @@ -31,23 +31,23 @@ func TestRenameAllPlan(t *testing.T) { "type": "extractor", "name": "Generic", }) - assert.NoError(t, err) + require.NoError(t, err) getMySQLExResponder, err := httpmock.NewJsonResponder(200, map[string]any{ "id": "keboola.ex-db-mysql", "type": "extractor", "name": "MySQL", }) - assert.NoError(t, err) + require.NoError(t, err) d.MockedHTTPTransport().RegisterResponder("GET", `=~/storage/components/ex-generic-v2`, getGenericExResponder.Once()) d.MockedHTTPTransport().RegisterResponder("GET", `=~/storage/components/keboola.ex-db-mysql`, getMySQLExResponder.Once()) // Load state projectState, err := d.MockedProject(fs).LoadState(loadState.Options{LoadLocalState: true}, d) - assert.NoError(t, err) + require.NoError(t, err) // Get rename plan plan, err := NewPlan(projectState.State()) - assert.NoError(t, err) + require.NoError(t, err) // Clear manifest records before assert for _, action := range plan.actions { diff --git a/internal/pkg/platform/model_test/create_test.go b/internal/pkg/platform/model_test/create_test.go index e3abd972ef..71dd50c1ce 100644 --- a/internal/pkg/platform/model_test/create_test.go +++ b/internal/pkg/platform/model_test/create_test.go @@ -8,6 +8,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/platform/model" "github.com/keboola/keboola-as-code/internal/pkg/platform/model/enttest" @@ -21,22 +22,22 @@ func TestCreate_SetParent(t *testing.T) { branch, err := branchBuilder(tx). SetBranchID(123). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) config, err := configBuilder(tx). SetParent(branch). SetComponentID("keboola.my-component"). SetConfigID("my-config"). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) row, err := rowBuilder(tx). SetParent(config). SetRowID("my-row"). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, tx.Commit()) + require.NoError(t, tx.Commit()) checkResults(t, ctx, client, branch, config, row) } @@ -47,14 +48,14 @@ func TestCreate_SetPartOfID(t *testing.T) { branch, err := branchBuilder(tx). SetBranchID(123). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) config, err := configBuilder(tx). SetBranchID(branch.BranchID). SetComponentID("keboola.my-component"). SetConfigID("my-config"). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) row, err := rowBuilder(tx). SetBranchID(branch.BranchID). @@ -62,9 +63,9 @@ func TestCreate_SetPartOfID(t *testing.T) { SetConfigID("my-config"). SetRowID("my-row"). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, tx.Commit()) + require.NoError(t, tx.Commit()) checkResults(t, ctx, client, branch, config, row) } @@ -75,7 +76,7 @@ func TestCreate_SetID(t *testing.T) { branch, err := branchBuilder(tx). SetID(key.BranchKey{BranchID: 123}). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) config, err := configBuilder(tx). SetID(key.ConfigurationKey{ @@ -84,7 +85,7 @@ func TestCreate_SetID(t *testing.T) { ConfigID: "my-config", }). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) row, err := rowBuilder(tx). SetID(key.ConfigurationRowKey{ @@ -94,9 +95,9 @@ func TestCreate_SetID(t *testing.T) { RowID: "my-row", }). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, tx.Commit()) + require.NoError(t, tx.Commit()) checkResults(t, ctx, client, branch, config, row) } @@ -108,11 +109,11 @@ func checkResults(t *testing.T, ctx context.Context, client *model.Client, b *mo // Check entities load from the DB b, err := client.Branch.Query().First(ctx) - assert.NoError(t, err) + require.NoError(t, err) c, err = client.Configuration.Query().First(ctx) - assert.NoError(t, err) + require.NoError(t, err) r, err = client.ConfigurationRow.Query().First(ctx) - assert.NoError(t, err) + require.NoError(t, err) assertResults(t, b, c, r) } @@ -122,7 +123,7 @@ func assertResults(t *testing.T, b *model.Branch, c *model.Configuration, r *mod // Test created entities assert.Equal(t, keboola.BranchID(123), b.BranchID) assert.Equal(t, "main", b.Name) - assert.Equal(t, true, b.IsDefault) + assert.True(t, b.IsDefault) assert.Equal(t, "my main branch", b.Description) assert.Equal(t, keboola.BranchID(123), c.BranchID) @@ -130,7 +131,7 @@ func assertResults(t *testing.T, b *model.Branch, c *model.Configuration, r *mod assert.Equal(t, keboola.ConfigID("my-config"), c.ConfigID) assert.Equal(t, "my-config", c.Name) assert.Equal(t, "My Config", c.Description) - assert.Equal(t, false, c.IsDisabled) + assert.False(t, c.IsDisabled) assert.Equal(t, orderedmap.FromPairs([]orderedmap.Pair{ {Key: "foo1", Value: "bar1"}, }), c.Content) @@ -141,7 +142,7 @@ func assertResults(t *testing.T, b *model.Branch, c *model.Configuration, r *mod assert.Equal(t, keboola.RowID("my-row"), r.RowID) assert.Equal(t, "my-row", r.Name) assert.Equal(t, "My Row", r.Description) - assert.Equal(t, true, r.IsDisabled) + assert.True(t, r.IsDisabled) assert.Equal(t, orderedmap.FromPairs([]orderedmap.Pair{ {Key: "foo2", Value: "bar2"}, }), r.Content) @@ -164,7 +165,7 @@ func clientForTest(t *testing.T) (context.Context, *model.Client) { ctx := context.Background() client := enttest.Open(t, "sqlite3", "file:model_test?mode=memory&_fk=1") t.Cleanup(func() { - assert.NoError(t, client.Close()) + require.NoError(t, client.Close()) }) return ctx, client @@ -174,27 +175,27 @@ func createEntities(t *testing.T, ctx context.Context, client *model.Client) { t.Helper() tx, err := client.Tx(ctx) - assert.NoError(t, err) + require.NoError(t, err) branch, err := branchBuilder(tx). SetBranchID(123). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) config, err := configBuilder(tx). SetParent(branch). SetComponentID("keboola.my-component"). SetConfigID("my-config"). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) _, err = rowBuilder(tx). SetParent(config). SetRowID("my-row"). Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, tx.Commit()) + require.NoError(t, tx.Commit()) } func branchBuilder(tx *model.Tx) *model.BranchCreate { diff --git a/internal/pkg/platform/model_test/delete_test.go b/internal/pkg/platform/model_test/delete_test.go index ac8c245954..37840ed12b 100644 --- a/internal/pkg/platform/model_test/delete_test.go +++ b/internal/pkg/platform/model_test/delete_test.go @@ -5,6 +5,7 @@ import ( _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDelete(t *testing.T) { @@ -20,7 +21,7 @@ func TestDelete(t *testing.T) { // Cascade delete count, err := client.Branch.Delete().Exec(ctx) assert.Equal(t, 1, count) - assert.NoError(t, err) + require.NoError(t, err) // Assert assert.Equal(t, 0, client.Branch.Query().CountX(ctx)) diff --git a/internal/pkg/platform/model_test/model_test.go b/internal/pkg/platform/model_test/model_test.go index a5afb86f75..4849ade55e 100644 --- a/internal/pkg/platform/model_test/model_test.go +++ b/internal/pkg/platform/model_test/model_test.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql/schema" _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/platform/model/migrate" ) @@ -24,29 +25,29 @@ func TestModelDump(t *testing.T) { // Create connection db, err := sql.Open("sqlite3", "file:model_test?mode=memory&_fk=1") - assert.NoError(t, err) + require.NoError(t, err) // Migrate tables, err := schema.CopyTables(migrate.Tables) - assert.NoError(t, err) - assert.NoError(t, migrate.Create(ctx, migrate.NewSchema(db), tables)) + require.NoError(t, err) + require.NoError(t, migrate.Create(ctx, migrate.NewSchema(db), tables)) // Inspect driver, err := sqlite.Open(db) - assert.NoError(t, err) + require.NoError(t, err) spec, err := driver.InspectRealm(ctx, &atlasSchema.InspectRealmOption{Mode: atlasSchema.InspectTables}) - assert.NoError(t, err) + require.NoError(t, err) hclBytes, err := sqlite.MarshalHCL(spec) - assert.NoError(t, err) + require.NoError(t, err) hcl := string(hclBytes) // Dump - assert.NoError(t, os.RemoveAll(".out")) - assert.NoError(t, os.MkdirAll(".out", 0o755)) - assert.NoError(t, os.WriteFile(filepath.Join(".out", "model_actual.hcl"), hclBytes, 0o644)) + require.NoError(t, os.RemoveAll(".out")) + require.NoError(t, os.MkdirAll(".out", 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(".out", "model_actual.hcl"), hclBytes, 0o644)) // Compare expected, err := os.ReadFile("expected/model_expected.hcl") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, string(expected), hcl) } diff --git a/internal/pkg/platform/model_test/update_test.go b/internal/pkg/platform/model_test/update_test.go index 17cf5b0886..f680cc255c 100644 --- a/internal/pkg/platform/model_test/update_test.go +++ b/internal/pkg/platform/model_test/update_test.go @@ -5,6 +5,7 @@ import ( _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/platform/model/configurationrow" "github.com/keboola/keboola-as-code/internal/pkg/platform/model/key" @@ -25,21 +26,21 @@ func TestUpdate(t *testing.T) { RowID: "my-row", } row, err := client.ConfigurationRow.Query().Where(configurationrow.ID(rowID)).Only(ctx) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "my-row", row.Name) assert.Equal(t, "My Row", row.Description) - assert.Equal(t, true, row.IsDisabled) + assert.True(t, row.IsDisabled) // Update _, err = row.Update().SetName("new-name").SetDescription("New Description").SetIsDisabled(false).Save(ctx) - assert.NoError(t, err) + require.NoError(t, err) // Query again row, err = client.ConfigurationRow.Query().Where(configurationrow.ID(rowID)).Only(ctx) - assert.NoError(t, err) + require.NoError(t, err) // Assert assert.Equal(t, "new-name", row.Name) assert.Equal(t, "New Description", row.Description) - assert.Equal(t, false, row.IsDisabled) + assert.False(t, row.IsDisabled) } diff --git a/internal/pkg/platform/schema/compiler/extension/primarykey/generatekey_test.go b/internal/pkg/platform/schema/compiler/extension/primarykey/generatekey_test.go index 7576d21fd5..88ab60d5de 100644 --- a/internal/pkg/platform/schema/compiler/extension/primarykey/generatekey_test.go +++ b/internal/pkg/platform/schema/compiler/extension/primarykey/generatekey_test.go @@ -7,6 +7,7 @@ import ( "entgo.io/ent/entc/gen" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/platform/schema/compiler/extension/primarykey" ) @@ -22,19 +23,16 @@ func TestGenerateKeys(t *testing.T) { } // Generate - if !assert.NoError(t, primarykey.GenerateKeys(config)) { - return - } - + require.NoError(t, primarykey.GenerateKeys(config)) // Read all files files := make(map[string]string) - assert.NoError(t, filepath.Walk(targetDir, func(path string, info os.FileInfo, err error) error { + require.NoError(t, filepath.Walk(targetDir, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if !info.IsDir() { b, err := os.ReadFile(path) - assert.NoError(t, err) + require.NoError(t, err) relPath, _ := filepath.Rel(targetDir, path) files[relPath] = string(b) } @@ -50,13 +48,13 @@ func TestGenerateKeys(t *testing.T) { func expectedChildKeyGo(t *testing.T) string { t.Helper() b, err := os.ReadFile("fixture/expectedChildKeyGo.txt") - assert.NoError(t, err) + require.NoError(t, err) return string(b) } func expectedSubChildKeyGo(t *testing.T) string { t.Helper() b, err := os.ReadFile("fixture/expectedSubChildKeyGo.txt") - assert.NoError(t, err) + require.NoError(t, err) return string(b) } diff --git a/internal/pkg/platform/schema/compiler/extension/primarykey/mixin_test.go b/internal/pkg/platform/schema/compiler/extension/primarykey/mixin_test.go index e893b92c6f..5c6e436bee 100644 --- a/internal/pkg/platform/schema/compiler/extension/primarykey/mixin_test.go +++ b/internal/pkg/platform/schema/compiler/extension/primarykey/mixin_test.go @@ -38,7 +38,7 @@ func TestDefinition_Valid_OneField(t *testing.T) { fields := mixin.Fields() assert.Len(t, fields, 2) edges := mixin.Edges() - assert.Len(t, edges, 0) + assert.Empty(t, edges) // ID field assert.Equal(t, "id", fields[0].Descriptor().Name) @@ -89,7 +89,7 @@ func TestDefinition_Valid_MoreFields(t *testing.T) { fields := mixin.Fields() assert.Len(t, fields, 3) edges := mixin.Edges() - assert.Len(t, edges, 0) + assert.Empty(t, edges) // ID field assert.Equal(t, "id", fields[0].Descriptor().Name) diff --git a/internal/pkg/project/ignore/ignore_test.go b/internal/pkg/project/ignore/ignore_test.go index 933505eb77..16ea4fe4a5 100644 --- a/internal/pkg/project/ignore/ignore_test.go +++ b/internal/pkg/project/ignore/ignore_test.go @@ -24,12 +24,12 @@ func TestFile_IgnoreConfigsOrRows(t *testing.T) { file, err := LoadFile(ctx, fs, registry, "foo/bar1") require.NoError(t, err) - assert.NoError(t, file.IgnoreConfigsOrRows()) + require.NoError(t, file.IgnoreConfigsOrRows()) assert.Len(t, registry.IgnoredConfigRows(), 1) assert.Len(t, registry.IgnoredConfigs(), 1) - assert.Equal(t, registry.IgnoredConfigRows()[0].ID.String(), "34") - assert.Equal(t, registry.IgnoredConfigs()[0].ID.String(), "345") + assert.Equal(t, "34", registry.IgnoredConfigRows()[0].ID.String()) + assert.Equal(t, "345", registry.IgnoredConfigs()[0].ID.String()) } func Test_applyIgnoredPatterns(t *testing.T) { diff --git a/internal/pkg/project/manifest/manifest_test.go b/internal/pkg/project/manifest/manifest_test.go index 9b27a9b192..043919d316 100644 --- a/internal/pkg/project/manifest/manifest_test.go +++ b/internal/pkg/project/manifest/manifest_test.go @@ -63,7 +63,7 @@ func TestManifestLoadNotFound(t *testing.T) { // Load manifest, err := Load(context.Background(), log.NewNopLogger(), fs, env.Empty(), false) assert.Nil(t, manifest) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `manifest ".keboola/manifest.json" not found`, err.Error()) } @@ -75,12 +75,12 @@ func TestLoadManifestFile(t *testing.T) { // Write file path := Path() - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(path, c.json))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(path, c.json))) // Load manifest, err := Load(ctx, log.NewNopLogger(), fs, env.Empty(), false) assert.NotNil(t, manifest) - assert.NoError(t, err) + require.NoError(t, err) // Assert assert.Equal(t, c.naming, manifest.NamingTemplate(), c.name) @@ -101,12 +101,12 @@ func TestSaveManifestFile(t *testing.T) { manifest.SetNamingTemplate(c.naming) manifest.SetAllowedBranches(c.filter.AllowedBranches()) manifest.SetIgnoredComponents(c.filter.IgnoredComponents()) - assert.NoError(t, manifest.records.SetRecords(c.records)) - assert.NoError(t, manifest.Save(ctx, fs)) + require.NoError(t, manifest.records.SetRecords(c.records)) + require.NoError(t, manifest.Save(ctx, fs)) // Load file file, err := fs.ReadFile(ctx, filesystem.NewFileDef(Path())) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, wildcards.EscapeWhitespaces(c.json), wildcards.EscapeWhitespaces(file.Content), c.name) } } @@ -115,7 +115,7 @@ func TestManifestValidateEmpty(t *testing.T) { t.Parallel() content := &file{} err := content.validate(context.Background()) - assert.NotNil(t, err) + require.Error(t, err) expected := `manifest is not valid: - "version" is a required field - "project" is a required field @@ -129,14 +129,14 @@ func TestManifestValidateMinimal(t *testing.T) { t.Parallel() content := newFile(12345, "foo.bar") content.setRecords(minimalRecords()) - assert.NoError(t, content.validate(context.Background())) + require.NoError(t, content.validate(context.Background())) } func TestManifestValidateFull(t *testing.T) { t.Parallel() content := newFile(12345, "foo.bar") content.setRecords(fullRecords()) - assert.NoError(t, content.validate(context.Background())) + require.NoError(t, content.validate(context.Background())) } func TestManifestValidateBadVersion(t *testing.T) { @@ -145,7 +145,7 @@ func TestManifestValidateBadVersion(t *testing.T) { content.setRecords(minimalRecords()) content.Version = 123 err := content.validate(context.Background()) - assert.Error(t, err) + require.Error(t, err) expected := `manifest is not valid: "version" must be 2 or less` assert.Equal(t, expected, err.Error()) } @@ -164,7 +164,7 @@ func TestManifestValidateNestedField(t *testing.T) { }, }) err := content.validate(context.Background()) - assert.Error(t, err) + require.Error(t, err) expected := `manifest is not valid: "branches[0].id" is a required field` assert.Equal(t, expected, err.Error()) } @@ -176,12 +176,12 @@ func TestManifestCyclicDependency(t *testing.T) { // Write file path := filesystem.Join(filesystem.MetadataDir, FileName) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(path, cyclicDependencyJSON()))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(path, cyclicDependencyJSON()))) // Load manifest, err := Load(ctx, log.NewNopLogger(), fs, env.Empty(), false) assert.Nil(t, manifest) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, "invalid manifest:\n- a cyclic relation was found when resolving path to config \"branch:123/component:keboola.variables/config:111\"", err.Error()) } @@ -194,7 +194,7 @@ func TestManifest_AllowTargetENV(t *testing.T) { // Write file fs := aferofs.NewMemoryFs() path := filesystem.Join(filesystem.MetadataDir, FileName) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(path, allowTargetEnvJSON()))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(path, allowTargetEnvJSON()))) // Load file logger := log.NewDebugLogger() @@ -218,7 +218,7 @@ func TestManifest_AllowTargetENV(t *testing.T) { // The file content is same updatedFile, err := fs.ReadFile(ctx, filesystem.NewFileDef(Path())) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, strings.TrimSpace(allowTargetEnvJSON()), strings.TrimSpace(updatedFile.Content)) } diff --git a/internal/pkg/search/search_test.go b/internal/pkg/search/search_test.go index d5898fb171..b836796f30 100644 --- a/internal/pkg/search/search_test.go +++ b/internal/pkg/search/search_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" ) @@ -11,7 +12,7 @@ import ( func TestStateSearchForBranches(t *testing.T) { t.Parallel() all := testBranches() - assert.Len(t, Branches(all, `baz`), 0) + assert.Empty(t, Branches(all, `baz`)) assert.Len(t, Branches(all, `Foo bar`), 1) assert.Len(t, Branches(all, `a`), 2) } @@ -21,17 +22,17 @@ func TestStateSearchForBranch(t *testing.T) { all := testBranches() b, err := Branch(all, `baz`) - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, b) assert.Equal(t, `no branch matches the specified "baz"`, err.Error()) b, err = Branch(all, `Foo bar`) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, b) assert.Equal(t, "Foo Bar Branch", b.ObjectName()) b, err = Branch(all, `a`) - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, b) assert.Equal(t, `multiple branches match the specified "a"`, err.Error()) } @@ -40,7 +41,7 @@ func TestStateSearchForConfigs(t *testing.T) { t.Parallel() all := testConfigs() - assert.Len(t, Configs(all, `baz`), 0) + assert.Empty(t, Configs(all, `baz`)) assert.Len(t, Configs(all, `1`), 1) assert.Len(t, Configs(all, `Config`), 2) } @@ -50,17 +51,17 @@ func TestStateSearchForConfig(t *testing.T) { all := testConfigs() c, err := Config(all, `baz`) - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, c) assert.Equal(t, `no config matches the specified "baz"`, err.Error()) c, err = Config(all, `1`) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, c) assert.Equal(t, "Config 1", c.ObjectName()) c, err = Config(all, `config`) - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, c) assert.Equal(t, `multiple configs match the specified "config"`, err.Error()) } @@ -69,7 +70,7 @@ func TestStateSearchForConfigRows(t *testing.T) { t.Parallel() all := testRows() - assert.Len(t, ConfigRows(all, `baz`), 0) + assert.Empty(t, ConfigRows(all, `baz`)) assert.Len(t, ConfigRows(all, `1`), 1) assert.Len(t, ConfigRows(all, `row`), 2) } @@ -79,17 +80,17 @@ func TestStateSearchForConfigRow(t *testing.T) { all := testRows() r, err := ConfigRow(all, `baz`) - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, r) assert.Equal(t, `no row matches the specified "baz"`, err.Error()) r, err = ConfigRow(all, `1`) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, r) assert.Equal(t, "Config Row 1", r.ObjectName()) r, err = ConfigRow(all, `row`) - assert.Error(t, err) + require.Error(t, err) assert.Nil(t, r) assert.Equal(t, `multiple rows match the specified "row"`, err.Error()) } diff --git a/internal/pkg/service/appsproxy/dataapps/api/rule_test.go b/internal/pkg/service/appsproxy/dataapps/api/rule_test.go index 05bbc46a7e..906242ef77 100644 --- a/internal/pkg/service/appsproxy/dataapps/api/rule_test.go +++ b/internal/pkg/service/appsproxy/dataapps/api/rule_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestRule_Match(t *testing.T) { @@ -131,7 +132,7 @@ func TestRule_Match(t *testing.T) { matched, err := tc.Rule.Match(httptest.NewRequest(http.MethodGet, tc.URL, nil)) assert.Equal(t, tc.ExpectedMatch, matched, tc.Description) if tc.ExpectedErr == "" { - assert.NoError(t, err, tc.Description) + require.NoError(t, err, tc.Description) } else if assert.Error(t, err, tc.Description) { assert.Equal(t, tc.ExpectedErr, err.Error()) } diff --git a/internal/pkg/service/appsproxy/dataapps/appconfig/appconfig_test.go b/internal/pkg/service/appsproxy/dataapps/appconfig/appconfig_test.go index ffd8aee776..fd2bb5031b 100644 --- a/internal/pkg/service/appsproxy/dataapps/appconfig/appconfig_test.go +++ b/internal/pkg/service/appsproxy/dataapps/appconfig/appconfig_test.go @@ -297,7 +297,7 @@ func TestLoader_LoadConfig_Race(t *testing.T) { defer wg.Done() cfg, _, err := loader.GetConfig(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "http://app.local", cfg.UpstreamAppURL) counter.Add(1) }() diff --git a/internal/pkg/service/appsproxy/dataapps/notify/notify_test.go b/internal/pkg/service/appsproxy/dataapps/notify/notify_test.go index 5bd50d8c97..aa69e96cc3 100644 --- a/internal/pkg/service/appsproxy/dataapps/notify/notify_test.go +++ b/internal/pkg/service/appsproxy/dataapps/notify/notify_test.go @@ -11,6 +11,7 @@ import ( "github.com/benbjohnson/clock" "github.com/jarcoal/httpmock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.uber.org/atomic" "github.com/keboola/keboola-as-code/internal/pkg/service/appsproxy/config" @@ -40,19 +41,19 @@ func TestManager_Notify(t *testing.T) { // The first request is send to the API err := manager.Notify(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 1, transport.GetTotalCallCount()) // Request is skipped, the interval was not exceeded clk.Add(time.Millisecond) err = manager.Notify(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 1, transport.GetTotalCallCount()) // Exceed the interval clk.Add(notify.Interval) err = manager.Notify(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 2, transport.GetTotalCallCount()) } @@ -86,7 +87,7 @@ func TestManager_Notify_Race(t *testing.T) { defer wg.Done() err := manager.Notify(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) counter.Add(1) }() diff --git a/internal/pkg/service/appsproxy/dataapps/wakeup/wakeup_test.go b/internal/pkg/service/appsproxy/dataapps/wakeup/wakeup_test.go index e4068164dc..4171abb8d8 100644 --- a/internal/pkg/service/appsproxy/dataapps/wakeup/wakeup_test.go +++ b/internal/pkg/service/appsproxy/dataapps/wakeup/wakeup_test.go @@ -11,6 +11,7 @@ import ( "github.com/benbjohnson/clock" "github.com/jarcoal/httpmock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.uber.org/atomic" "github.com/keboola/keboola-as-code/internal/pkg/service/appsproxy/config" @@ -40,19 +41,19 @@ func TestManager_Wakeup(t *testing.T) { // The first request is send to the API err := manager.Wakeup(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 1, transport.GetTotalCallCount()) // Request is skipped, the Interval was not exceeded clk.Add(time.Millisecond) err = manager.Wakeup(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 1, transport.GetTotalCallCount()) // Exceed the Interval clk.Add(wakeup.Interval) err = manager.Wakeup(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 2, transport.GetTotalCallCount()) } @@ -86,7 +87,7 @@ func TestManager_Wakeup_Race(t *testing.T) { defer wg.Done() err := manager.Wakeup(ctx, appID) - assert.NoError(t, err) + require.NoError(t, err) counter.Add(1) }() diff --git a/internal/pkg/service/appsproxy/proxy/proxy_test.go b/internal/pkg/service/appsproxy/proxy/proxy_test.go index 1dba13f848..118b65c011 100644 --- a/internal/pkg/service/appsproxy/proxy/proxy_test.go +++ b/internal/pkg/service/appsproxy/proxy/proxy_test.go @@ -727,7 +727,7 @@ func TestAppProxyRouter(t *testing.T) { } // Shutdown provider server - assert.NoError(t, m[0].Shutdown()) + require.NoError(t, m[0].Shutdown()) // Request to the OIDC provider request, err = http.NewRequestWithContext(context.Background(), http.MethodGet, location, nil) @@ -1175,7 +1175,7 @@ func TestAppProxyRouter(t *testing.T) { assert.Equal(t, "Hello websocket", v) - assert.NoError(t, c.Close(websocket.StatusNormalClosure, "")) + require.NoError(t, c.Close(websocket.StatusNormalClosure, "")) }, expectedNotifications: map[string]int{ "123": 1, @@ -1267,7 +1267,7 @@ func TestAppProxyRouter(t *testing.T) { assert.Equal(t, "Hello websocket", v) - assert.NoError(t, c.Close(websocket.StatusNormalClosure, "")) + require.NoError(t, c.Close(websocket.StatusNormalClosure, "")) }, expectedNotifications: map[string]int{ "oidc": 1, @@ -1391,7 +1391,7 @@ func TestAppProxyRouter(t *testing.T) { assert.Equal(t, "Hello websocket", v) - assert.NoError(t, c.Close(websocket.StatusNormalClosure, "")) + require.NoError(t, c.Close(websocket.StatusNormalClosure, "")) }, expectedNotifications: map[string]int{ "multi": 1, @@ -1476,7 +1476,7 @@ func TestAppProxyRouter(t *testing.T) { require.NoError(t, err) require.Equal(t, http.StatusFound, response.StatusCode) location = response.Header.Get("Location") - assert.Equal(t, location, "/api") + assert.Equal(t, "/api", location) // Request to private part (authorized) request, err = http.NewRequestWithContext(context.Background(), http.MethodGet, "https://prefix.hub.keboola.local/api", nil) @@ -1734,7 +1734,7 @@ func TestAppProxyRouter(t *testing.T) { }) request, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://oidc.hub.keboola.local/foo/bar", nil) - assert.NoError(t, err) + require.NoError(t, err) response, err := client.Do(request) if assert.NoError(t, err) { @@ -2232,7 +2232,7 @@ func TestAppProxyRouter(t *testing.T) { body, err := io.ReadAll(response.Body) require.NoError(t, err) assert.Contains(t, string(body), "Basic Authentication") - require.Len(t, response.Cookies(), 0) + require.Empty(t, response.Cookies()) }, expectedNotifications: map[string]int{}, expectedWakeUps: map[string]int{}, @@ -2444,12 +2444,12 @@ func testAuthProviders(t *testing.T) []*mockoidc.MockOIDC { oidc0 := testutil.StartOIDCProviderServer(t) t.Cleanup(func() { - assert.NoError(t, oidc0.Shutdown()) + require.NoError(t, oidc0.Shutdown()) }) oidc1 := testutil.StartOIDCProviderServer(t) t.Cleanup(func() { - assert.NoError(t, oidc1.Shutdown()) + require.NoError(t, oidc1.Shutdown()) }) return []*mockoidc.MockOIDC{oidc0, oidc1} diff --git a/internal/pkg/service/appsproxy/proxy/testutil/api.go b/internal/pkg/service/appsproxy/proxy/testutil/api.go index 3d921358c7..a8f53615b1 100644 --- a/internal/pkg/service/appsproxy/proxy/testutil/api.go +++ b/internal/pkg/service/appsproxy/proxy/testutil/api.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/mitchellh/hashstructure/v2" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/encoding/json" "github.com/keboola/keboola-as-code/internal/pkg/service/appsproxy/dataapps/api" @@ -46,7 +46,7 @@ func StartDataAppsAPI(t *testing.T) *DataAppsAPI { expectedETag := strings.Trim(req.Header.Get("If-None-Match"), `"`) actualETagInt, err := hashstructure.Hash(app, hashstructure.FormatV2, &hashstructure.HashOptions{}) - assert.NoError(t, err) + require.NoError(t, err) actualETag := strconv.FormatUint(actualETagInt, 10) w.Header().Set("ETag", fmt.Sprintf(`"%s"`, actualETag)) @@ -58,18 +58,18 @@ func StartDataAppsAPI(t *testing.T) *DataAppsAPI { w.WriteHeader(http.StatusOK) jsonData, err := json.Encode(app, true) - assert.NoError(t, err) + require.NoError(t, err) _, _ = w.Write(jsonData) }) mux.HandleFunc("PATCH /apps/{app}", func(w http.ResponseWriter, req *http.Request) { appID := req.PathValue("app") body, err := io.ReadAll(req.Body) - assert.NoError(t, err) + require.NoError(t, err) data := make(map[string]string) err = json.DecodeString(string(body), &data) - assert.NoError(t, err) + require.NoError(t, err) if _, ok := data["lastRequestTimestamp"]; ok { service.Notifications[appID] += 1 diff --git a/internal/pkg/service/cli/cmd/ci/workflow/workflows_test.go b/internal/pkg/service/cli/cmd/ci/workflow/workflows_test.go index f175da0c2a..b7b1e7f80f 100644 --- a/internal/pkg/service/cli/cmd/ci/workflow/workflows_test.go +++ b/internal/pkg/service/cli/cmd/ci/workflow/workflows_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/service/cli/dialog" "github.com/keboola/keboola-as-code/internal/pkg/service/common/configmap" @@ -24,23 +25,23 @@ func TestAskWorkflowsOptionsInteractive(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString(`Generate "validate" workflow?`)) + require.NoError(t, console.ExpectString(`Generate "validate" workflow?`)) - assert.NoError(t, console.SendLine(`n`)) // no + require.NoError(t, console.SendLine(`n`)) // no - assert.NoError(t, console.ExpectString(`Generate "push" workflow?`)) + require.NoError(t, console.ExpectString(`Generate "push" workflow?`)) - assert.NoError(t, console.SendEnter()) // enter - yes + require.NoError(t, console.SendEnter()) // enter - yes - assert.NoError(t, console.ExpectString(`Generate "pull" workflow?`)) + require.NoError(t, console.ExpectString(`Generate "pull" workflow?`)) - assert.NoError(t, console.SendLine(`n`)) // no + require.NoError(t, console.SendLine(`n`)) // no - assert.NoError(t, console.ExpectString(`Please select the main GitHub branch name:`)) + require.NoError(t, console.ExpectString(`Please select the main GitHub branch name:`)) - assert.NoError(t, console.SendEnter()) // enter - main + require.NoError(t, console.SendEnter()) // enter - main - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run @@ -53,9 +54,9 @@ func TestAskWorkflowsOptionsInteractive(t *testing.T) { }, out) // Close terminal - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) } func TestAskWorkflowsOptionsByFlag(t *testing.T) { diff --git a/internal/pkg/service/cli/cmd/cmd_test.go b/internal/pkg/service/cli/cmd/cmd_test.go index 97229c92d9..cfa8134d71 100644 --- a/internal/pkg/service/cli/cmd/cmd_test.go +++ b/internal/pkg/service/cli/cmd/cmd_test.go @@ -232,7 +232,6 @@ func TestGetLogFileFromFlags(t *testing.T) { tempDir := t.TempDir() root.globalFlags.LogFile.Value = filesystem.Join(tempDir, "log-file.txt") root.setupLogger() - assert.Equal(t, root.globalFlags.LogFile, root.globalFlags.LogFile) assert.False(t, root.logFile.IsTemp()) assert.NoError(t, root.logFile.File().Close()) } diff --git a/internal/pkg/service/cli/cmd/local/create/config/dialog_test.go b/internal/pkg/service/cli/cmd/local/create/config/dialog_test.go index 8103f8344a..55029bde7d 100644 --- a/internal/pkg/service/cli/cmd/local/create/config/dialog_test.go +++ b/internal/pkg/service/cli/cmd/local/create/config/dialog_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -42,18 +43,18 @@ func TestAskCreateConfig(t *testing.T) { "branches": [{"id": 123, "path": "main"}] } ` - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile( + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile( filesystem.Join(filesystem.MetadataDir, manifest.FileName), fmt.Sprintf(manifestContent, 123, `foo.bar.com`), ))) // Create branch files - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`main`, naming.MetaFile), `{"name": "Main"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`main`, naming.DescriptionFile), ``))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`main`, naming.MetaFile), `{"name": "Main"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`main`, naming.DescriptionFile), ``))) // Load project projectState, err := deps.MockedProject(fs).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) // Interaction wg := sync.WaitGroup{} @@ -61,27 +62,27 @@ func TestAskCreateConfig(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select the target branch")) + require.NoError(t, console.ExpectString("Select the target branch")) - assert.NoError(t, console.SendEnter()) // enter - Main + require.NoError(t, console.SendEnter()) // enter - Main - assert.NoError(t, console.ExpectString("Select the target component")) + require.NoError(t, console.ExpectString("Select the target component")) - assert.NoError(t, console.SendLine("extractor generic\n")) + require.NoError(t, console.SendLine("extractor generic\n")) - assert.NoError(t, console.ExpectString("Enter a name for the new config")) + require.NoError(t, console.ExpectString("Enter a name for the new config")) - assert.NoError(t, console.SendLine(`Foo Bar`)) + require.NoError(t, console.SendLine(`Foo Bar`)) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run opts, err := AskCreateConfig(projectState, d, deps, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, createConfig.Options{ diff --git a/internal/pkg/service/cli/cmd/local/create/row/dialog_test.go b/internal/pkg/service/cli/cmd/local/create/row/dialog_test.go index 976ae2245a..d4655de0fc 100644 --- a/internal/pkg/service/cli/cmd/local/create/row/dialog_test.go +++ b/internal/pkg/service/cli/cmd/local/create/row/dialog_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" @@ -50,24 +51,24 @@ func TestAskCreateRow(t *testing.T) { ] } ` - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile( + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile( filesystem.Join(filesystem.MetadataDir, manifest.FileName), fmt.Sprintf(manifestContent, 123, `foo.bar.com`), ))) // Create branch files - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`main`, naming.MetaFile), `{"name": "Main"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`main`, naming.DescriptionFile), ``))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`main`, naming.MetaFile), `{"name": "Main"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(`main`, naming.DescriptionFile), ``))) // Create config files configDir := filesystem.Join(`main`, `extractor`, `keboola.ex-db-mysql`, `my-config`) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(configDir, naming.MetaFile), `{"name": "My Config"}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(configDir, naming.ConfigFile), `{}`))) - assert.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(configDir, naming.DescriptionFile), ``))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(configDir, naming.MetaFile), `{"name": "My Config"}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(configDir, naming.ConfigFile), `{}`))) + require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile(filesystem.Join(configDir, naming.DescriptionFile), ``))) // Test dependencies projectState, err := deps.MockedProject(fs).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) // Interaction wg := sync.WaitGroup{} @@ -75,27 +76,27 @@ func TestAskCreateRow(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select the target branch")) + require.NoError(t, console.ExpectString("Select the target branch")) - assert.NoError(t, console.SendEnter()) // enter - My Config + require.NoError(t, console.SendEnter()) // enter - My Config - assert.NoError(t, console.ExpectString("Select the target config")) + require.NoError(t, console.ExpectString("Select the target config")) - assert.NoError(t, console.SendEnter()) // enter - My Config + require.NoError(t, console.SendEnter()) // enter - My Config - assert.NoError(t, console.ExpectString("Enter a name for the new config row")) + require.NoError(t, console.ExpectString("Enter a name for the new config row")) - assert.NoError(t, console.SendLine(`Foo Bar`)) + require.NoError(t, console.SendLine(`Foo Bar`)) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run opts, err := AskCreateRow(projectState, d, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, createRow.Options{ diff --git a/internal/pkg/service/cli/cmd/local/template/rename/rename_instance_test.go b/internal/pkg/service/cli/cmd/local/template/rename/rename_instance_test.go index d66f62e67c..97bd770931 100644 --- a/internal/pkg/service/cli/cmd/local/template/rename/rename_instance_test.go +++ b/internal/pkg/service/cli/cmd/local/template/rename/rename_instance_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -24,7 +25,7 @@ func TestAskRenameInstance_Interactive(t *testing.T) { deps := dependencies.NewMocked(t, context.Background()) projectState, err := deps.MockedProject(fixtures.MinimalProjectFs(t)).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) branchKey := model.BranchKey{ID: 123} branchRaw, _ := projectState.LocalObjects().Get(branchKey) branch := branchRaw.(*model.Branch) @@ -36,7 +37,7 @@ func TestAskRenameInstance_Interactive(t *testing.T) { instanceName := "Old Name" repositoryName := "repo" tokenID := "1234" - assert.NoError(t, branch.Metadata.UpsertTemplateInstance(now, instanceID, instanceName, templateID, repositoryName, version, tokenID, nil)) + require.NoError(t, branch.Metadata.UpsertTemplateInstance(now, instanceID, instanceName, templateID, repositoryName, version, tokenID, nil)) instance, _, _ := branch.Metadata.TemplateInstance(instanceID) // Interaction @@ -45,29 +46,29 @@ func TestAskRenameInstance_Interactive(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select branch:")) + require.NoError(t, console.ExpectString("Select branch:")) - assert.NoError(t, console.SendEnter()) // enter - Main + require.NoError(t, console.SendEnter()) // enter - Main - assert.NoError(t, console.ExpectString("Select template instance:")) + require.NoError(t, console.ExpectString("Select template instance:")) - assert.NoError(t, console.SendEnter()) // enter - tmpl1 + require.NoError(t, console.SendEnter()) // enter - tmpl1 - assert.NoError(t, console.ExpectString("Instance Name")) + require.NoError(t, console.ExpectString("Instance Name")) - assert.NoError(t, console.ExpectString("(Old Name)")) + require.NoError(t, console.ExpectString("(Old Name)")) - assert.NoError(t, console.SendLine("New Name")) + require.NoError(t, console.SendLine("New Name")) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run opts, err := AskRenameInstance(projectState, d, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) assert.Equal(t, renameOp.Options{ Branch: branchKey, @@ -83,7 +84,7 @@ func TestAskRenameInstance_Noninteractive(t *testing.T) { deps := dependencies.NewMocked(t, context.Background()) projectState, err := deps.MockedProject(fixtures.MinimalProjectFs(t)).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) branchKey := model.BranchKey{ID: 123} branchRaw, _ := projectState.LocalObjects().Get(branchKey) branch := branchRaw.(*model.Branch) @@ -95,7 +96,7 @@ func TestAskRenameInstance_Noninteractive(t *testing.T) { instanceName := "Old Name" repositoryName := "repo" tokenID := "1234" - assert.NoError(t, branch.Metadata.UpsertTemplateInstance(now, instanceID, instanceName, templateID, repositoryName, version, tokenID, nil)) + require.NoError(t, branch.Metadata.UpsertTemplateInstance(now, instanceID, instanceName, templateID, repositoryName, version, tokenID, nil)) instance, _, _ := branch.Metadata.TemplateInstance(instanceID) f := Flags{ @@ -104,7 +105,7 @@ func TestAskRenameInstance_Noninteractive(t *testing.T) { NewName: configmap.Value[string]{Value: "New Name", SetBy: configmap.SetByFlag}, } opts, err := AskRenameInstance(projectState, d, f) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, renameOp.Options{ Branch: branchKey, Instance: *instance, diff --git a/internal/pkg/service/cli/cmd/local/template/upgrade/upgrade_template_test.go b/internal/pkg/service/cli/cmd/local/template/upgrade/upgrade_template_test.go index 6bdeaa1d5b..d5dfa8dc1e 100644 --- a/internal/pkg/service/cli/cmd/local/template/upgrade/upgrade_template_test.go +++ b/internal/pkg/service/cli/cmd/local/template/upgrade/upgrade_template_test.go @@ -7,6 +7,7 @@ import ( "github.com/keboola/go-utils/pkg/orderedmap" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" "github.com/keboola/keboola-as-code/internal/pkg/service/cli/dialog" @@ -41,14 +42,14 @@ func TestAskUpgradeTemplate(t *testing.T) { configContent := orderedmap.New() rowContent := orderedmap.New() configMetadata.AddInputUsage("input1", orderedmap.PathFromStr("foo.bar"), nil) - assert.NoError(t, configContent.SetNested("foo.bar", "old value 1")) // <<<<<<<<<<< + require.NoError(t, configContent.SetNested("foo.bar", "old value 1")) // <<<<<<<<<<< configMetadata.AddRowInputUsage(configRowKey.ID, "input2", orderedmap.PathFromStr("foo.bar"), nil) - assert.NoError(t, rowContent.SetNested("foo.bar", "old value 2")) // <<<<<<<<<<< - assert.NoError(t, projectState.Set(&model.ConfigState{ + require.NoError(t, rowContent.SetNested("foo.bar", "old value 2")) // <<<<<<<<<<< + require.NoError(t, projectState.Set(&model.ConfigState{ ConfigManifest: &model.ConfigManifest{ConfigKey: configKey}, Local: &model.Config{ConfigKey: configKey, Metadata: configMetadata, Content: configContent}, })) - assert.NoError(t, projectState.Set(&model.ConfigRowState{ + require.NoError(t, projectState.Set(&model.ConfigRowState{ ConfigRowManifest: &model.ConfigRowManifest{ConfigRowKey: configRowKey}, Local: &model.ConfigRow{ConfigRowKey: configRowKey, Content: rowContent}, })) @@ -130,68 +131,68 @@ func TestAskUpgradeTemplate(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Please select which steps you want to fill.")) + require.NoError(t, console.ExpectString("Please select which steps you want to fill.")) // Step 1 and 2 are pre-selected, because Input 1 and 2 have been found in config/row. - assert.NoError(t, console.ExpectString("Select steps:")) + require.NoError(t, console.ExpectString("Select steps:")) - assert.NoError(t, console.ExpectString("[x]")) + require.NoError(t, console.ExpectString("[x]")) - assert.NoError(t, console.ExpectString("Step 1 - Step Description")) + require.NoError(t, console.ExpectString("Step 1 - Step Description")) - assert.NoError(t, console.ExpectString("[x]")) + require.NoError(t, console.ExpectString("[x]")) - assert.NoError(t, console.ExpectString("Step 2 - Step Description")) + require.NoError(t, console.ExpectString("Step 2 - Step Description")) - assert.NoError(t, console.ExpectString("[ ]")) + require.NoError(t, console.ExpectString("[ ]")) - assert.NoError(t, console.ExpectString("Step 3 - Step Description")) + require.NoError(t, console.ExpectString("Step 3 - Step Description")) - assert.NoError(t, console.ExpectString("[ ]")) + require.NoError(t, console.ExpectString("[ ]")) - assert.NoError(t, console.ExpectString("Step 4 - Step Description")) + require.NoError(t, console.ExpectString("Step 4 - Step Description")) - assert.NoError(t, console.Send(DownArrow)) // move to step 4 + require.NoError(t, console.Send(DownArrow)) // move to step 4 - assert.NoError(t, console.Send(DownArrow)) + require.NoError(t, console.Send(DownArrow)) - assert.NoError(t, console.Send(DownArrow)) + require.NoError(t, console.Send(DownArrow)) - assert.NoError(t, console.Send(Space)) // select step 4 + require.NoError(t, console.Send(Space)) // select step 4 - assert.NoError(t, console.Send(Enter)) // confirm the selection + require.NoError(t, console.Send(Enter)) // confirm the selection - assert.NoError(t, console.ExpectString("Step 1")) + require.NoError(t, console.ExpectString("Step 1")) - assert.NoError(t, console.ExpectString("input1:")) + require.NoError(t, console.ExpectString("input1:")) - assert.NoError(t, console.ExpectString("(old value 1)")) + require.NoError(t, console.ExpectString("(old value 1)")) - assert.NoError(t, console.SendLine(Enter)) // use default/old value + require.NoError(t, console.SendLine(Enter)) // use default/old value - assert.NoError(t, console.ExpectString("Step 2")) + require.NoError(t, console.ExpectString("Step 2")) - assert.NoError(t, console.ExpectString("input2:")) + require.NoError(t, console.ExpectString("input2:")) - assert.NoError(t, console.ExpectString("(old value 2)")) + require.NoError(t, console.ExpectString("(old value 2)")) - assert.NoError(t, console.SendLine("new value 2")) // fill new value + require.NoError(t, console.SendLine("new value 2")) // fill new value - assert.NoError(t, console.ExpectString("Step 4")) + require.NoError(t, console.ExpectString("Step 4")) - assert.NoError(t, console.ExpectString("input4:")) + require.NoError(t, console.ExpectString("input4:")) - assert.NoError(t, console.SendLine("value 4")) + require.NoError(t, console.SendLine("value 4")) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() output, err := AskUpgradeTemplateOptions(context.Background(), d, deps, projectState, branchKey, instance, stepsGroups, configmap.NewValue("input4")) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, upgradeTemplate.Options{ diff --git a/internal/pkg/service/cli/cmd/local/template/use/use_template_test.go b/internal/pkg/service/cli/cmd/local/template/use/use_template_test.go index 163e2486b1..9a79a4ee24 100644 --- a/internal/pkg/service/cli/cmd/local/template/use/use_template_test.go +++ b/internal/pkg/service/cli/cmd/local/template/use/use_template_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/fixtures" "github.com/keboola/keboola-as-code/internal/pkg/model" @@ -32,7 +33,7 @@ func TestAskUseTemplate_ShowIfMet(t *testing.T) { deps := dependencies.NewMocked(t, context.Background()) projectState, err := deps.MockedProject(fixtures.MinimalProjectFs(t)).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) // Set fake file editor d.Prompt.(*interactive.Prompt).SetEditor(`true`) @@ -43,84 +44,84 @@ func TestAskUseTemplate_ShowIfMet(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select the target branch:")) + require.NoError(t, console.ExpectString("Select the target branch:")) - assert.NoError(t, console.SendEnter()) // enter - Main + require.NoError(t, console.SendEnter()) // enter - Main - assert.NoError(t, console.ExpectString("Instance Name:")) + require.NoError(t, console.ExpectString("Instance Name:")) - assert.NoError(t, console.SendLine("My Instance")) + require.NoError(t, console.SendLine("My Instance")) - assert.NoError(t, console.ExpectString("Enter your Facebook username")) + require.NoError(t, console.ExpectString("Enter your Facebook username")) - assert.NoError(t, console.ExpectString("Facebook username")) + require.NoError(t, console.ExpectString("Facebook username")) // username can contain alphanum only - assert.NoError(t, console.SendLine("u-s")) + require.NoError(t, console.SendLine("u-s")) - assert.NoError(t, console.ExpectString(`Facebook username can only contain alphanumeric characters`)) + require.NoError(t, console.ExpectString(`Facebook username can only contain alphanumeric characters`)) - assert.NoError(t, console.Send(strings.Repeat(Backspace, 3))) // remove "u-s" + require.NoError(t, console.Send(strings.Repeat(Backspace, 3))) // remove "u-s" - assert.NoError(t, console.SendLine("username")) + require.NoError(t, console.SendLine("username")) - assert.NoError(t, console.ExpectString("Enter your Facebook password")) + require.NoError(t, console.ExpectString("Enter your Facebook password")) - assert.NoError(t, console.ExpectString("Facebook password")) + require.NoError(t, console.ExpectString("Facebook password")) - assert.NoError(t, console.SendLine("password")) + require.NoError(t, console.SendLine("password")) - assert.NoError(t, console.ExpectString("Enter your age")) + require.NoError(t, console.ExpectString("Enter your age")) - assert.NoError(t, console.SendLine("text")) // enter invalid string value + require.NoError(t, console.SendLine("text")) // enter invalid string value - assert.NoError(t, console.ExpectString(`Sorry, your reply was invalid: value "text" is not integer`)) + require.NoError(t, console.ExpectString(`Sorry, your reply was invalid: value "text" is not integer`)) - assert.NoError(t, console.Send(strings.Repeat(Backspace, 4))) // remove "text" + require.NoError(t, console.Send(strings.Repeat(Backspace, 4))) // remove "text" - assert.NoError(t, console.SendLine("25")) // enter valid numeric value + require.NoError(t, console.SendLine("25")) // enter valid numeric value - assert.NoError(t, console.ExpectString("Do you want to see restricted content?")) + require.NoError(t, console.ExpectString("Do you want to see restricted content?")) - assert.NoError(t, console.ExpectString("Restricted content")) + require.NoError(t, console.ExpectString("Restricted content")) - assert.NoError(t, console.SendLine("yes")) + require.NoError(t, console.SendLine("yes")) - assert.NoError(t, console.ExpectString("What do you like to drink?")) + require.NoError(t, console.ExpectString("What do you like to drink?")) - assert.NoError(t, console.ExpectString("Favorite drink")) + require.NoError(t, console.ExpectString("Favorite drink")) - assert.NoError(t, console.ExpectString("Beer")) + require.NoError(t, console.ExpectString("Beer")) - assert.NoError(t, console.ExpectString("Wine")) + require.NoError(t, console.ExpectString("Wine")) - assert.NoError(t, console.SendDownArrow()) // -> Wine + require.NoError(t, console.SendDownArrow()) // -> Wine - assert.NoError(t, console.SendSpace()) // -> select + require.NoError(t, console.SendSpace()) // -> select - assert.NoError(t, console.SendEnter()) // -> confirm + require.NoError(t, console.SendEnter()) // -> confirm - assert.NoError(t, console.ExpectString("Anything stronger?")) + require.NoError(t, console.ExpectString("Anything stronger?")) - assert.NoError(t, console.ExpectString("Stronger drinks")) + require.NoError(t, console.ExpectString("Stronger drinks")) - assert.NoError(t, console.ExpectString("Rum")) + require.NoError(t, console.ExpectString("Rum")) - assert.NoError(t, console.ExpectString("Vodka")) + require.NoError(t, console.ExpectString("Vodka")) - assert.NoError(t, console.ExpectString("Whiskey")) + require.NoError(t, console.ExpectString("Whiskey")) - assert.NoError(t, console.SendSpace()) // -> select + require.NoError(t, console.SendSpace()) // -> select - assert.NoError(t, console.SendDownArrow()) // -> Vodka + require.NoError(t, console.SendDownArrow()) // -> Vodka - assert.NoError(t, console.SendDownArrow()) // -> Whiskey + require.NoError(t, console.SendDownArrow()) // -> Whiskey - assert.NoError(t, console.SendSpace()) // -> select + require.NoError(t, console.SendSpace()) // -> select - assert.NoError(t, console.SendEnter()) // -> confirm + require.NoError(t, console.SendEnter()) // -> confirm - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run @@ -196,11 +197,11 @@ func TestAskUseTemplate_ShowIfMet(t *testing.T) { } output, err := AskUseTemplateOptions(context.Background(), d, projectState, stepsGroups, f) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, useTemplate.Options{ @@ -225,7 +226,7 @@ func TestAskUseTemplate_ShowIfNotMet(t *testing.T) { deps := dependencies.NewMocked(t, context.Background()) projectState, err := deps.MockedProject(fixtures.MinimalProjectFs(t)).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) // Set fake file editor d.Prompt.(*interactive.Prompt).SetEditor(`true`) @@ -236,27 +237,27 @@ func TestAskUseTemplate_ShowIfNotMet(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select the target branch:")) + require.NoError(t, console.ExpectString("Select the target branch:")) - assert.NoError(t, console.SendEnter()) // enter - Main + require.NoError(t, console.SendEnter()) // enter - Main - assert.NoError(t, console.ExpectString("Instance Name:")) + require.NoError(t, console.ExpectString("Instance Name:")) - assert.NoError(t, console.SendLine("My Instance")) + require.NoError(t, console.SendLine("My Instance")) - assert.NoError(t, console.ExpectString("Enter your Facebook username")) + require.NoError(t, console.ExpectString("Enter your Facebook username")) - assert.NoError(t, console.SendLine("username")) + require.NoError(t, console.SendLine("username")) - assert.NoError(t, console.ExpectString("Enter your Facebook password")) + require.NoError(t, console.ExpectString("Enter your Facebook password")) - assert.NoError(t, console.SendLine("password")) + require.NoError(t, console.SendLine("password")) - assert.NoError(t, console.ExpectString("Enter your age")) + require.NoError(t, console.ExpectString("Enter your age")) - assert.NoError(t, console.SendLine("15")) + require.NoError(t, console.SendLine("15")) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run @@ -323,11 +324,11 @@ func TestAskUseTemplate_ShowIfNotMet(t *testing.T) { } output, err := AskUseTemplateOptions(context.Background(), d, projectState, stepsGroups, f) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, useTemplate.Options{ @@ -352,7 +353,7 @@ func TestAskUseTemplate_OptionalSteps(t *testing.T) { deps := dependencies.NewMocked(t, context.Background()) projectState, err := deps.MockedProject(fixtures.MinimalProjectFs(t)).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) // Run stepsGroups := input.StepsGroups{ @@ -430,43 +431,43 @@ func TestAskUseTemplate_OptionalSteps(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select the target branch:")) + require.NoError(t, console.ExpectString("Select the target branch:")) - assert.NoError(t, console.SendEnter()) // enter - Main + require.NoError(t, console.SendEnter()) // enter - Main - assert.NoError(t, console.ExpectString("Instance Name:")) + require.NoError(t, console.ExpectString("Instance Name:")) - assert.NoError(t, console.SendLine("My Instance")) + require.NoError(t, console.SendLine("My Instance")) - assert.NoError(t, console.ExpectString("Please select which steps you want to fill.")) + require.NoError(t, console.ExpectString("Please select which steps you want to fill.")) - assert.NoError(t, console.ExpectString("Select steps:")) + require.NoError(t, console.ExpectString("Select steps:")) - assert.NoError(t, console.SendDownArrow()) // skip step 1 + require.NoError(t, console.SendDownArrow()) // skip step 1 - assert.NoError(t, console.SendDownArrow()) // skip step 2 + require.NoError(t, console.SendDownArrow()) // skip step 2 - assert.NoError(t, console.SendSpace()) // select step 3 + require.NoError(t, console.SendSpace()) // select step 3 - assert.NoError(t, console.SendDownArrow()) // move to step 4 + require.NoError(t, console.SendDownArrow()) // move to step 4 - assert.NoError(t, console.SendSpace()) // select step 4 + require.NoError(t, console.SendSpace()) // select step 4 - assert.NoError(t, console.SendEnter()) // confirm the selection + require.NoError(t, console.SendEnter()) // confirm the selection - assert.NoError(t, console.ExpectString("Step 3")) + require.NoError(t, console.ExpectString("Step 3")) - assert.NoError(t, console.ExpectString("input3:")) + require.NoError(t, console.ExpectString("input3:")) - assert.NoError(t, console.SendLine("value for input 3")) + require.NoError(t, console.SendLine("value for input 3")) - assert.NoError(t, console.ExpectString("Step 4")) + require.NoError(t, console.ExpectString("Step 4")) - assert.NoError(t, console.ExpectString("input4:")) + require.NoError(t, console.ExpectString("input4:")) - assert.NoError(t, console.SendLine("value for input 4")) + require.NoError(t, console.SendLine("value for input 4")) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() f := Flags{ @@ -476,11 +477,11 @@ func TestAskUseTemplate_OptionalSteps(t *testing.T) { } output, err := AskUseTemplateOptions(context.Background(), d, projectState, stepsGroups, f) - assert.NoError(t, err) + require.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, useTemplate.Options{ @@ -502,7 +503,7 @@ func TestAskUseTemplate_InputsFromFile(t *testing.T) { tempDir := t.TempDir() inputsFile := `{"input1": "A", "input2": "B", "input4": "C"}` // input 3 is missing inputsFilePath := filepath.Join(tempDir, "my-inputs.json") // nolint: forbidigo - assert.NoError(t, os.WriteFile(inputsFilePath, []byte(inputsFile), 0o600)) + require.NoError(t, os.WriteFile(inputsFilePath, []byte(inputsFile), 0o600)) d, _ := dialog.NewForTest(t, false) @@ -514,7 +515,7 @@ func TestAskUseTemplate_InputsFromFile(t *testing.T) { deps := dependencies.NewMocked(t, context.Background()) projectState, err := deps.MockedProject(fixtures.MinimalProjectFs(t)).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) // Run stepsGroups := input.StepsGroups{ @@ -577,7 +578,7 @@ func TestAskUseTemplate_InputsFromFile(t *testing.T) { } output, err := AskUseTemplateOptions(context.Background(), d, projectState, stepsGroups, f) - assert.NoError(t, err) + require.NoError(t, err) // Assert assert.Equal(t, useTemplate.Options{ @@ -599,7 +600,7 @@ func TestAskUseTemplate_InputsFromFile_InvalidStepsCount(t *testing.T) { tempDir := t.TempDir() inputsFile := `{"input1": "A", "input3": "B", "input4": "C"}` // input 2 is missing inputsFilePath := filepath.Join(tempDir, "my-inputs.json") // nolint: forbidigo - assert.NoError(t, os.WriteFile(inputsFilePath, []byte(inputsFile), 0o600)) + require.NoError(t, os.WriteFile(inputsFilePath, []byte(inputsFile), 0o600)) d, _ := dialog.NewForTest(t, false) @@ -610,7 +611,7 @@ func TestAskUseTemplate_InputsFromFile_InvalidStepsCount(t *testing.T) { } deps := dependencies.NewMocked(t, context.Background()) projectState, err := deps.MockedProject(fixtures.MinimalProjectFs(t)).LoadState(loadState.Options{LoadLocalState: true}, deps) - assert.NoError(t, err) + require.NoError(t, err) // Run stepsGroups := input.StepsGroups{ @@ -681,6 +682,6 @@ steps group 1 "Please select which steps you want to fill." is invalid: - Step 1, inputs: input1 - Step 3, inputs: input3, input4 ` - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, strings.Trim(expectedErr, "\n"), err.Error()) } diff --git a/internal/pkg/service/cli/cmd/remote/create/branch/dialog_test.go b/internal/pkg/service/cli/cmd/remote/create/branch/dialog_test.go index 1f9054aea9..1b94ba0634 100644 --- a/internal/pkg/service/cli/cmd/remote/create/branch/dialog_test.go +++ b/internal/pkg/service/cli/cmd/remote/create/branch/dialog_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/service/cli/dialog" "github.com/keboola/keboola-as-code/internal/pkg/service/common/configmap" @@ -22,19 +23,19 @@ func TestAskCreateBranch(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Enter a name for the new branch")) + require.NoError(t, console.ExpectString("Enter a name for the new branch")) - assert.NoError(t, console.SendLine(`Foo Bar`)) + require.NoError(t, console.SendLine(`Foo Bar`)) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run opts, err := AskCreateBranch(d, configmap.NewValue("Foo Bar")) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, createBranch.Options{ diff --git a/internal/pkg/service/cli/cmd/remote/job/run/run_test.go b/internal/pkg/service/cli/cmd/remote/job/run/run_test.go index 427fc8eb37..21da6039d5 100644 --- a/internal/pkg/service/cli/cmd/remote/job/run/run_test.go +++ b/internal/pkg/service/cli/cmd/remote/job/run/run_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/service/common/configmap" "github.com/keboola/keboola-as-code/pkg/lib/operation/project/remote/job/run" @@ -26,7 +27,7 @@ func TestParseJobRunOptions(t *testing.T) { "component3/config3@tag", "1234/component3/config3@tag", }, f) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, run.RunOptions{ Jobs: []*run.Job{ diff --git a/internal/pkg/service/cli/cmd/remote/table/create/create_table_test.go b/internal/pkg/service/cli/cmd/remote/table/create/create_table_test.go index 4ae236edc6..79163b3dd9 100644 --- a/internal/pkg/service/cli/cmd/remote/table/create/create_table_test.go +++ b/internal/pkg/service/cli/cmd/remote/table/create/create_table_test.go @@ -102,45 +102,45 @@ func TestAskCreate(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select a bucket:")) + require.NoError(t, console.ExpectString("Select a bucket:")) - assert.NoError(t, console.Send("in.c-test_1214124")) + require.NoError(t, console.Send("in.c-test_1214124")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Enter the table name.")) + require.NoError(t, console.ExpectString("Enter the table name.")) - assert.NoError(t, console.ExpectString("Table name:")) + require.NoError(t, console.ExpectString("Table name:")) - assert.NoError(t, console.Send("table1")) + require.NoError(t, console.Send("table1")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Want to define column types?")) + require.NoError(t, console.ExpectString("Want to define column types?")) - assert.NoError(t, console.Send("Y")) + require.NoError(t, console.Send("Y")) - assert.NoError(t, console.SendEnter()) // confirm + require.NoError(t, console.SendEnter()) // confirm - assert.NoError(t, console.ExpectString("Columns definitions")) + require.NoError(t, console.ExpectString("Columns definitions")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Select columns for primary key")) + require.NoError(t, console.ExpectString("Select columns for primary key")) - assert.NoError(t, console.ExpectString("id")) + require.NoError(t, console.ExpectString("id")) - assert.NoError(t, console.ExpectString("name")) + require.NoError(t, console.ExpectString("name")) - assert.NoError(t, console.SendSpace()) + require.NoError(t, console.SendSpace()) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Select columns for primary key: id")) + require.NoError(t, console.ExpectString("Select columns for primary key: id")) }() res, err := AskCreateTable(args, branch.BranchKey, buckets, d, Flags{}, deps.ProjectBackends()) - assert.NoError(t, err) + require.NoError(t, err) wg.Wait() assert.Equal(t, table.Options{ @@ -188,47 +188,47 @@ func TestAskCreate(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select a bucket:")) + require.NoError(t, console.ExpectString("Select a bucket:")) - assert.NoError(t, console.Send("in.c-test_1214124")) + require.NoError(t, console.Send("in.c-test_1214124")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Enter the table name.")) + require.NoError(t, console.ExpectString("Enter the table name.")) - assert.NoError(t, console.ExpectString("Table name:")) + require.NoError(t, console.ExpectString("Table name:")) - assert.NoError(t, console.Send("table1")) + require.NoError(t, console.Send("table1")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Want to define column types?")) + require.NoError(t, console.ExpectString("Want to define column types?")) - assert.NoError(t, console.Send("N")) + require.NoError(t, console.Send("N")) - assert.NoError(t, console.SendEnter()) // confirm + require.NoError(t, console.SendEnter()) // confirm - assert.NoError(t, console.ExpectString("Enter a comma-separated list of column names.")) + require.NoError(t, console.ExpectString("Enter a comma-separated list of column names.")) - assert.NoError(t, console.Send("id,name")) + require.NoError(t, console.Send("id,name")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Select columns for primary key")) + require.NoError(t, console.ExpectString("Select columns for primary key")) - assert.NoError(t, console.ExpectString("id")) + require.NoError(t, console.ExpectString("id")) - assert.NoError(t, console.ExpectString("name")) + require.NoError(t, console.ExpectString("name")) - assert.NoError(t, console.SendSpace()) + require.NoError(t, console.SendSpace()) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Select columns for primary key: id")) + require.NoError(t, console.ExpectString("Select columns for primary key: id")) }() res, err := AskCreateTable(args, branch.BranchKey, buckets, d, Flags{}, deps.ProjectBackends()) - assert.NoError(t, err) + require.NoError(t, err) wg.Wait() assert.Equal(t, table.Options{ @@ -266,31 +266,31 @@ func TestAskCreate(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select a bucket:")) + require.NoError(t, console.ExpectString("Select a bucket:")) - assert.NoError(t, console.Send("in.c-test_1214124")) + require.NoError(t, console.Send("in.c-test_1214124")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Enter the table name.")) + require.NoError(t, console.ExpectString("Enter the table name.")) - assert.NoError(t, console.ExpectString("Table name:")) + require.NoError(t, console.ExpectString("Table name:")) - assert.NoError(t, console.Send("table1")) + require.NoError(t, console.Send("table1")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Select columns for primary key")) + require.NoError(t, console.ExpectString("Select columns for primary key")) - assert.NoError(t, console.ExpectString("id")) + require.NoError(t, console.ExpectString("id")) - assert.NoError(t, console.ExpectString("name")) + require.NoError(t, console.ExpectString("name")) - assert.NoError(t, console.SendSpace()) + require.NoError(t, console.SendSpace()) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Select columns for primary key: id")) + require.NoError(t, console.ExpectString("Select columns for primary key: id")) }() tempDir := t.TempDir() @@ -313,7 +313,7 @@ func TestAskCreate(t *testing.T) { ColumnsFrom: configmap.NewValueWithOrigin(filePath, configmap.SetByFlag), } res, err := AskCreateTable(args, branch.BranchKey, buckets, d, f, deps.ProjectBackends()) - assert.NoError(t, err) + require.NoError(t, err) wg.Wait() assert.Equal(t, table.Options{ @@ -361,31 +361,31 @@ func TestAskCreate(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Select a bucket:")) + require.NoError(t, console.ExpectString("Select a bucket:")) - assert.NoError(t, console.Send("in.c-test_1214124")) + require.NoError(t, console.Send("in.c-test_1214124")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Enter the table name.")) + require.NoError(t, console.ExpectString("Enter the table name.")) - assert.NoError(t, console.ExpectString("Table name:")) + require.NoError(t, console.ExpectString("Table name:")) - assert.NoError(t, console.Send("table1")) + require.NoError(t, console.Send("table1")) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Select columns for primary key")) + require.NoError(t, console.ExpectString("Select columns for primary key")) - assert.NoError(t, console.ExpectString("id")) + require.NoError(t, console.ExpectString("id")) - assert.NoError(t, console.ExpectString("name")) + require.NoError(t, console.ExpectString("name")) - assert.NoError(t, console.SendSpace()) + require.NoError(t, console.SendSpace()) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectString("Select columns for primary key: id")) + require.NoError(t, console.ExpectString("Select columns for primary key: id")) }() // set flag --columns @@ -393,7 +393,7 @@ func TestAskCreate(t *testing.T) { Columns: configmap.NewValueWithOrigin([]string{"id", "name"}, configmap.SetByFlag), } res, err := AskCreateTable(args, branch.BranchKey, buckets, d, f, deps.ProjectBackends()) - assert.NoError(t, err) + require.NoError(t, err) wg.Wait() assert.Equal(t, table.Options{ diff --git a/internal/pkg/service/cli/cmd/remote/table/preview/preview_test.go b/internal/pkg/service/cli/cmd/remote/table/preview/preview_test.go index c329c633cd..84b3775a6b 100644 --- a/internal/pkg/service/cli/cmd/remote/table/preview/preview_test.go +++ b/internal/pkg/service/cli/cmd/remote/table/preview/preview_test.go @@ -5,6 +5,7 @@ import ( "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/pkg/lib/operation/project/remote/table/preview" ) @@ -62,7 +63,7 @@ func TestParseWhereFilter(t *testing.T) { for _, c := range cases { actual, err := ParseWhereFilter(c.input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, c.expected, actual) } } @@ -79,7 +80,7 @@ func TestParseWhereFilter_Errors(t *testing.T) { for _, c := range cases { actual, err := ParseWhereFilter(c) - assert.Error(t, err) + require.Error(t, err) assert.Empty(t, actual) } } @@ -109,7 +110,7 @@ func TestParseColumnOrder(t *testing.T) { for _, c := range cases { actual, err := ParseColumnOrder(c.input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, c.expected, actual) } } diff --git a/internal/pkg/service/cli/cmd/remote/workspace/create/create_workspace_test.go b/internal/pkg/service/cli/cmd/remote/workspace/create/create_workspace_test.go index 22c597a9b4..1b62e583a4 100644 --- a/internal/pkg/service/cli/cmd/remote/workspace/create/create_workspace_test.go +++ b/internal/pkg/service/cli/cmd/remote/workspace/create/create_workspace_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/service/cli/dialog" "github.com/keboola/keboola-as-code/pkg/lib/operation/project/remote/workspace/create" @@ -21,28 +22,28 @@ func TestAskCreateWorkspace(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Enter a name for the new workspace")) + require.NoError(t, console.ExpectString("Enter a name for the new workspace")) - assert.NoError(t, console.SendLine("foo")) + require.NoError(t, console.SendLine("foo")) - assert.NoError(t, console.ExpectString("Select a type for the new workspace")) + require.NoError(t, console.ExpectString("Select a type for the new workspace")) - assert.NoError(t, console.SendDownArrow()) - assert.NoError(t, console.SendEnter()) // python + require.NoError(t, console.SendDownArrow()) + require.NoError(t, console.SendEnter()) // python - assert.NoError(t, console.ExpectString("Select a size for the new workspace")) + require.NoError(t, console.ExpectString("Select a size for the new workspace")) - assert.NoError(t, console.SendEnter()) // small + require.NoError(t, console.SendEnter()) // small - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run opts, err := AskCreateWorkspace(d, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, create.CreateOptions{ diff --git a/internal/pkg/service/cli/cmd/sync/init/allowed_branches_test.go b/internal/pkg/service/cli/cmd/sync/init/allowed_branches_test.go index b41f0be544..914c7deb70 100644 --- a/internal/pkg/service/cli/cmd/sync/init/allowed_branches_test.go +++ b/internal/pkg/service/cli/cmd/sync/init/allowed_branches_test.go @@ -9,6 +9,7 @@ import ( "github.com/jarcoal/httpmock" "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" "github.com/keboola/keboola-as-code/internal/pkg/service/cli/dialog" @@ -37,10 +38,10 @@ func TestAskAllowedBranchesByFlag(t *testing.T) { // No interaction expected allowedBranches, err := AskAllowedBranches(context.Background(), deps, d, f) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, model.AllowedBranches{"foo", "bar"}, allowedBranches) - assert.NoError(t, console.Tty().Close()) - assert.NoError(t, console.Close()) + require.NoError(t, console.Tty().Close()) + require.NoError(t, console.Close()) } // TestAllowedBranchesDefaultValue use default value if terminal is not interactive. @@ -62,7 +63,7 @@ func TestAskAllowedBranchesDefaultValue(t *testing.T) { // No interaction expected allowedBranches, err := AskAllowedBranches(context.Background(), deps, d, f) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, model.AllowedBranches{model.AllBranchesDef}, allowedBranches) } @@ -85,15 +86,15 @@ func TestAskAllowedBranchesOnlyMain(t *testing.T) { go func() { defer wg.Done() selectOption(t, 1, console) // only main branch - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run allowedBranches, err := AskAllowedBranches(context.Background(), deps, d, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, model.AllowedBranches{model.MainBranchDef}, allowedBranches) @@ -118,15 +119,15 @@ func TestAskAllowedBranchesAllBranches(t *testing.T) { go func() { defer wg.Done() selectOption(t, 2, console) // all branches - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run allowedBranches, err := AskAllowedBranches(context.Background(), deps, d, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, model.AllowedBranches{model.AllBranchesDef}, allowedBranches) @@ -156,31 +157,31 @@ func TestAskAllowedBranchesSelectedBranches(t *testing.T) { go func() { defer wg.Done() selectOption(t, 3, console) // selected branches - assert.NoError(t, console.ExpectString(`Main (10)`)) - assert.NoError(t, console.ExpectString(`foo (20)`)) - assert.NoError(t, console.ExpectString(`bar (30)`)) - assert.NoError(t, console.ExpectString(`baz (40)`)) + require.NoError(t, console.ExpectString(`Main (10)`)) + require.NoError(t, console.ExpectString(`foo (20)`)) + require.NoError(t, console.ExpectString(`bar (30)`)) + require.NoError(t, console.ExpectString(`baz (40)`)) time.Sleep(50 * time.Millisecond) // Skip Main - assert.NoError(t, console.SendDownArrow()) + require.NoError(t, console.SendDownArrow()) // Select foo - assert.NoError(t, console.SendSpace()) - assert.NoError(t, console.SendDownArrow()) + require.NoError(t, console.SendSpace()) + require.NoError(t, console.SendDownArrow()) // Skip bar - assert.NoError(t, console.SendDownArrow()) + require.NoError(t, console.SendDownArrow()) // Select baz - assert.NoError(t, console.SendSpace()) - assert.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.SendSpace()) + require.NoError(t, console.SendEnter()) + require.NoError(t, console.ExpectEOF()) }() // Run allowedBranches, err := AskAllowedBranches(context.Background(), deps, d, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert, foo and baz IDs assert.Equal(t, model.AllowedBranches{"20", "40"}, allowedBranches) @@ -210,19 +211,19 @@ func TestAskAllowedBranchesTypeList(t *testing.T) { go func() { defer wg.Done() selectOption(t, 4, console) // type custom definitions - assert.NoError(t, console.ExpectString("Please enter one branch definition per line.")) - assert.NoError(t, console.Send("f**\n")) - assert.NoError(t, console.Send("b*z\n")) - assert.NoError(t, console.Send("\n\n\n")) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectString("Please enter one branch definition per line.")) + require.NoError(t, console.Send("f**\n")) + require.NoError(t, console.Send("b*z\n")) + require.NoError(t, console.Send("\n\n\n")) + require.NoError(t, console.ExpectEOF()) }() // Run allowedBranches, err := AskAllowedBranches(context.Background(), deps, d, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert, foo and baz IDs assert.Equal(t, model.AllowedBranches{"f**", "b*z"}, allowedBranches) @@ -232,15 +233,15 @@ func TestAskAllowedBranchesTypeList(t *testing.T) { func selectOption(t *testing.T, option int, c terminal.Console) { t.Helper() - assert.NoError(t, c.ExpectString("Allowed project's branches:")) - assert.NoError(t, c.ExpectString(ModeMainBranch)) - assert.NoError(t, c.ExpectString(ModeAllBranches)) - assert.NoError(t, c.ExpectString(ModeSelectSpecific)) - assert.NoError(t, c.ExpectString(ModeTypeList)) + require.NoError(t, c.ExpectString("Allowed project's branches:")) + require.NoError(t, c.ExpectString(ModeMainBranch)) + require.NoError(t, c.ExpectString(ModeAllBranches)) + require.NoError(t, c.ExpectString(ModeSelectSpecific)) + require.NoError(t, c.ExpectString(ModeTypeList)) for i := 1; i < option; i++ { - assert.NoError(t, c.SendDownArrow()) + require.NoError(t, c.SendDownArrow()) } - assert.NoError(t, c.SendEnter()) + require.NoError(t, c.SendEnter()) } func registerMockedBranchesResponse(httpTransport *httpmock.MockTransport, branches []*keboola.Branch) { diff --git a/internal/pkg/service/cli/cmd/sync/init/init_test.go b/internal/pkg/service/cli/cmd/sync/init/init_test.go index 5936a28ad3..80b0de9029 100644 --- a/internal/pkg/service/cli/cmd/sync/init/init_test.go +++ b/internal/pkg/service/cli/cmd/sync/init/init_test.go @@ -7,6 +7,7 @@ import ( "github.com/jarcoal/httpmock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" "github.com/keboola/keboola-as-code/internal/pkg/naming" @@ -37,39 +38,39 @@ func TestDialogs_AskInitOptions(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Allowed project's branches:")) + require.NoError(t, console.ExpectString("Allowed project's branches:")) - assert.NoError(t, console.SendEnter()) // enter, first option "only main branch" + require.NoError(t, console.SendEnter()) // enter, first option "only main branch" - assert.NoError(t, console.ExpectString(`Generate workflows files for GitHub Actions?`)) + require.NoError(t, console.ExpectString(`Generate workflows files for GitHub Actions?`)) - assert.NoError(t, console.SendEnter()) // enter - yes + require.NoError(t, console.SendEnter()) // enter - yes - assert.NoError(t, console.ExpectString(`Generate "validate" workflow?`)) + require.NoError(t, console.ExpectString(`Generate "validate" workflow?`)) - assert.NoError(t, console.SendEnter()) // enter - yes + require.NoError(t, console.SendEnter()) // enter - yes - assert.NoError(t, console.ExpectString(`Generate "push" workflow?`)) + require.NoError(t, console.ExpectString(`Generate "push" workflow?`)) - assert.NoError(t, console.SendEnter()) // enter - yes + require.NoError(t, console.SendEnter()) // enter - yes - assert.NoError(t, console.ExpectString(`Generate "pull" workflow?`)) + require.NoError(t, console.ExpectString(`Generate "pull" workflow?`)) - assert.NoError(t, console.SendLine(`n`)) + require.NoError(t, console.SendLine(`n`)) - assert.NoError(t, console.ExpectString(`Please select the main GitHub branch name:`)) + require.NoError(t, console.ExpectString(`Please select the main GitHub branch name:`)) - assert.NoError(t, console.SendEnter()) // enter - main + require.NoError(t, console.SendEnter()) // enter - main - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run opts, err := AskInitOptions(context.Background(), d, deps, DefaultFlags()) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, initOp.Options{ @@ -106,9 +107,9 @@ func TestDialogs_AskInitOptions_No_CI(t *testing.T) { // Run opts, err := AskInitOptions(context.Background(), d, deps, f) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) - assert.NoError(t, console.Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, initOp.Options{ diff --git a/internal/pkg/service/cli/cmd/template/create/create_template_test.go b/internal/pkg/service/cli/cmd/template/create/create_template_test.go index 80a87f4203..c425167cc0 100644 --- a/internal/pkg/service/cli/cmd/template/create/create_template_test.go +++ b/internal/pkg/service/cli/cmd/template/create/create_template_test.go @@ -15,6 +15,7 @@ import ( "github.com/keboola/keboola-as-code/internal/pkg/template/input" createTemplate "github.com/keboola/keboola-as-code/pkg/lib/operation/template/local/create" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" nopPrompt "github.com/keboola/keboola-as-code/internal/pkg/service/cli/prompt/nop" @@ -107,73 +108,73 @@ func TestAskCreateTemplateInteractive(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Please enter a template public name for users.")) + require.NoError(t, console.ExpectString("Please enter a template public name for users.")) - assert.NoError(t, console.ExpectString("Template name:")) + require.NoError(t, console.ExpectString("Template name:")) - assert.NoError(t, console.SendLine(`My Super Template`)) + require.NoError(t, console.SendLine(`My Super Template`)) - assert.NoError(t, console.ExpectString("Please enter a template internal ID.")) + require.NoError(t, console.ExpectString("Please enter a template internal ID.")) - assert.NoError(t, console.ExpectString("Template ID:")) + require.NoError(t, console.ExpectString("Template ID:")) - assert.NoError(t, console.SendEnter()) // enter - use generated default value, "my-super-template" + require.NoError(t, console.SendEnter()) // enter - use generated default value, "my-super-template" - assert.NoError(t, console.ExpectString("Please enter a short template description.")) + require.NoError(t, console.ExpectString("Please enter a short template description.")) - assert.NoError(t, console.SendEnter()) // -> start editor + require.NoError(t, console.SendEnter()) // -> start editor - assert.NoError(t, console.ExpectString("Select the source branch:")) + require.NoError(t, console.ExpectString("Select the source branch:")) - assert.NoError(t, console.SendEnter()) // enter - Main + require.NoError(t, console.SendEnter()) // enter - Main - assert.NoError(t, console.ExpectString("Select the configurations to include in the template:")) + require.NoError(t, console.ExpectString("Select the configurations to include in the template:")) - assert.NoError(t, console.ExpectString("Config 1 (keboola.my-component:1)")) + require.NoError(t, console.ExpectString("Config 1 (keboola.my-component:1)")) - assert.NoError(t, console.ExpectString("Config 2 (keboola.my-component:2)")) + require.NoError(t, console.ExpectString("Config 2 (keboola.my-component:2)")) - assert.NoError(t, console.ExpectString("Config 3 (keboola.my-component:3)")) + require.NoError(t, console.ExpectString("Config 3 (keboola.my-component:3)")) - assert.NoError(t, console.SendSpace()) // -> select Config 1 + require.NoError(t, console.SendSpace()) // -> select Config 1 - assert.NoError(t, console.SendDownArrow()) // -> Config 2 + require.NoError(t, console.SendDownArrow()) // -> Config 2 - assert.NoError(t, console.SendDownArrow()) // -> Config 3 + require.NoError(t, console.SendDownArrow()) // -> Config 3 - assert.NoError(t, console.SendSpace()) // -> select + require.NoError(t, console.SendSpace()) // -> select - assert.NoError(t, console.SendEnter()) // -> confirm + require.NoError(t, console.SendEnter()) // -> confirm - assert.NoError(t, console.ExpectString("Please enter a human readable ID for each config and config row.")) + require.NoError(t, console.ExpectString("Please enter a human readable ID for each config and config row.")) - assert.NoError(t, console.SendEnter()) // -> start editor + require.NoError(t, console.SendEnter()) // -> start editor - assert.NoError(t, console.ExpectString("Please select which fields in the configurations should be user inputs.")) + require.NoError(t, console.ExpectString("Please select which fields in the configurations should be user inputs.")) - assert.NoError(t, console.SendEnter()) // -> start editor + require.NoError(t, console.SendEnter()) // -> start editor - assert.NoError(t, console.ExpectString("Please define steps and groups for user inputs specification.")) + require.NoError(t, console.ExpectString("Please define steps and groups for user inputs specification.")) - assert.NoError(t, console.SendEnter()) // -> start editor + require.NoError(t, console.SendEnter()) // -> start editor - assert.NoError(t, console.ExpectString("Please complete the user inputs specification.")) + require.NoError(t, console.ExpectString("Please complete the user inputs specification.")) - assert.NoError(t, console.SendEnter()) // -> start editor + require.NoError(t, console.SendEnter()) // -> start editor - assert.NoError(t, console.ExpectString("Select the components that are used in the templates.")) + require.NoError(t, console.ExpectString("Select the components that are used in the templates.")) - assert.NoError(t, console.SendEnter()) // enter + require.NoError(t, console.SendEnter()) // enter - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run opts, err := AskCreateTemplateOpts(context.Background(), d, deps, Flags{}) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, createTemplate.Options{ @@ -262,7 +263,7 @@ func TestAskCreateTemplateNonInteractive(t *testing.T) { // Run opts, err := AskCreateTemplateOpts(context.Background(), d, deps, f) - assert.NoError(t, err) + require.NoError(t, err) // Assert assert.Equal(t, createTemplate.Options{ @@ -372,7 +373,7 @@ func TestAskCreateTemplateAllConfigs(t *testing.T) { // Run opts, err := AskCreateTemplateOpts(context.Background(), d, deps, f) - assert.NoError(t, err) + require.NoError(t, err) // Assert assert.Equal(t, createTemplate.Options{ diff --git a/internal/pkg/service/cli/cmd/template/test/create/create_test_template_test.go b/internal/pkg/service/cli/cmd/template/test/create/create_test_template_test.go index c0c298b694..88b1898c0c 100644 --- a/internal/pkg/service/cli/cmd/template/test/create/create_test_template_test.go +++ b/internal/pkg/service/cli/cmd/template/test/create/create_test_template_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/env" fixtures "github.com/keboola/keboola-as-code/internal/pkg/fixtures/local" @@ -36,9 +37,9 @@ func TestAskCreateTemplateTestInteractive(t *testing.T) { // Prepare the template fs, err := fixtures.LoadFS(context.Background(), "template-simple", env.Empty()) - assert.NoError(t, err) + require.NoError(t, err) version, err := model.NewSemVersion("v0.0.1") - assert.NoError(t, err) + require.NoError(t, err) tmplRef := model.NewTemplateRef(model.TemplateRepository{Name: "my-repository"}, "tmpl1", version.String()) versionRec := repository.VersionRecord{ Version: version, @@ -56,7 +57,7 @@ func TestAskCreateTemplateTestInteractive(t *testing.T) { } tmpl, err := template.New(context.Background(), tmplRef, tmplRec, versionRec, fs, fs, "", testapi.MockedComponentsMap()) - assert.NoError(t, err) + require.NoError(t, err) // Interaction wg := sync.WaitGroup{} @@ -64,25 +65,25 @@ func TestAskCreateTemplateTestInteractive(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("Default Group")) + require.NoError(t, console.ExpectString("Default Group")) - assert.NoError(t, console.ExpectString("Default Step")) + require.NoError(t, console.ExpectString("Default Step")) - assert.NoError(t, console.ExpectString("Default Step Description")) + require.NoError(t, console.ExpectString("Default Step Description")) - assert.NoError(t, console.ExpectString("url description")) + require.NoError(t, console.ExpectString("url description")) - assert.NoError(t, console.ExpectString("API URL:")) + require.NoError(t, console.ExpectString("API URL:")) - assert.NoError(t, console.SendLine(`foo.bar.com`)) + require.NoError(t, console.SendLine(`foo.bar.com`)) - assert.NoError(t, console.ExpectString(`Enter the name of the environment variable that will fill input "API Token". Note that it will get prefix KBC_SECRET_.`)) + require.NoError(t, console.ExpectString(`Enter the name of the environment variable that will fill input "API Token". Note that it will get prefix KBC_SECRET_.`)) - assert.NoError(t, console.ExpectString("API Token:")) + require.NoError(t, console.ExpectString("API Token:")) - assert.NoError(t, console.SendLine(`VAR1`)) + require.NoError(t, console.SendLine(`VAR1`)) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run @@ -90,10 +91,10 @@ func TestAskCreateTemplateTestInteractive(t *testing.T) { TestName: configmap.NewValueWithOrigin("one", configmap.SetByFlag), } opts, warnings, err := AskCreateTemplateTestOptions(context.Background(), d, tmpl, f) - assert.NoError(t, err) - assert.NoError(t, console.Tty().Close()) + require.NoError(t, err) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) // Assert assert.Equal(t, createOp.Options{ diff --git a/internal/pkg/service/cli/dependencies/apihost_test.go b/internal/pkg/service/cli/dependencies/apihost_test.go index 7dd14e7624..4c7973f9ae 100644 --- a/internal/pkg/service/cli/dependencies/apihost_test.go +++ b/internal/pkg/service/cli/dependencies/apihost_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/filesystem/aferofs" "github.com/keboola/keboola-as-code/internal/pkg/service/cli/dialog" @@ -28,7 +29,7 @@ func TestStorageAPIHost_NotSet_Fallback(t *testing.T) { baseScp := &baseScope{fs: aferofs.NewMemoryFs(), dialogs: dialog.New(nopPrompt.New())} out, err := storageAPIHost(context.Background(), baseScp, "https://connection.keboola.com", configmap.NewValueWithOrigin("", configmap.SetByFlag)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "https://connection.keboola.com", out) // fallback } @@ -49,7 +50,7 @@ func TestStorageAPIHost_Empty_Fallback(t *testing.T) { baseScp := &baseScope{fs: aferofs.NewMemoryFs(), globalsFlags: flag.DefaultGlobalFlags(), dialogs: dialog.New(nopPrompt.New())} out, err := storageAPIHost(context.Background(), baseScp, "https://connection.keboola.com", configmap.NewValueWithOrigin("", configmap.SetByFlag)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "https://connection.keboola.com", out) // fallback } @@ -60,7 +61,7 @@ func TestStorageAPIHost_NoProtocol(t *testing.T) { baseScp := &baseScope{fs: aferofs.NewMemoryFs(), globalsFlags: f, dialogs: dialog.New(nopPrompt.New())} out, err := storageAPIHost(context.Background(), baseScp, "", configmap.NewValueWithOrigin("connection.keboola.local", configmap.SetByFlag)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "https://connection.keboola.local", out) } @@ -71,7 +72,7 @@ func TestStorageAPIHost_HTTP_Protocol(t *testing.T) { d := &baseScope{fs: aferofs.NewMemoryFs(), globalsFlags: f, dialogs: dialog.New(nopPrompt.New())} out, err := storageAPIHost(context.Background(), d, "", configmap.NewValueWithOrigin("http://connection.keboola.local", configmap.SetByFlag)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "http://connection.keboola.local", out) } @@ -83,7 +84,7 @@ func TestStorageAPIHost_HTTPS_Protocol(t *testing.T) { baseScp := &baseScope{fs: aferofs.NewMemoryFs(), globalsFlags: f, dialogs: dialog.New(nopPrompt.New())} out, err := storageAPIHost(context.Background(), baseScp, "", configmap.NewValueWithOrigin("https://connection.keboola.local", configmap.SetByFlag)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "https://connection.keboola.local", out) } @@ -95,6 +96,6 @@ func TestStorageAPIHost_Invalid_Protocol(t *testing.T) { baseScp := &baseScope{fs: aferofs.NewMemoryFs(), globalsFlags: f, dialogs: dialog.New(nopPrompt.New())} out, err := storageAPIHost(context.Background(), baseScp, "", configmap.NewValueWithOrigin("foo://connection.keboola.local", configmap.SetByFlag)) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "https://foo://connection.keboola.local", out) } diff --git a/internal/pkg/service/cli/dependencies/dependencies_test.go b/internal/pkg/service/cli/dependencies/dependencies_test.go index dc70368d00..977f5621f7 100644 --- a/internal/pkg/service/cli/dependencies/dependencies_test.go +++ b/internal/pkg/service/cli/dependencies/dependencies_test.go @@ -11,6 +11,7 @@ import ( "github.com/keboola/go-client/pkg/client" "github.com/keboola/go-client/pkg/keboola" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/env" "github.com/keboola/keboola-as-code/internal/pkg/filesystem" @@ -31,7 +32,7 @@ func TestDifferentProjectIdInManifestAndToken(t *testing.T) { // Create manifest fs := aferofs.NewMemoryFs() manifestContent := `{"version": 2, "project": {"id": 789, "apiHost": "mocked.transport.http"}}` - assert.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile(projectManifest.Path(), manifestContent))) + require.NoError(t, fs.WriteFile(context.Background(), filesystem.NewRawFile(projectManifest.Path(), manifestContent))) f := flag.DefaultGlobalFlags() @@ -74,9 +75,9 @@ func TestDifferentProjectIdInManifestAndToken(t *testing.T) { proc := servicectx.NewForTest(t) baseScp := newBaseScope(ctx, logger, os.Stdout, os.Stderr, proc, httpClient, fs, dialog.New(nopPrompt.New()), f, env.Empty()) localScp, err := newLocalCommandScope(ctx, baseScp, configmap.NewValueWithOrigin("mocked.transport.http", configmap.SetByFlag)) - assert.NoError(t, err) + require.NoError(t, err) _, err = newRemoteCommandScope(ctx, localScp, configmap.NewValueWithOrigin("my-secret", configmap.SetByFlag)) expected := `provided token is from the project "12345", but in manifest is defined project "789"` - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, expected, err.Error()) } diff --git a/internal/pkg/service/cli/dialog/branches_test.go b/internal/pkg/service/cli/dialog/branches_test.go index 0150fcb151..5aee300044 100644 --- a/internal/pkg/service/cli/dialog/branches_test.go +++ b/internal/pkg/service/cli/dialog/branches_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" syncInit "github.com/keboola/keboola-as-code/internal/pkg/service/cli/cmd/sync/init" @@ -29,30 +30,30 @@ func TestSelectBranchInteractive(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("LABEL:")) + require.NoError(t, console.ExpectString("LABEL:")) - assert.NoError(t, console.ExpectString("Branch 1 (1)")) + require.NoError(t, console.ExpectString("Branch 1 (1)")) - assert.NoError(t, console.ExpectString("Branch 2 (2)")) + require.NoError(t, console.ExpectString("Branch 2 (2)")) - assert.NoError(t, console.ExpectString("Branch 3 (3)")) + require.NoError(t, console.ExpectString("Branch 3 (3)")) // down arrow -> select Branch 2 - assert.NoError(t, console.SendDownArrow()) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendDownArrow()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run out, err := dialog.SelectBranch(allBranches, `LABEL`, configmap.NewValue(branch2.String())) assert.Same(t, branch2, out) - assert.NoError(t, err) + require.NoError(t, err) // Close terminal - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) } func TestSelectBranchByFlag(t *testing.T) { @@ -70,7 +71,7 @@ func TestSelectBranchByFlag(t *testing.T) { // Run out, err := dialog.SelectBranch(allBranches, `LABEL`, configmap.Value[string]{Value: branch2.Name, SetBy: configmap.SetByFlag}) assert.Same(t, branch2, out) - assert.NoError(t, err) + require.NoError(t, err) } func TestSelectBranchNonInteractive(t *testing.T) { @@ -87,7 +88,7 @@ func TestSelectBranchNonInteractive(t *testing.T) { // Run _, err := dialog.SelectBranch(allBranches, `LABEL`, configmap.Value[string]{Value: "", SetBy: configmap.SetByDefault}) - assert.ErrorContains(t, err, "please specify branch") + require.ErrorContains(t, err, "please specify branch") } func TestSelectBranchMissing(t *testing.T) { @@ -105,7 +106,7 @@ func TestSelectBranchMissing(t *testing.T) { // Run out, err := dialog.SelectBranch(allBranches, `LABEL`, configmap.NewValue("")) assert.Nil(t, out) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `please specify branch`, err.Error()) } @@ -129,42 +130,42 @@ func TestSelectBranchesInteractive(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("LABEL:")) + require.NoError(t, console.ExpectString("LABEL:")) - assert.NoError(t, console.ExpectString("Branch 1 (1)")) + require.NoError(t, console.ExpectString("Branch 1 (1)")) - assert.NoError(t, console.ExpectString("Branch 2 (2)")) + require.NoError(t, console.ExpectString("Branch 2 (2)")) - assert.NoError(t, console.ExpectString("Branch 3 (3)")) + require.NoError(t, console.ExpectString("Branch 3 (3)")) - assert.NoError(t, console.ExpectString("Branch 4 (4)")) + require.NoError(t, console.ExpectString("Branch 4 (4)")) - assert.NoError(t, console.ExpectString("Branch 5 (5)")) + require.NoError(t, console.ExpectString("Branch 5 (5)")) - assert.NoError(t, console.SendDownArrow()) // -> Branch 2 + require.NoError(t, console.SendDownArrow()) // -> Branch 2 - assert.NoError(t, console.SendSpace()) // -> select + require.NoError(t, console.SendSpace()) // -> select - assert.NoError(t, console.SendDownArrow()) // -> Branch 3 + require.NoError(t, console.SendDownArrow()) // -> Branch 3 - assert.NoError(t, console.SendDownArrow()) // -> Branch 4 + require.NoError(t, console.SendDownArrow()) // -> Branch 4 - assert.NoError(t, console.SendSpace()) // -> select + require.NoError(t, console.SendSpace()) // -> select - assert.NoError(t, console.SendEnter()) // -> confirm + require.NoError(t, console.SendEnter()) // -> confirm - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run out, err := syncInit.SelectBranches(allBranches, `LABEL`, dialog, syncInit.Flags{}) assert.Equal(t, []*model.Branch{branch2, branch4}, out) - assert.NoError(t, err) + require.NoError(t, err) // Close terminal - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) } func TestSelectBranchesByFlag(t *testing.T) { @@ -188,7 +189,7 @@ func TestSelectBranchesByFlag(t *testing.T) { // Run out, err := syncInit.SelectBranches(allBranches, `LABEL`, dialog, f) assert.Equal(t, []*model.Branch{branch2, branch4}, out) - assert.NoError(t, err) + require.NoError(t, err) } func TestSelectBranchesMissing(t *testing.T) { @@ -208,6 +209,6 @@ func TestSelectBranchesMissing(t *testing.T) { // Run out, err := syncInit.SelectBranches(allBranches, `LABEL`, dialog, syncInit.Flags{}) assert.Nil(t, out) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `please specify at least one branch`, err.Error()) } diff --git a/internal/pkg/service/cli/dialog/configs_test.go b/internal/pkg/service/cli/dialog/configs_test.go index 4e8e2d4e6b..963c2813a8 100644 --- a/internal/pkg/service/cli/dialog/configs_test.go +++ b/internal/pkg/service/cli/dialog/configs_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/model" "github.com/keboola/keboola-as-code/internal/pkg/service/common/configmap" @@ -28,30 +29,30 @@ func TestSelectConfigInteractive(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("LABEL:")) + require.NoError(t, console.ExpectString("LABEL:")) - assert.NoError(t, console.ExpectString("Config 1 (foo.bar:1)")) + require.NoError(t, console.ExpectString("Config 1 (foo.bar:1)")) - assert.NoError(t, console.ExpectString("Config 2 (foo.bar:2)")) + require.NoError(t, console.ExpectString("Config 2 (foo.bar:2)")) - assert.NoError(t, console.ExpectString("Config 3 (foo.bar:3)")) + require.NoError(t, console.ExpectString("Config 3 (foo.bar:3)")) // down arrow -> select Config 2 - assert.NoError(t, console.SendDownArrow()) - assert.NoError(t, console.SendEnter()) + require.NoError(t, console.SendDownArrow()) + require.NoError(t, console.SendEnter()) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run out, err := dialog.SelectConfig(allConfigs, `LABEL`, configmap.NewValue(config2.String())) assert.Same(t, config2, out) - assert.NoError(t, err) + require.NoError(t, err) // Close terminal - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) } func TestSelectConfigByFlag(t *testing.T) { @@ -69,7 +70,7 @@ func TestSelectConfigByFlag(t *testing.T) { // Run out, err := dialog.SelectConfig(allConfigs, `LABEL`, configmap.Value[string]{Value: "2", SetBy: configmap.SetByFlag}) assert.Same(t, config2, out) - assert.NoError(t, err) + require.NoError(t, err) } func TestSelectConfigNonInteractive(t *testing.T) { @@ -86,7 +87,7 @@ func TestSelectConfigNonInteractive(t *testing.T) { // Run _, err := dialog.SelectConfig(allConfigs, `LABEL`, configmap.NewValue("")) - assert.ErrorContains(t, err, "please specify config") + require.ErrorContains(t, err, "please specify config") } func TestSelectConfigMissing(t *testing.T) { @@ -104,7 +105,7 @@ func TestSelectConfigMissing(t *testing.T) { // Run out, err := dialog.SelectConfig(allConfigs, `LABEL`, configmap.Value[string]{Value: "", SetBy: configmap.SetByDefault}) assert.Nil(t, out) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `please specify config`, err.Error()) } @@ -128,42 +129,42 @@ func TestSelectConfigsInteractive(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("LABEL:")) + require.NoError(t, console.ExpectString("LABEL:")) - assert.NoError(t, console.ExpectString("Config 1 (foo.bar:1)")) + require.NoError(t, console.ExpectString("Config 1 (foo.bar:1)")) - assert.NoError(t, console.ExpectString("Config 2 (foo.bar:2)")) + require.NoError(t, console.ExpectString("Config 2 (foo.bar:2)")) - assert.NoError(t, console.ExpectString("Config 3 (foo.bar:3)")) + require.NoError(t, console.ExpectString("Config 3 (foo.bar:3)")) - assert.NoError(t, console.ExpectString("Config 4 (foo.bar:4)")) + require.NoError(t, console.ExpectString("Config 4 (foo.bar:4)")) - assert.NoError(t, console.ExpectString("Config 5 (foo.bar:5)")) + require.NoError(t, console.ExpectString("Config 5 (foo.bar:5)")) - assert.NoError(t, console.SendDownArrow()) // -> Config 2 + require.NoError(t, console.SendDownArrow()) // -> Config 2 - assert.NoError(t, console.SendSpace()) // -> select + require.NoError(t, console.SendSpace()) // -> select - assert.NoError(t, console.SendDownArrow()) // -> Config 3 + require.NoError(t, console.SendDownArrow()) // -> Config 3 - assert.NoError(t, console.SendDownArrow()) // -> Config 4 + require.NoError(t, console.SendDownArrow()) // -> Config 4 - assert.NoError(t, console.SendSpace()) // -> select + require.NoError(t, console.SendSpace()) // -> select - assert.NoError(t, console.SendEnter()) // -> confirm + require.NoError(t, console.SendEnter()) // -> confirm - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run out, err := dialog.SelectConfigs(allConfigs, `LABEL`, configmap.Value[string]{Value: config2.Name + config4.Name, SetBy: configmap.SetByDefault}) assert.Equal(t, []*model.ConfigWithRows{config2, config4}, out) - assert.NoError(t, err) + require.NoError(t, err) // Close terminal - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) } func TestSelectConfigsByFlag(t *testing.T) { @@ -183,7 +184,7 @@ func TestSelectConfigsByFlag(t *testing.T) { // Run out, err := dialog.SelectConfigs(allConfigs, `LABEL`, configmap.Value[string]{Value: "foo.bar:2, foo.bar:4", SetBy: configmap.SetByFlag}) assert.Equal(t, []*model.ConfigWithRows{config2, config4}, out) - assert.NoError(t, err) + require.NoError(t, err) } func TestSelectConfigsMissing(t *testing.T) { @@ -203,6 +204,6 @@ func TestSelectConfigsMissing(t *testing.T) { // Run out, err := dialog.SelectConfigs(allConfigs, `LABEL`, configmap.NewValue("")) assert.Nil(t, out) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, `please specify at least one config`, err.Error()) } diff --git a/internal/pkg/service/cli/dialog/dialog.go b/internal/pkg/service/cli/dialog/dialog.go index 539c286221..c3b65caff2 100644 --- a/internal/pkg/service/cli/dialog/dialog.go +++ b/internal/pkg/service/cli/dialog/dialog.go @@ -3,7 +3,7 @@ package dialog import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/service/cli" "github.com/keboola/keboola-as-code/internal/pkg/service/cli/prompt" @@ -25,7 +25,7 @@ func NewForTest(t *testing.T, interactive bool) (*Dialogs, terminal.Console) { if interactive { // Create virtual console console, err := terminal.New(t) - assert.NoError(t, err) + require.NoError(t, err) // Create prompt p := cli.NewPrompt(console.Tty(), console.Tty(), console.Tty(), false) diff --git a/internal/pkg/service/cli/dialog/dialog_test.go b/internal/pkg/service/cli/dialog/dialog_test.go index 0443dcc3d4..0895f7773c 100644 --- a/internal/pkg/service/cli/dialog/dialog_test.go +++ b/internal/pkg/service/cli/dialog/dialog_test.go @@ -3,7 +3,7 @@ package dialog_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/keboola/keboola-as-code/internal/pkg/service/cli" "github.com/keboola/keboola-as-code/internal/pkg/service/cli/dialog" @@ -17,7 +17,7 @@ func createDialogs(t *testing.T, interactive bool) (*dialog.Dialogs, terminal.Co if interactive { // Create virtual console console, err := terminal.New(t) - assert.NoError(t, err) + require.NoError(t, err) // Create prompt p := cli.NewPrompt(console.Tty(), console.Tty(), console.Tty(), false) diff --git a/internal/pkg/service/cli/dialog/host_test.go b/internal/pkg/service/cli/dialog/host_test.go index 3252eabdd5..ec600e7452 100644 --- a/internal/pkg/service/cli/dialog/host_test.go +++ b/internal/pkg/service/cli/dialog/host_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" . "github.com/keboola/keboola-as-code/internal/pkg/service/cli/dialog" ) @@ -20,11 +21,11 @@ func TestAskStorageAPIHost_HTTPS(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("API host: ")) + require.NoError(t, console.ExpectString("API host: ")) - assert.NoError(t, console.SendLine(`https://foo.bar.com/`)) + require.NoError(t, console.SendLine(`https://foo.bar.com/`)) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run @@ -32,9 +33,9 @@ func TestAskStorageAPIHost_HTTPS(t *testing.T) { assert.Equal(t, `https://foo.bar.com/`, out) // Close terminal - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) } func TestAskStorageAPIHost_HTTP(t *testing.T) { @@ -48,11 +49,11 @@ func TestAskStorageAPIHost_HTTP(t *testing.T) { go func() { defer wg.Done() - assert.NoError(t, console.ExpectString("API host: ")) + require.NoError(t, console.ExpectString("API host: ")) - assert.NoError(t, console.SendLine(`http://foo.bar.com/`)) + require.NoError(t, console.SendLine(`http://foo.bar.com/`)) - assert.NoError(t, console.ExpectEOF()) + require.NoError(t, console.ExpectEOF()) }() // Run @@ -60,23 +61,23 @@ func TestAskStorageAPIHost_HTTP(t *testing.T) { assert.Equal(t, `http://foo.bar.com/`, out) // Close terminal - assert.NoError(t, console.Tty().Close()) + require.NoError(t, console.Tty().Close()) wg.Wait() - assert.NoError(t, console.Close()) + require.NoError(t, console.Close()) } func TestAPIHostValidator(t *testing.T) { t.Parallel() - assert.NoError(t, StorageAPIHostValidator("connection.keboola.com")) - assert.NoError(t, StorageAPIHostValidator("connection.keboola.com/")) - assert.NoError(t, StorageAPIHostValidator("https://connection.keboola.com")) - assert.NoError(t, StorageAPIHostValidator("https://connection.keboola.com/")) + require.NoError(t, StorageAPIHostValidator("connection.keboola.com")) + require.NoError(t, StorageAPIHostValidator("connection.keboola.com/")) + require.NoError(t, StorageAPIHostValidator("https://connection.keboola.com")) + require.NoError(t, StorageAPIHostValidator("https://connection.keboola.com/")) err := StorageAPIHostValidator("") - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, "value is required", err.Error()) err = StorageAPIHostValidator("@#$$%^&%#$&") - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, "invalid host", err.Error()) } diff --git a/internal/pkg/service/cli/dialog/inputs_detail_test.go b/internal/pkg/service/cli/dialog/inputs_detail_test.go index cf94aaa8b8..ac0546494a 100644 --- a/internal/pkg/service/cli/dialog/inputs_detail_test.go +++ b/internal/pkg/service/cli/dialog/inputs_detail_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/umisama/go-regexpcache" nopPrompt "github.com/keboola/keboola-as-code/internal/pkg/service/cli/prompt/nop" @@ -29,7 +30,7 @@ func TestInputsDetailDialog_Parse_DefaultValue(t *testing.T) { // Parse d := newInputsDetailsDialog(nopPrompt.New(), testInputs(), testStepsGroups()) stepGroups, err := d.parse(context.Background(), inputsDetailDialogDefaultValue) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, testInputs().All(), d.inputs.All()) // Inputs are connected to default step group @@ -140,7 +141,7 @@ options: {"value1":"Label 1","value2":"Label 2","value3":123}