Skip to content

Commit

Permalink
fix: Update linter to 1.62.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Matovidlo committed Nov 28, 2024
1 parent 449bf95 commit ed63e34
Show file tree
Hide file tree
Showing 32 changed files with 153 additions and 95 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/encoding/json/schema/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ 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) {
t.Parallel()
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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/encoding/jsonnet/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ 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) {
t.Parallel()
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) {
t.Parallel()
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions internal/pkg/encoding/jsonnet/jsonnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -30,15 +30,15 @@ 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) {
t.Parallel()
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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/filesystem/aferofs/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/filesystem/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (

// nolint: gochecknoglobals
var (
SkipDir = fs.SkipDir
SkipDir = fs.SkipDir // nolint: errname
ErrNotExist = os.ErrNotExist
)

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/mapper/defaultbucket/local_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions internal/pkg/mapper/defaultbucket/local_save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion internal/pkg/mapper/scheduler/remote_activate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion internal/pkg/mapper/transformation/local_save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/mapper/transformation/remote_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions internal/pkg/model/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/service/appsproxy/proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions internal/pkg/service/common/configmap/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/service/common/duration/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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) {
t.Parallel()
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) {
Expand Down
16 changes: 10 additions & 6 deletions internal/pkg/service/common/errors/exceptionid.go
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
}

Expand All @@ -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
}
2 changes: 1 addition & 1 deletion internal/pkg/service/common/errors/multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/service/common/errors/statuscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
StatusClientClosedRequest = 499
)

type withStatusCode struct {
type withStatusCodeError struct {
error
httpCode int
}
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion internal/pkg/service/stream/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit ed63e34

Please sign in to comment.