diff --git a/internal/pkg/encoding/json/schema/generate_test.go b/internal/pkg/encoding/json/schema/generate_test.go index e01fc75058..28dc6c6d7f 100644 --- a/internal/pkg/encoding/json/schema/generate_test.go +++ b/internal/pkg/encoding/json/schema/generate_test.go @@ -44,7 +44,7 @@ func TestGenerateDocument(t *testing.T) { } } ` - assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(documentJSON)) + assert.JSONEq(t, strings.TrimSpace(expected), strings.TrimSpace(documentJSON)) } func TestGenerateDocumentEmptySchema(t *testing.T) { @@ -52,7 +52,7 @@ func TestGenerateDocumentEmptySchema(t *testing.T) { document, err := GenerateDocument([]byte(`{}`)) documentJSON := json.MustEncodeString(document, true) require.NoError(t, err) - assert.Equal(t, "{}\n", documentJSON) + assert.JSONEq(t, `{}`, documentJSON) } func getSampleSchema() []byte { diff --git a/internal/pkg/encoding/jsonnet/context_test.go b/internal/pkg/encoding/jsonnet/context_test.go index 7ec55d8915..ff847401bb 100644 --- a/internal/pkg/encoding/jsonnet/context_test.go +++ b/internal/pkg/encoding/jsonnet/context_test.go @@ -18,7 +18,7 @@ func TestVmContext_Nil(t *testing.T) { t.Parallel() output, err := Evaluate(`{foo: "bar"}`, nil) require.NoError(t, err) - assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", output) + assert.JSONEq(t, `{"foo":"bar"}`, output) } func TestVmContext_Empty(t *testing.T) { @@ -26,7 +26,7 @@ func TestVmContext_Empty(t *testing.T) { ctx := NewContext() output, err := Evaluate(`{foo: "bar"}`, ctx) require.NoError(t, err) - assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", output) + assert.JSONEq(t, `{"foo":"bar"}`, output) } func TestVmContext_Pretty_False(t *testing.T) { @@ -34,7 +34,7 @@ func TestVmContext_Pretty_False(t *testing.T) { ctx := NewContext().WithPretty(false) output, err := Evaluate(`{foo: "bar"}`, ctx) require.NoError(t, err) - assert.Equal(t, `{"foo":"bar"}`, output) + assert.JSONEq(t, `{"foo":"bar"}`, output) } func TestVmContext_Complex(t *testing.T) { diff --git a/internal/pkg/encoding/jsonnet/fsimporter/fsimporter_test.go b/internal/pkg/encoding/jsonnet/fsimporter/fsimporter_test.go index ca339de012..3bddca0ff3 100644 --- a/internal/pkg/encoding/jsonnet/fsimporter/fsimporter_test.go +++ b/internal/pkg/encoding/jsonnet/fsimporter/fsimporter_test.go @@ -32,5 +32,5 @@ func TestImporter(t *testing.T) { require.NoError(t, fs.WriteFile(ctx, filesystem.NewRawFile("foo/bar/C.jsonnet", `{some: "value"}`))) out, err := jsonnet.Evaluate(`import "foo/bar/A.jsonnet"`, jsonnetCtx) require.NoError(t, err) - assert.Equal(t, "{\n \"some\": \"value\"\n}\n", out) + assert.JSONEq(t, `{"some":"value"}`, out) } diff --git a/internal/pkg/encoding/jsonnet/jsonnet_test.go b/internal/pkg/encoding/jsonnet/jsonnet_test.go index 5322102a54..e62001e1f1 100644 --- a/internal/pkg/encoding/jsonnet/jsonnet_test.go +++ b/internal/pkg/encoding/jsonnet/jsonnet_test.go @@ -13,7 +13,7 @@ func TestEvaluate(t *testing.T) { code := `{ foo: "bar" }` json, err := Evaluate(code, nil) require.NoError(t, err) - assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", json) + assert.JSONEq(t, `{"foo":"bar"}`, json) } func TestEvaluateAst(t *testing.T) { @@ -30,7 +30,7 @@ func TestEvaluateAst(t *testing.T) { } json, err := EvaluateAst(astNode, nil) require.NoError(t, err) - assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", json) + assert.JSONEq(t, `{"foo":"bar"}`, json) } func TestFormat(t *testing.T) { @@ -38,7 +38,7 @@ func TestFormat(t *testing.T) { code := `{"foo":"bar"}` jsonnetStr, err := Format(code) require.NoError(t, err) - assert.Equal(t, "{ foo: \"bar\" }\n", jsonnetStr) + assert.Equal(t, "{ foo: \"bar\" }\n", jsonnetStr) //nolint: testifylint } func TestFormatAst(t *testing.T) { @@ -54,7 +54,7 @@ func TestFormatAst(t *testing.T) { }, } jsonnetStr := FormatAst(astNode) - assert.Equal(t, "{ foo: \"bar\" }\n", jsonnetStr) + assert.Equal(t, "{ foo: \"bar\" }\n", jsonnetStr) //nolint: testifylint } func TestToAst(t *testing.T) { diff --git a/internal/pkg/filesystem/aferofs/filesystem_test.go b/internal/pkg/filesystem/aferofs/filesystem_test.go index 1f5cb48b20..53363e1275 100644 --- a/internal/pkg/filesystem/aferofs/filesystem_test.go +++ b/internal/pkg/filesystem/aferofs/filesystem_test.go @@ -601,7 +601,7 @@ func (*testCases) TestWriteFile_JsonFile(t *testing.T, fs filesystem.Fs, logger file, err := fs.ReadFile(ctx, filesystem.NewFileDef(filePath)) require.NoError(t, err) assert.NotNil(t, file) - assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", file.Content) + assert.JSONEq(t, `{"foo":"bar"}`, file.Content) } func (*testCases) TestCreateOrUpdateFile(t *testing.T, fs filesystem.Fs, _ log.DebugLogger) { diff --git a/internal/pkg/filesystem/file_test.go b/internal/pkg/filesystem/file_test.go index 6e16c7a6bc..1b7b76c38f 100644 --- a/internal/pkg/filesystem/file_test.go +++ b/internal/pkg/filesystem/file_test.go @@ -33,7 +33,7 @@ func TestRawFile_ToJsonnetFile(t *testing.T) { f, err := NewRawFile(`path`, `{foo:"bar"}`).ToJSONNetFile(nil) require.NoError(t, err) assert.Equal(t, `path`, f.Path()) - assert.Equal(t, "{\n \"foo\": \"bar\"\n}\n", jsonnet.MustEvaluateAst(f.Content, nil)) + assert.JSONEq(t, `{"foo":"bar"}`, jsonnet.MustEvaluateAst(f.Content, nil)) } func TestNewJsonFile(t *testing.T) { @@ -54,7 +54,7 @@ func TestJsonFile_ToRawFile(t *testing.T) { 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) + assert.JSONEq(t, `{"foo":"bar"}`, f.Content) } func TestJsonFile_ToJsonnetFile(t *testing.T) { @@ -64,7 +64,7 @@ func TestJsonFile_ToJsonnetFile(t *testing.T) { f, err := NewJSONFile(`path.json`, m).ToJsonnetFile() require.NoError(t, err) assert.Equal(t, `path.jsonnet`, f.Path()) - assert.Equal(t, "{\n foo: \"bar\",\n}\n", jsonnet.FormatAst(f.Content)) + assert.Equal(t, "{\n foo: \"bar\",\n}\n", jsonnet.FormatAst(f.Content)) //nolint: testifylint } func TestNewJsonnetFile(t *testing.T) { @@ -94,7 +94,7 @@ func TestJsonnetFile_ToRawFile(t *testing.T) { require.NoError(t, err) assert.Equal(t, `path`, file.Path()) assert.Equal(t, `desc`, file.Description()) - assert.Equal(t, "{ foo: \"bar\" }\n", file.Content) + assert.Equal(t, "{ foo: \"bar\" }\n", file.Content) //nolint: testifylint } func TestJsonnetFile_ToJsonFile(t *testing.T) { @@ -146,7 +146,7 @@ func TestJsonnetFile_ToRawJsonFile(t *testing.T) { 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) + assert.JSONEq(t, `{"foo":"bar"}`, rawJSONFile.Content) } func TestFiles(t *testing.T) { diff --git a/internal/pkg/filesystem/filesystem.go b/internal/pkg/filesystem/filesystem.go index 4744eccb40..5595aca5dc 100644 --- a/internal/pkg/filesystem/filesystem.go +++ b/internal/pkg/filesystem/filesystem.go @@ -24,7 +24,7 @@ const ( // nolint: gochecknoglobals var ( - SkipDir = fs.SkipDir + SkipDir = fs.SkipDir // nolint: errname ErrNotExist = os.ErrNotExist ) diff --git a/internal/pkg/mapper/defaultbucket/local_load_test.go b/internal/pkg/mapper/defaultbucket/local_load_test.go index e31e4ea7d4..752008b627 100644 --- a/internal/pkg/mapper/defaultbucket/local_load_test.go +++ b/internal/pkg/mapper/defaultbucket/local_load_test.go @@ -123,7 +123,7 @@ WARN Warning: // Check default bucket replacement configContent := json.MustEncodeString(recipe.Object.(*model.Config).Content, false) - assert.Equal(t, `{"parameters":{},"storage":{"input":{"tables":[{"columns":[],"source":"in.c-keboola-ex-aws-s3-123.accounts","destination":"accounts","where_column":"","where_operator":"eq","where_values":[]},{"columns":[],"source":"{{:default-bucket:extractor/keboola.ex-aws-s3/test2}}.contacts","destination":"contacts","where_column":"","where_operator":"eq","where_values":[]}],"files":[]},"output":{"tables":[],"files":[]}}}`, configContent) + assert.JSONEq(t, `{"parameters":{},"storage":{"input":{"tables":[{"columns":[],"source":"in.c-keboola-ex-aws-s3-123.accounts","destination":"accounts","where_column":"","where_operator":"eq","where_values":[]},{"columns":[],"source":"{{:default-bucket:extractor/keboola.ex-aws-s3/test2}}.contacts","destination":"contacts","where_column":"","where_operator":"eq","where_values":[]}],"files":[]},"output":{"tables":[],"files":[]}}}`, configContent) } func TestDefaultBucketMapper_MapBeforeLocalLoadRow(t *testing.T) { @@ -227,5 +227,5 @@ WARN Warning: // Check default bucket replacement configContent := json.MustEncodeString(recipe.Object.(*model.ConfigRow).Content, false) - assert.Equal(t, `{"parameters":{},"storage":{"input":{"tables":[{"columns":[],"source":"in.c-keboola-ex-aws-s3-123.accounts","destination":"accounts","where_column":"","where_operator":"eq","where_values":[]},{"columns":[],"source":"{{:default-bucket:extractor/keboola.ex-aws-s3/test2}}.contacts","destination":"contacts","where_column":"","where_operator":"eq","where_values":[]}],"files":[]},"output":{"tables":[],"files":[]}}}`, configContent) + assert.JSONEq(t, `{"parameters":{},"storage":{"input":{"tables":[{"columns":[],"source":"in.c-keboola-ex-aws-s3-123.accounts","destination":"accounts","where_column":"","where_operator":"eq","where_values":[]},{"columns":[],"source":"{{:default-bucket:extractor/keboola.ex-aws-s3/test2}}.contacts","destination":"contacts","where_column":"","where_operator":"eq","where_values":[]}],"files":[]},"output":{"tables":[],"files":[]}}}`, configContent) } diff --git a/internal/pkg/mapper/defaultbucket/local_save_test.go b/internal/pkg/mapper/defaultbucket/local_save_test.go index 6ec5ddb8f5..250576e8cc 100644 --- a/internal/pkg/mapper/defaultbucket/local_save_test.go +++ b/internal/pkg/mapper/defaultbucket/local_save_test.go @@ -113,7 +113,7 @@ WARN Warning: config "branch:123/component:keboola.ex-aws-s3/config:456" not fo // Check default bucket replacement configContent := json.MustEncodeString(object.Content, false) - assert.Equal(t, `{"parameters":{},"storage":{"input":{"tables":[{"columns":[],"source":"{{:default-bucket:extractor/keboola.ex-aws-s3/test}}.accounts","destination":"accounts","where_column":"","where_operator":"eq","where_values":[]},{"columns":[],"source":"in.c-keboola-ex-aws-s3-456.contacts","destination":"contacts","where_column":"","where_operator":"eq","where_values":[]}],"files":[]},"output":{"tables":[],"files":[]}}}`, configContent) + assert.JSONEq(t, `{"parameters":{},"storage":{"input":{"tables":[{"columns":[],"source":"{{:default-bucket:extractor/keboola.ex-aws-s3/test}}.accounts","destination":"accounts","where_column":"","where_operator":"eq","where_values":[]},{"columns":[],"source":"in.c-keboola-ex-aws-s3-456.contacts","destination":"contacts","where_column":"","where_operator":"eq","where_values":[]}],"files":[]},"output":{"tables":[],"files":[]}}}`, configContent) } func TestDefaultBucketMapper_MapBeforeLocalSaveRow(t *testing.T) { @@ -207,5 +207,5 @@ WARN Warning: config "branch:123/component:keboola.ex-aws-s3/config:456" not fo // Check default bucket replacement configContent := json.MustEncodeString(object.Content, false) - assert.Equal(t, `{"parameters":{},"storage":{"input":{"tables":[{"columns":[],"source":"{{:default-bucket:extractor/keboola.ex-aws-s3/test}}.accounts","destination":"accounts","where_column":"","where_operator":"eq","where_values":[]},{"columns":[],"source":"in.c-keboola-ex-aws-s3-456.contacts","destination":"contacts","where_column":"","where_operator":"eq","where_values":[]}],"files":[]},"output":{"tables":[],"files":[]}}}`, configContent) + assert.JSONEq(t, `{"parameters":{},"storage":{"input":{"tables":[{"columns":[],"source":"{{:default-bucket:extractor/keboola.ex-aws-s3/test}}.accounts","destination":"accounts","where_column":"","where_operator":"eq","where_values":[]},{"columns":[],"source":"in.c-keboola-ex-aws-s3-456.contacts","destination":"contacts","where_column":"","where_operator":"eq","where_values":[]}],"files":[]},"output":{"tables":[],"files":[]}}}`, configContent) } diff --git a/internal/pkg/mapper/scheduler/remote_activate_test.go b/internal/pkg/mapper/scheduler/remote_activate_test.go index a24fe5df20..a4685044ac 100644 --- a/internal/pkg/mapper/scheduler/remote_activate_test.go +++ b/internal/pkg/mapper/scheduler/remote_activate_test.go @@ -83,5 +83,5 @@ func TestSchedulerMapperRemoteActivate(t *testing.T) { reqBody, err := io.ReadAll(httpRequest.Body) require.NoError(t, err) require.NoError(t, err) - assert.Equal(t, `{"configurationId":"456"}`, string(reqBody)) + assert.JSONEq(t, `{"configurationId":"456"}`, string(reqBody)) } diff --git a/internal/pkg/mapper/transformation/local_save_test.go b/internal/pkg/mapper/transformation/local_save_test.go index 8cb2f125b0..355a0b0052 100644 --- a/internal/pkg/mapper/transformation/local_save_test.go +++ b/internal/pkg/mapper/transformation/local_save_test.go @@ -35,7 +35,7 @@ func TestLocalSaveTransformationEmpty(t *testing.T) { err := state.Mapper().MapBeforeLocalSave(context.Background(), recipe) require.NoError(t, err) require.NoError(t, err) - assert.Equal(t, `{"foo":"bar"}`, json.MustEncodeString(object.Content, false)) + assert.JSONEq(t, `{"foo":"bar"}`, json.MustEncodeString(object.Content, false)) } func TestTransformationMapper_MapBeforeLocalSave(t *testing.T) { diff --git a/internal/pkg/mapper/transformation/remote_load_test.go b/internal/pkg/mapper/transformation/remote_load_test.go index d4a113f7e6..ad85d4d099 100644 --- a/internal/pkg/mapper/transformation/remote_load_test.go +++ b/internal/pkg/mapper/transformation/remote_load_test.go @@ -158,6 +158,6 @@ func TestLoadRemoteTransformation(t *testing.T) { } // In internal object are blocks in Blocks field, not in Content - assert.Equal(t, `{"parameters":{}}`, json.MustEncodeString(object.Content, false)) + assert.JSONEq(t, `{"parameters":{}}`, json.MustEncodeString(object.Content, false)) assert.Equal(t, expected, object.Transformation.Blocks) } diff --git a/internal/pkg/model/mapper_test.go b/internal/pkg/model/mapper_test.go index 30d10a3148..a652977a1a 100644 --- a/internal/pkg/model/mapper_test.go +++ b/internal/pkg/model/mapper_test.go @@ -105,7 +105,7 @@ func TestFilesLoader(t *testing.T) { require.NoError(t, err) assert.Equal(t, `foo1.json`, rawFile1.Path()) assert.Equal(t, `my description`, rawFile1.Description()) - assert.Equal(t, jsonContent, rawFile1.Content) + assert.JSONEq(t, jsonContent, rawFile1.Content) // ReadJSONFile jsonFile1, err := files. @@ -146,7 +146,7 @@ func TestFilesLoader(t *testing.T) { require.NoError(t, err) assert.Equal(t, `foo4.json`, rawFile2.Path()) assert.Equal(t, `my description`, rawFile2.Description()) - assert.Equal(t, jsonContent, target2.Content) + assert.JSONEq(t, jsonContent, target2.Content) // ReadJSONMapTo target3 := &myStruct{} diff --git a/internal/pkg/service/appsproxy/proxy/server_test.go b/internal/pkg/service/appsproxy/proxy/server_test.go index 9487b8dda4..8766649c6a 100644 --- a/internal/pkg/service/appsproxy/proxy/server_test.go +++ b/internal/pkg/service/appsproxy/proxy/server_test.go @@ -639,5 +639,5 @@ func TestAppProxyHandler(t *testing.T) { } ] ` - assert.Equal(t, strings.TrimSpace(expectedMetricsJSON), strings.TrimSpace(actualMetricsJSON)) + assert.Equal(t, strings.TrimSpace(expectedMetricsJSON), strings.TrimSpace(actualMetricsJSON)) //nolint: testifylint } diff --git a/internal/pkg/service/appsproxy/proxy/testutil/app.go b/internal/pkg/service/appsproxy/proxy/testutil/app.go index 0a4dec46f3..c4cf284871 100644 --- a/internal/pkg/service/appsproxy/proxy/testutil/app.go +++ b/internal/pkg/service/appsproxy/proxy/testutil/app.go @@ -44,7 +44,7 @@ func StartAppServer(t *testing.T) *AppServer { c, err := websocket.Accept(w, r, nil) require.NoError(t, err) - ctx, cancel := context.WithTimeout(r.Context(), time.Second*10) + ctx, cancel := context.WithTimeout(r.Context(), time.Second*15) defer cancel() ticker := time.NewTicker(5 * time.Second) diff --git a/internal/pkg/service/common/configmap/dump_test.go b/internal/pkg/service/common/configmap/dump_test.go index 6bb1cf946c..8845476707 100644 --- a/internal/pkg/service/common/configmap/dump_test.go +++ b/internal/pkg/service/common/configmap/dump_test.go @@ -15,7 +15,7 @@ func TestDumpFlat_Empty(t *testing.T) { t.Parallel() bytes, err := NewDumper().Dump(TestConfig{}).Flat().AsJSON(true) require.NoError(t, err) - assert.Equal(t, strings.TrimSpace(` + assert.JSONEq(t, strings.TrimSpace(` { "address": "", "addressNullable": null, @@ -41,7 +41,7 @@ func TestDumpFlat(t *testing.T) { t.Parallel() bytes, err := NewDumper().Dump(dumpTestConfig()).Flat().AsJSON(true) require.NoError(t, err) - assert.Equal(t, strings.TrimSpace(` + assert.JSONEq(t, strings.TrimSpace(` { "address": "1.2.3.4", "addressNullable": null, @@ -73,7 +73,7 @@ func TestDumpAsJSON(t *testing.T) { t.Parallel() bytes, err := NewDumper().Dump(dumpTestConfig()).AsJSON(true) require.NoError(t, err) - assert.Equal(t, strings.TrimSpace(` + assert.JSONEq(t, strings.TrimSpace(` { "embedded": "embedded Value", "customString": "custom", diff --git a/internal/pkg/service/common/duration/duration_test.go b/internal/pkg/service/common/duration/duration_test.go index bd6fdfe652..11e44c2c36 100644 --- a/internal/pkg/service/common/duration/duration_test.go +++ b/internal/pkg/service/common/duration/duration_test.go @@ -21,7 +21,7 @@ func TestDuration_MarshalText_JSON(t *testing.T) { data := Data{Duration: duration.From(123 * time.Hour)} jsonOut, err := json.Marshal(data) require.NoError(t, err) - assert.Equal(t, `{"duration":"123h0m0s"}`, string(jsonOut)) + assert.JSONEq(t, `{"duration":"123h0m0s"}`, string(jsonOut)) } func TestDuration_MarshalText_YAML(t *testing.T) { @@ -29,7 +29,7 @@ func TestDuration_MarshalText_YAML(t *testing.T) { data := Data{Duration: duration.From(123 * time.Hour)} yamlOut, err := yaml.Marshal(data) require.NoError(t, err) - assert.Equal(t, "duration: 123h0m0s\n", string(yamlOut)) + assert.YAMLEq(t, "duration: 123h0m0s\n", string(yamlOut)) } func TestDuration_UnmarshalText_JSON(t *testing.T) { diff --git a/internal/pkg/service/common/errors/exceptionid.go b/internal/pkg/service/common/errors/exceptionid.go index d8a321851b..b2f1534469 100644 --- a/internal/pkg/service/common/errors/exceptionid.go +++ b/internal/pkg/service/common/errors/exceptionid.go @@ -1,8 +1,11 @@ package errors -import "github.com/keboola/keboola-as-code/internal/pkg/idgenerator" +import ( + "github.com/keboola/keboola-as-code/internal/pkg/idgenerator" + "github.com/keboola/keboola-as-code/internal/pkg/utils/errors" +) -type ErrorWithExceptionID struct { +type WithExceptionIDError struct { error exceptionID string } @@ -13,7 +16,8 @@ func GenerateExceptionID() string { func WrapWithExceptionID(exceptionID string, err error) error { // Skip, if there is already an exceptionID - if _, ok := err.(WithExceptionID); ok { + var withExceptionID WithExceptionIDError + if errors.As(err, &withExceptionID) { return err } @@ -22,13 +26,13 @@ func WrapWithExceptionID(exceptionID string, err error) error { exceptionID = GenerateExceptionID() } - return ErrorWithExceptionID{error: err, exceptionID: exceptionID} + return WithExceptionIDError{error: err, exceptionID: exceptionID} } -func (e ErrorWithExceptionID) Unwrap() error { +func (e WithExceptionIDError) Unwrap() error { return e.error } -func (e ErrorWithExceptionID) ErrorExceptionID() string { +func (e WithExceptionIDError) ExceptionID() string { return e.exceptionID } diff --git a/internal/pkg/service/common/errors/multiple.go b/internal/pkg/service/common/errors/multiple.go index fc65cb4f48..4ae48059e6 100644 --- a/internal/pkg/service/common/errors/multiple.go +++ b/internal/pkg/service/common/errors/multiple.go @@ -4,7 +4,7 @@ import ( "github.com/keboola/keboola-as-code/internal/pkg/utils/errors" ) -type multipleErrors struct { +type multipleErrors struct { // nolint:errname error httpCode int } diff --git a/internal/pkg/service/common/errors/statuscode.go b/internal/pkg/service/common/errors/statuscode.go index 8ce5e2a82f..51e6bd1a2b 100644 --- a/internal/pkg/service/common/errors/statuscode.go +++ b/internal/pkg/service/common/errors/statuscode.go @@ -13,7 +13,7 @@ const ( StatusClientClosedRequest = 499 ) -type withStatusCode struct { +type withStatusCodeError struct { error httpCode int } @@ -47,13 +47,13 @@ func HTTPCodeFrom(err error) int { } func WrapWithStatusCode(err error, httpCode int) WithStatusCode { - return withStatusCode{error: err, httpCode: httpCode} + return withStatusCodeError{error: err, httpCode: httpCode} } -func (w withStatusCode) StatusCode() int { +func (w withStatusCodeError) StatusCode() int { return w.httpCode } -func (w withStatusCode) Unwrap() error { +func (w withStatusCodeError) Unwrap() error { return w.error } diff --git a/internal/pkg/service/stream/config/config_test.go b/internal/pkg/service/stream/config/config_test.go index d864e03d5b..39a5751c5d 100644 --- a/internal/pkg/service/stream/config/config_test.go +++ b/internal/pkg/service/stream/config/config_test.go @@ -333,7 +333,7 @@ func TestTableSinkConfigPatch_ToKVs(t *testing.T) { ) require.NoError(t, err) - assert.Equal(t, strings.TrimSpace(` + assert.JSONEq(t, strings.TrimSpace(` [ { "key": "storage.level.local.encoding.compression.gzip.blockSize", diff --git a/internal/pkg/service/stream/mapping/table/column/column_test.go b/internal/pkg/service/stream/mapping/table/column/column_test.go index 92aaef6ab4..5c0614fc45 100644 --- a/internal/pkg/service/stream/mapping/table/column/column_test.go +++ b/internal/pkg/service/stream/mapping/table/column/column_test.go @@ -32,7 +32,7 @@ func TestMappedColumns_Serde(t *testing.T) { bytes, err := json.Marshal(&typed) require.NoError(t, err) - assert.Equal(t, expectedJSON, string(bytes)) + assert.JSONEq(t, expectedJSON, string(bytes)) var output column.Columns err = json.Unmarshal(bytes, &output) diff --git a/internal/pkg/service/stream/mapping/table/column/renderer_test.go b/internal/pkg/service/stream/mapping/table/column/renderer_test.go index d1fd9e861f..6b79b260a8 100644 --- a/internal/pkg/service/stream/mapping/table/column/renderer_test.go +++ b/internal/pkg/service/stream/mapping/table/column/renderer_test.go @@ -76,7 +76,9 @@ func TestRenderer_Headers(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header})) require.NoError(t, err) - assert.Equal(t, `{"Foo1":"bar1","Foo2":"bar2"}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"Foo1":"bar1","Foo2":"bar2"}`, value) } func TestRenderer_Path_Json_Scalar(t *testing.T) { @@ -140,7 +142,9 @@ func TestRenderer_Path_Json_Object(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `{"key2":"val2"}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"key2":"val2"}`, value) } func TestRenderer_Path_Json_ArrayOfObjects(t *testing.T) { @@ -156,7 +160,9 @@ func TestRenderer_Path_Json_ArrayOfObjects(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `[{"key2":"val2","key3":"val3"}]`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `[{"key2":"val2","key3":"val3"}]`, value) } func TestRenderer_Path_Json_ArrayIndex(t *testing.T) { @@ -172,7 +178,9 @@ func TestRenderer_Path_Json_ArrayIndex(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `"val3"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"val3"`, value) } func TestRenderer_Path_Json_ArrayIndex_RawString(t *testing.T) { @@ -203,7 +211,9 @@ func TestRenderer_Path_Json_Full(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `{"key1":[{"key2":"val2","key3":"val3"}]}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"key1":[{"key2":"val2","key3":"val3"}]}`, value) } func TestRenderer_Path_Json_UndefinedKey_Error(t *testing.T) { @@ -252,7 +262,9 @@ func TestRenderer_Path_Json_UndefinedKey_DefaultValue(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `"123"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"123"`, value) } func TestRenderer_Path_Json_UndefinedIndex_DefaultValue(t *testing.T) { @@ -269,7 +281,9 @@ func TestRenderer_Path_Json_UndefinedIndex_DefaultValue(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `"123"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"123"`, value) } func TestRenderer_Path_Json_UndefinedKey_DefaultValue_RawString(t *testing.T) { @@ -317,7 +331,9 @@ func TestRenderer_Path_FormData_Full(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `{"key1":"bar1","key2":["bar2","bar3"]}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"key1":"bar1","key2":["bar2","bar3"]}`, value) } func TestRenderer_Path_FormData_Scalar(t *testing.T) { @@ -333,7 +349,9 @@ func TestRenderer_Path_FormData_Scalar(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `"bar1"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"bar1"`, value) } func TestRenderer_Path_FormData_RawString(t *testing.T) { @@ -350,7 +368,9 @@ func TestRenderer_Path_FormData_RawString(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `42`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `42`, value) } func TestRenderer_Path_FormData_Object(t *testing.T) { @@ -366,7 +386,9 @@ func TestRenderer_Path_FormData_Object(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `{"x":"bar2","y":"bar3"}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"x":"bar2","y":"bar3"}`, value) } func TestRenderer_Path_FormData_ArrayOfObjects(t *testing.T) { @@ -382,7 +404,9 @@ func TestRenderer_Path_FormData_ArrayOfObjects(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `[{"x":"bar2"},{"x":"bar3"}]`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `[{"x":"bar2"},{"x":"bar3"}]`, value) } func TestRenderer_Path_FormData_ArrayIndex(t *testing.T) { @@ -398,7 +422,9 @@ func TestRenderer_Path_FormData_ArrayIndex(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `{"x":"bar3"}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"x":"bar3"}`, value) } func TestRenderer_Path_FormData_UndefinedKey_Error(t *testing.T) { @@ -447,7 +473,9 @@ func TestRenderer_Path_FormData_UndefinedKey_DefaultValue(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `"123"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"123"`, value) } func TestRenderer_Path_FormData_UndefinedKey_DefaultValue_RawString(t *testing.T) { @@ -465,7 +493,9 @@ func TestRenderer_Path_FormData_UndefinedKey_DefaultValue_RawString(t *testing.T val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `123`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `123`, value) } func TestRenderer_Template_Json_Scalar(t *testing.T) { @@ -482,7 +512,9 @@ func TestRenderer_Template_Json_Scalar(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `"val2"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"val2"`, value) } func TestRenderer_Template_Json_Object(t *testing.T) { @@ -499,7 +531,9 @@ func TestRenderer_Template_Json_Object(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `{"key2":"val2"}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"key2":"val2"}`, value) } func TestRenderer_Template_Json_ArrayOfObjects(t *testing.T) { @@ -516,7 +550,9 @@ func TestRenderer_Template_Json_ArrayOfObjects(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `[{"key2":"val2","key3":"val3"}]`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `[{"key2":"val2","key3":"val3"}]`, value) } func TestRenderer_Template_Json_ArrayIndex(t *testing.T) { @@ -533,7 +569,9 @@ func TestRenderer_Template_Json_ArrayIndex(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `"val3"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"val3"`, value) } func TestRenderer_Template_Json_ArrayIndex_RawString(t *testing.T) { @@ -553,7 +591,9 @@ func TestRenderer_Template_Json_ArrayIndex_RawString(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, "val3", val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, "val3", value) } func TestRenderer_Template_Json_Full(t *testing.T) { @@ -570,7 +610,9 @@ func TestRenderer_Template_Json_Full(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `{"key1":[{"key2":"val2","key3":"val3"}]}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"key1":[{"key2":"val2","key3":"val3"}]}`, value) } func TestRenderer_Template_Json_UndefinedKey_Error(t *testing.T) { @@ -604,7 +646,9 @@ func TestRenderer_Template_Json_UndefinedKey_DefaultValue(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, "123", val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, "123", value) } func TestRenderer_Template_Json_Invalid(t *testing.T) { @@ -637,7 +681,9 @@ func TestRenderer_Template_FormData_Full(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header, Body: io.NopCloser(strings.NewReader(body))})) require.NoError(t, err) - assert.Equal(t, `{"key1":"bar1","key2":["bar2","bar3"]}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"key1":"bar1","key2":["bar2","bar3"]}`, value) } func TestRenderer_Template_Headers(t *testing.T) { @@ -653,7 +699,9 @@ func TestRenderer_Template_Headers(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header})) require.NoError(t, err) - assert.Equal(t, `"gzip"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"gzip"`, value) } func TestRenderer_Template_Headers_Case(t *testing.T) { @@ -669,7 +717,9 @@ func TestRenderer_Template_Headers_Case(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header})) require.NoError(t, err) - assert.Equal(t, `"gzip"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"gzip"`, value) } func TestRenderer_Template_Headers_All(t *testing.T) { @@ -685,7 +735,9 @@ func TestRenderer_Template_Headers_All(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header})) require.NoError(t, err) - assert.Equal(t, `{"Content-Encoding":"gzip","Content-Type":"application/json"}`, val) + value, ok := val.(string) + require.True(t, ok) + assert.JSONEq(t, `{"Content-Encoding":"gzip","Content-Type":"application/json"}`, value) } func TestRenderer_Template_Headers_UndefinedKey_Error(t *testing.T) { @@ -716,7 +768,9 @@ func TestRenderer_Template_Headers_UndefinedKey_DefaultValue(t *testing.T) { val, err := renderer.CSVValue(c, recordctx.FromHTTP(time.Now(), &http.Request{Header: header})) require.NoError(t, err) - assert.Equal(t, `"abc"`, val) + value, ok := val.(string) + require.True(t, ok) + assert.Equal(t, `"abc"`, value) } func TestRenderer_Template_InvalidLanguage(t *testing.T) { diff --git a/internal/pkg/state/load_local_test.go b/internal/pkg/state/load_local_test.go index 6a93d20fd9..2d0282d769 100644 --- a/internal/pkg/state/load_local_test.go +++ b/internal/pkg/state/load_local_test.go @@ -28,7 +28,7 @@ func TestLoadLocalStateMinimal(t *testing.T) { m, fs := loadManifest(t, "minimal") _, state, localErr := loadLocalTestState(t, m, fs) assert.NotNil(t, state) - assert.Empty(t, localErr) + require.NoError(t, localErr) assert.Len(t, state.Branches(), 1) assert.Len(t, state.Configs(), 1) assert.Empty(t, state.UntrackedPaths()) @@ -52,7 +52,7 @@ func TestLoadLocalStateComplex(t *testing.T) { m, fs := loadManifest(t, "complex") _, state, localErr := loadLocalTestState(t, m, fs) assert.NotNil(t, state) - assert.Empty(t, localErr) + require.NoError(t, localErr) assert.Equal(t, complexLocalExpectedBranches(), reflecthelper.SortByName(state.Branches())) assert.Equal(t, complexLocalExpectedConfigs(), reflecthelper.SortByName(state.Configs())) assert.Equal(t, complexLocalExpectedConfigRows(), reflecthelper.SortByName(state.ConfigRows())) @@ -109,7 +109,7 @@ func TestLoadLocalStateAllowedBranches(t *testing.T) { m.SetAllowedBranches(model.AllowedBranches{"main"}) _, state, localErr := loadLocalTestState(t, m, fs) assert.NotNil(t, state) - assert.Empty(t, localErr) + require.NoError(t, localErr) } func TestLoadLocalStateAllowedBranchesWarning(t *testing.T) { diff --git a/internal/pkg/state/load_remote_test.go b/internal/pkg/state/load_remote_test.go index 60974a2c3a..467b317dc1 100644 --- a/internal/pkg/state/load_remote_test.go +++ b/internal/pkg/state/load_remote_test.go @@ -26,7 +26,7 @@ func TestLoadRemoteStateEmpty(t *testing.T) { m := createManifest(t) state, _, remoteErr := loadRemoteState(t, m, "empty.json") assert.NotNil(t, state) - assert.Empty(t, remoteErr) + require.NoError(t, remoteErr) assert.Len(t, state.Branches(), 1) assert.Empty(t, state.Configs()) } @@ -36,7 +36,7 @@ func TestLoadRemoteStateComplex(t *testing.T) { m := createManifest(t) state, envs, remoteErr := loadRemoteState(t, m, "complex.json") assert.NotNil(t, state) - assert.Empty(t, remoteErr) + require.NoError(t, remoteErr) assert.Equal(t, complexRemoteExpectedBranches(envs), state.Branches()) assert.Equal(t, complexRemoteExpectedConfigs(envs), state.Configs()) assert.Equal(t, complexRemoteExpectedConfigsRows(envs), state.ConfigRows()) @@ -48,7 +48,7 @@ func TestLoadRemoteStateAllowedBranches(t *testing.T) { m.SetAllowedBranches(model.AllowedBranches{"f??"}) // foo state, envs, remoteErr := loadRemoteState(t, m, "complex.json") assert.NotNil(t, state) - assert.Empty(t, remoteErr) + require.NoError(t, remoteErr) // Only Foo branch is loaded, other are "invisible" assert.Equal(t, []*model.BranchState{ { diff --git a/internal/pkg/state/local/manager_test.go b/internal/pkg/state/local/manager_test.go index 10495a1847..56ea64e91e 100644 --- a/internal/pkg/state/local/manager_test.go +++ b/internal/pkg/state/local/manager_test.go @@ -105,7 +105,7 @@ func TestLocalSaveMapper(t *testing.T) { // File content has been mapped configFile, err := fs.ReadFile(context.Background(), filesystem.NewFileDef(filesystem.Join(`branch`, `config`, naming.ConfigFile)).SetDescription(`config file`)) require.NoError(t, err) - assert.Equal(t, "{\n \"key\": \"overwritten\",\n \"new\": \"value\"\n}", strings.TrimSpace(configFile.Content)) + assert.JSONEq(t, `{"key": "overwritten","new": "value"}`, strings.TrimSpace(configFile.Content)) // AfterLocalOperation event has been called assert.Equal(t, []string{ @@ -147,7 +147,7 @@ func TestLocalLoadMapper(t *testing.T) { // Internal state has been mapped configState := projectState.MustGet(model.ConfigKey{BranchID: 111, ComponentID: `ex-generic-v2`, ID: `456`}).(*model.ConfigState) - assert.Equal(t, `{"parameters":"overwritten","new":"value"}`, json.MustEncodeString(configState.Local.Content, false)) + assert.JSONEq(t, `{"parameters":"overwritten","new":"value"}`, json.MustEncodeString(configState.Local.Content, false)) // AfterLocalOperation event has been called assert.Equal(t, []string{ diff --git a/internal/pkg/state/remote/manager_test.go b/internal/pkg/state/remote/manager_test.go index 3900445f6c..ac6ed9215d 100644 --- a/internal/pkg/state/remote/manager_test.go +++ b/internal/pkg/state/remote/manager_test.go @@ -116,7 +116,7 @@ func TestRemoteSaveMapper(t *testing.T) { // But the internal state is unchanged assert.Equal(t, `internal name`, configState.Local.Name) - assert.Equal(t, `{"key":"internal value"}`, json.MustEncodeString(configState.Local.Content, false)) + assert.JSONEq(t, `{"key":"internal value"}`, json.MustEncodeString(configState.Local.Content, false)) // AfterRemoteOperation event has been called assert.Equal(t, []string{ @@ -199,7 +199,7 @@ func TestRemoteLoadMapper(t *testing.T) { // API response has been mapped assert.Equal(t, `internal name`, config.Name) - assert.Equal(t, `{"key":"internal value","new":"value"}`, json.MustEncodeString(config.Content, false)) + assert.JSONEq(t, `{"key":"internal value","new":"value"}`, json.MustEncodeString(config.Content, false)) // AfterRemoteOperation event has been called assert.Equal(t, []string{ @@ -361,7 +361,7 @@ func TestSaveConfigMetadata_Create(t *testing.T) { require.NoError(t, err) reqBody, err := url.QueryUnescape(string(reqBodyRaw)) require.NoError(t, err) - assert.Equal(t, `{"metadata":[{"key":"KBC-KaC-meta1","value":"val1"}]}`, reqBody) + assert.JSONEq(t, `{"metadata":[{"key":"KBC-KaC-meta1","value":"val1"}]}`, reqBody) } func TestSaveConfigMetadata_Create_Empty(t *testing.T) { @@ -433,7 +433,7 @@ func TestSaveConfigMetadata_Update(t *testing.T) { require.NoError(t, err) reqBody, err := url.QueryUnescape(string(reqBodyRaw)) require.NoError(t, err) - assert.Equal(t, `{"metadata":[{"key":"KBC-KaC-meta1","value":"val1"}]}`, reqBody) + assert.JSONEq(t, `{"metadata":[{"key":"KBC-KaC-meta1","value":"val1"}]}`, reqBody) } func TestSaveConfigMetadata_Update_NoChange(t *testing.T) { diff --git a/internal/pkg/template/context/upgrade/context_test.go b/internal/pkg/template/context/upgrade/context_test.go index 0261b396c2..70483bda91 100644 --- a/internal/pkg/template/context/upgrade/context_test.go +++ b/internal/pkg/template/context/upgrade/context_test.go @@ -138,7 +138,7 @@ func TestContext(t *testing.T) { ` jsonOutput, err := jsonnet.Evaluate(code, tmplContext.JsonnetContext()) require.NoError(t, err) - assert.Equal(t, strings.TrimLeft(expectedJSON, "\n"), jsonOutput) + assert.JSONEq(t, strings.TrimLeft(expectedJSON, "\n"), jsonOutput) // Check tickets replacement data := orderedmap.New() @@ -165,5 +165,5 @@ func TestContext(t *testing.T) { } } ` - assert.Equal(t, strings.TrimLeft(expectedJSON, "\n"), modifiedJSON) + assert.JSONEq(t, strings.TrimLeft(expectedJSON, "\n"), modifiedJSON) } diff --git a/internal/pkg/template/context/use/context_test.go b/internal/pkg/template/context/use/context_test.go index 6e73fe2b5c..c8ea2b52e0 100644 --- a/internal/pkg/template/context/use/context_test.go +++ b/internal/pkg/template/context/use/context_test.go @@ -130,7 +130,7 @@ func TestContext(t *testing.T) { ` jsonOutput, err := jsonnet.Evaluate(code, useCtx.JsonnetContext()) require.NoError(t, err) - assert.Equal(t, strings.TrimLeft(expectedJSON, "\n"), jsonOutput) + assert.JSONEq(t, strings.TrimLeft(expectedJSON, "\n"), jsonOutput) // Check tickets replacement data := orderedmap.New() @@ -156,7 +156,7 @@ func TestContext(t *testing.T) { } } ` - assert.Equal(t, strings.TrimLeft(expectedJSON, "\n"), modifiedJSON) + assert.JSONEq(t, strings.TrimLeft(expectedJSON, "\n"), modifiedJSON) // Check collected inputs usage assert.Equal(t, &metadata.InputsUsage{ diff --git a/internal/pkg/utils/etcdhelper/put_test.go b/internal/pkg/utils/etcdhelper/put_test.go index 684fbb7800..c5c1e5cbbf 100644 --- a/internal/pkg/utils/etcdhelper/put_test.go +++ b/internal/pkg/utils/etcdhelper/put_test.go @@ -72,5 +72,5 @@ key3/key4 res, err = client.Get(context.Background(), "key3/key4") require.NoError(t, err) assert.Len(t, res.Kvs, 1) - assert.Equal(t, "{\n \"foo1\": \"bar1\",\n \"foo2\": [\n \"bar2\",\n \"bar3\"\n ]\n}", string(res.Kvs[0].Value)) + assert.JSONEq(t, `{"foo1": "bar1","foo2": ["bar2","bar3"]}`, string(res.Kvs[0].Value)) } diff --git a/pkg/lib/operation/dbt/generate/sources/generate_test.go b/pkg/lib/operation/dbt/generate/sources/generate_test.go index 21e3339ed3..b8d4a588c8 100644 --- a/pkg/lib/operation/dbt/generate/sources/generate_test.go +++ b/pkg/lib/operation/dbt/generate/sources/generate_test.go @@ -103,7 +103,7 @@ func TestGenerateSourcesDefinition(t *testing.T) { yamlEnc, err := yaml.Marshal(&res) require.NoError(t, err) - assert.Equal(t, strings.TrimSpace(` + assert.YAMLEq(t, strings.TrimSpace(` version: 2 sources: - name: out.c-main @@ -229,7 +229,7 @@ func TestGenerateSourcesDefinition_LinkedBucket(t *testing.T) { yamlEnc, err := yaml.Marshal(&res) require.NoError(t, err) - assert.Equal(t, strings.TrimSpace(` + assert.YAMLEq(t, strings.TrimSpace(` version: 2 sources: - name: out.c-main diff --git a/scripts/tools.sh b/scripts/tools.sh index 20dfe057c2..4435578fbe 100755 --- a/scripts/tools.sh +++ b/scripts/tools.sh @@ -42,8 +42,8 @@ if ! command -v golangci-lint &> /dev/null then # Disabled due to issues with windows curl command not working # Related to https://github.com/keboola/keboola-as-code/pull/1818/commits/df23a4e2855557a01460593f7d6ba59b5dc8825c - # curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$GOBIN" v1.61.0 - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 + # curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$GOBIN" v1.62.2 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 fi # gci diff --git a/test/stream/bridge/keboola/keboola_test.go b/test/stream/bridge/keboola/keboola_test.go index 608cffe88f..731fcf9672 100644 --- a/test/stream/bridge/keboola/keboola_test.go +++ b/test/stream/bridge/keboola/keboola_test.go @@ -392,7 +392,7 @@ func (ts *testState) testSlicesUpload(t *testing.T, ctx context.Context, expecta require.NoError(t, rawReader.Close()) } for i := range expectations.records.count { - assert.True(t, strings.Contains(allSlicesContent, fmt.Sprintf(`,"foo%d"`, expectations.records.startID+i))) + assert.Contains(t, allSlicesContent, fmt.Sprintf(`,"foo%d"`, expectations.records.startID+i)) } } @@ -474,7 +474,7 @@ func (ts *testState) checkKeboolaTable(t *testing.T, ctx context.Context, start, tablePreviewStr := json.MustEncodeString(tablePreview, true) for i := range expectedCount { - assert.True(t, strings.Contains(tablePreviewStr, fmt.Sprintf("foo%d", start+i))) + assert.Contains(t, tablePreviewStr, fmt.Sprintf("foo%d", start+i)) } }