From 732d17203179f0174df6a571bb31af75814b6b21 Mon Sep 17 00:00:00 2001 From: AdamHaffar Date: Tue, 12 Sep 2023 00:36:03 +0100 Subject: [PATCH 1/7] refactor test in ./processor to use is. instead of assert package --- .../procbuiltin/extractfield_test.go | 10 ++++-- pkg/processor/procbuiltin/filterfield_test.go | 10 ++++-- pkg/processor/procbuiltin/hoistfield_test.go | 10 ++++-- pkg/processor/procbuiltin/insertfield_test.go | 10 ++++-- pkg/processor/procbuiltin/maskfield_test.go | 10 ++++-- .../procbuiltin/replacefield_test.go | 10 ++++-- .../procbuiltin/timestampconverter_test.go | 10 ++++-- pkg/processor/procbuiltin/valuetokey_test.go | 6 ++-- pkg/processor/store_test.go | 36 +++++++++++-------- 9 files changed, 74 insertions(+), 38 deletions(-) diff --git a/pkg/processor/procbuiltin/extractfield_test.go b/pkg/processor/procbuiltin/extractfield_test.go index 19f587279..41c653534 100644 --- a/pkg/processor/procbuiltin/extractfield_test.go +++ b/pkg/processor/procbuiltin/extractfield_test.go @@ -19,10 +19,10 @@ import ( "reflect" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/record" "github.com/conduitio/conduit/pkg/record/schema/mock" + "github.com/matryer/is" ) func TestExtractFieldKey_Build(t *testing.T) { @@ -68,6 +68,8 @@ func TestExtractFieldKey_Build(t *testing.T) { } func TestExtractFieldKey_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -135,7 +137,7 @@ func TestExtractFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := ExtractFieldKey(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) @@ -191,6 +193,8 @@ func TestExtractFieldPayload_Build(t *testing.T) { } func TestExtractFieldPayload_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -273,7 +277,7 @@ func TestExtractFieldPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := ExtractFieldPayload(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) diff --git a/pkg/processor/procbuiltin/filterfield_test.go b/pkg/processor/procbuiltin/filterfield_test.go index 687337795..5e738d531 100644 --- a/pkg/processor/procbuiltin/filterfield_test.go +++ b/pkg/processor/procbuiltin/filterfield_test.go @@ -18,11 +18,11 @@ import ( "context" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/cerrors" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/record" "github.com/google/go-cmp/cmp" + "github.com/matryer/is" ) func TestFilterFieldKey_Build(t *testing.T) { @@ -101,6 +101,8 @@ func TestFilterFieldKey_Build(t *testing.T) { } func TestFilterFieldKey_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -231,7 +233,7 @@ func TestFilterFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := FilterFieldKey(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("FilterFieldKey() error = %v, wantErr %v", err, tt.wantErr) @@ -316,6 +318,8 @@ func TestFilterFieldPayload_Build(t *testing.T) { } func TestFilterFieldPayload_Process(t *testing.T) { + is := is.New(t) + type args struct { config processor.Config r record.Record @@ -421,7 +425,7 @@ func TestFilterFieldPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := FilterFieldPayload(tt.args.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != (tt.err != nil) { t.Errorf("FilterFieldPayload Error: %s - wanted: %s", err, tt.err) diff --git a/pkg/processor/procbuiltin/hoistfield_test.go b/pkg/processor/procbuiltin/hoistfield_test.go index 4c67221f7..7bc110b30 100644 --- a/pkg/processor/procbuiltin/hoistfield_test.go +++ b/pkg/processor/procbuiltin/hoistfield_test.go @@ -19,10 +19,10 @@ import ( "reflect" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/record" "github.com/conduitio/conduit/pkg/record/schema/mock" + "github.com/matryer/is" ) func TestHoistFieldKey_Build(t *testing.T) { @@ -69,6 +69,8 @@ func TestHoistFieldKey_Build(t *testing.T) { } func TestHoistFieldKey_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -132,7 +134,7 @@ func TestHoistFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := HoistFieldKey(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) @@ -189,6 +191,8 @@ func TestHoistFieldPayload_Build(t *testing.T) { } func TestHoistFieldPayload_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -267,7 +271,7 @@ func TestHoistFieldPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := HoistFieldPayload(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) diff --git a/pkg/processor/procbuiltin/insertfield_test.go b/pkg/processor/procbuiltin/insertfield_test.go index 71b7ea2ed..e5476bc2a 100644 --- a/pkg/processor/procbuiltin/insertfield_test.go +++ b/pkg/processor/procbuiltin/insertfield_test.go @@ -19,10 +19,10 @@ import ( "reflect" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/record" "github.com/conduitio/conduit/pkg/record/schema/mock" + "github.com/matryer/is" ) func TestInsertFieldKey_Build(t *testing.T) { @@ -82,6 +82,8 @@ func TestInsertFieldKey_Build(t *testing.T) { } func TestInsertFieldKey_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -244,7 +246,7 @@ func TestInsertFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := InsertFieldKey(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) @@ -312,6 +314,8 @@ func TestInsertFieldPayload_Build(t *testing.T) { } func TestInsertFieldPayload_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -503,7 +507,7 @@ func TestInsertFieldPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := InsertFieldPayload(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) diff --git a/pkg/processor/procbuiltin/maskfield_test.go b/pkg/processor/procbuiltin/maskfield_test.go index c47a111f8..3b80b23a6 100644 --- a/pkg/processor/procbuiltin/maskfield_test.go +++ b/pkg/processor/procbuiltin/maskfield_test.go @@ -18,11 +18,11 @@ import ( "context" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/record" "github.com/conduitio/conduit/pkg/record/schema/mock" "github.com/google/go-cmp/cmp" + "github.com/matryer/is" ) func TestMaskFieldKey_Build(t *testing.T) { @@ -68,6 +68,8 @@ func TestMaskFieldKey_Build(t *testing.T) { } func TestMaskFieldKey_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -160,7 +162,7 @@ func TestMaskFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := MaskFieldKey(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) @@ -216,6 +218,8 @@ func TestMaskFieldPayload_Build(t *testing.T) { } func TestMaskFieldPayload_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -332,7 +336,7 @@ func TestMaskFieldPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := MaskFieldPayload(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) diff --git a/pkg/processor/procbuiltin/replacefield_test.go b/pkg/processor/procbuiltin/replacefield_test.go index 278375f1d..41a7441fc 100644 --- a/pkg/processor/procbuiltin/replacefield_test.go +++ b/pkg/processor/procbuiltin/replacefield_test.go @@ -18,11 +18,11 @@ import ( "context" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/record" "github.com/conduitio/conduit/pkg/record/schema/mock" "github.com/google/go-cmp/cmp" + "github.com/matryer/is" ) func TestReplaceFieldKey_Build(t *testing.T) { @@ -108,6 +108,8 @@ func TestReplaceFieldKey_Build(t *testing.T) { } func TestReplaceFieldKey_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -292,7 +294,7 @@ func TestReplaceFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := ReplaceFieldKey(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) @@ -389,6 +391,8 @@ func TestReplaceFieldPayload_Build(t *testing.T) { } func TestReplaceFieldPayload_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -621,7 +625,7 @@ func TestReplaceFieldPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := ReplaceFieldPayload(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) diff --git a/pkg/processor/procbuiltin/timestampconverter_test.go b/pkg/processor/procbuiltin/timestampconverter_test.go index 4e30318f3..1e8d2b8b7 100644 --- a/pkg/processor/procbuiltin/timestampconverter_test.go +++ b/pkg/processor/procbuiltin/timestampconverter_test.go @@ -19,11 +19,11 @@ import ( "testing" "time" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/record" "github.com/conduitio/conduit/pkg/record/schema/mock" "github.com/google/go-cmp/cmp" + "github.com/matryer/is" ) func TestTimestampConverterKey_Build(t *testing.T) { @@ -101,6 +101,8 @@ func TestTimestampConverterKey_Build(t *testing.T) { } func TestTimestampConverterKey_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -298,7 +300,7 @@ func TestTimestampConverterKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := TimestampConverterKey(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) @@ -357,6 +359,8 @@ func TestTimestampConverterPayload_Build(t *testing.T) { } func TestTimestampConverterPayload_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -601,7 +605,7 @@ func TestTimestampConverterPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := TimestampConverterPayload(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) diff --git a/pkg/processor/procbuiltin/valuetokey_test.go b/pkg/processor/procbuiltin/valuetokey_test.go index 159428b6a..585fb2665 100644 --- a/pkg/processor/procbuiltin/valuetokey_test.go +++ b/pkg/processor/procbuiltin/valuetokey_test.go @@ -19,10 +19,10 @@ import ( "reflect" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/record" "github.com/conduitio/conduit/pkg/record/schema/mock" + "github.com/matryer/is" ) func TestValueToKey_Build(t *testing.T) { @@ -68,6 +68,8 @@ func TestValueToKey_Build(t *testing.T) { } func TestValueToKey_Process(t *testing.T) { + is := is.New(t) + type args struct { r record.Record } @@ -140,7 +142,7 @@ func TestValueToKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { underTest, err := ValueToKey(tt.config) - assert.Ok(t, err) + is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) if (err != nil) != tt.wantErr { t.Errorf("process() error = %v, wantErr = %v", err, tt.wantErr) diff --git a/pkg/processor/store_test.go b/pkg/processor/store_test.go index 1481286ef..61f4cf21d 100644 --- a/pkg/processor/store_test.go +++ b/pkg/processor/store_test.go @@ -18,17 +18,19 @@ import ( "context" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/cerrors" "github.com/conduitio/conduit/pkg/foundation/database" "github.com/conduitio/conduit/pkg/foundation/database/inmemory" "github.com/conduitio/conduit/pkg/processor" "github.com/conduitio/conduit/pkg/processor/mock" "github.com/google/uuid" + "github.com/matryer/is" "go.uber.org/mock/gomock" ) func TestConfigStore_SetGet(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} ctrl := gomock.NewController(t) @@ -54,20 +56,22 @@ func TestConfigStore_SetGet(t *testing.T) { var err error want.Processor, err = registry.MustGet(processorType)(want.Config) - assert.Ok(t, err) + is.NoErr(err) s := processor.NewStore(db, registry) err = s.Set(ctx, want.ID, want) - assert.Ok(t, err) - assert.NotNil(t, want.Processor) // make sure processor is left untouched + is.NoErr(err) + is.True(want.Processor != nil) // make sure processor is left untouched got, err := s.Get(ctx, want.ID) - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) } func TestConfigStore_GetAll(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} ctrl := gomock.NewController(t) @@ -100,19 +104,21 @@ func TestConfigStore_GetAll(t *testing.T) { } var err error instance.Processor, err = registry.MustGet(procType)(instance.Config) - assert.Ok(t, err) + is.NoErr(err) err = s.Set(ctx, instance.ID, instance) - assert.Ok(t, err) + is.NoErr(err) want[instance.ID] = instance } got, err := s.GetAll(ctx) - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) } func TestConfigStore_Delete(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} registry := processor.NewBuilderRegistry() @@ -125,13 +131,13 @@ func TestConfigStore_Delete(t *testing.T) { s := processor.NewStore(db, registry) err := s.Set(ctx, want.ID, want) - assert.Ok(t, err) + is.NoErr(err) err = s.Delete(ctx, want.ID) - assert.Ok(t, err) + is.NoErr(err) got, err := s.Get(ctx, want.ID) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, database.ErrKeyNotExist), "expected error for non-existing key") - assert.Nil(t, got) + is.True(err != nil) + is.True(cerrors.Is(err, database.ErrKeyNotExist)) // expected error for non-existing key + is.True(got == nil) } From 636b64104b8f3f198b95a5281291b6c65365d2e3 Mon Sep 17 00:00:00 2001 From: AdamHaffar Date: Fri, 15 Sep 2023 16:12:46 +0100 Subject: [PATCH 2/7] refactor test files in ./foundation to use matryer instead. Remove Assert pkg from ./foundation. Refactor is.New(t) to be initialised in each subtest --- pkg/foundation/cerrors/cerrors_test.go | 24 ++-- pkg/orchestrator/processors_test.go | 123 ++++++++++++------ .../procbuiltin/extractfield_test.go | 8 +- pkg/processor/procbuiltin/filterfield_test.go | 8 +- pkg/processor/procbuiltin/hoistfield_test.go | 8 +- pkg/processor/procbuiltin/insertfield_test.go | 8 +- pkg/processor/procbuiltin/maskfield_test.go | 8 +- pkg/processor/procbuiltin/parsejson_test.go | 2 + .../procbuiltin/replacefield_test.go | 8 +- .../procbuiltin/timestampconverter_test.go | 8 +- pkg/processor/procbuiltin/unwrap_test.go | 1 + pkg/processor/procbuiltin/valuetokey_test.go | 2 + pkg/provisioning/config/validate_test.go | 2 + pkg/web/api/status/status_test.go | 16 +-- 14 files changed, 137 insertions(+), 89 deletions(-) diff --git a/pkg/foundation/cerrors/cerrors_test.go b/pkg/foundation/cerrors/cerrors_test.go index 325958c1e..c9e18c304 100644 --- a/pkg/foundation/cerrors/cerrors_test.go +++ b/pkg/foundation/cerrors/cerrors_test.go @@ -19,7 +19,6 @@ import ( "runtime" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/cerrors" "github.com/matryer/is" ) @@ -45,22 +44,24 @@ func (w *unwrapPanicError) Unwrap() error { } func TestNew(t *testing.T) { + is := is.New(t) + err := newError() s := fmt.Sprintf("%+v", err) - assert.Equal( - t, + is.Equal( "foobar:\n github.com/conduitio/conduit/pkg/foundation/cerrors_test.newError\n "+helperFilePath+":26", s, ) } func TestErrorf(t *testing.T) { + is := is.New(t) + err := cerrors.Errorf("caused by: %w", newError()) s := fmt.Sprintf("%+v", err) - assert.Equal( - t, + is.Equal( "caused by:\n github.com/conduitio/conduit/pkg/foundation/cerrors_test.TestErrorf\n "+ - testFileLocation+":58\n - "+ + testFileLocation+":60\n - "+ "foobar:\n github.com/conduitio/conduit/pkg/foundation/cerrors_test.newError\n "+ helperFilePath+":26", s, @@ -90,7 +91,7 @@ func TestGetStackTrace(t *testing.T) { { Func: "github.com/conduitio/conduit/pkg/foundation/cerrors_test.TestGetStackTrace", File: testFileLocation, - Line: 88, + Line: 89, }, }, }, @@ -135,14 +136,17 @@ func TestGetStackTrace(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { + is := is.New(t) + res := cerrors.GetStackTrace(tc.err) if tc.expected == nil { - assert.Nil(t, res) + is.True(res == nil) return } act, ok := res.([]cerrors.Frame) - assert.True(t, ok, "expected []cerrors.Frame") - assert.Equal(t, tc.expected, act) + is.True(ok) // expected []cerrors.Frame + is.Equal(tc.expected, act) + }) } } diff --git a/pkg/orchestrator/processors_test.go b/pkg/orchestrator/processors_test.go index 716b0a1cd..ba20cdf6f 100644 --- a/pkg/orchestrator/processors_test.go +++ b/pkg/orchestrator/processors_test.go @@ -19,7 +19,6 @@ import ( "testing" "github.com/conduitio/conduit/pkg/connector" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/cerrors" "github.com/conduitio/conduit/pkg/foundation/database/inmemory" "github.com/conduitio/conduit/pkg/foundation/log" @@ -31,6 +30,8 @@ import ( ) func TestProcessorOrchestrator_CreateOnPipeline_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -70,11 +71,13 @@ func TestProcessorOrchestrator_CreateOnPipeline_Success(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Create(ctx, want.Type, want.Parent, want.Config) - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) } func TestProcessorOrchestrator_CreateOnPipeline_PipelineNotExist(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -90,12 +93,14 @@ func TestProcessorOrchestrator_CreateOnPipeline_PipelineNotExist(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Create(ctx, "test-processor", parent, processor.Config{}) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, wantErr), "errors did not match") - assert.Nil(t, got) + is.True(err != nil) + is.True(cerrors.Is(err, wantErr)) // errors did not match + is.True(got == nil) } func TestProcessorOrchestrator_CreateOnPipeline_PipelineRunning(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -114,13 +119,14 @@ func TestProcessorOrchestrator_CreateOnPipeline_PipelineRunning(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Create(ctx, "test-processor", parent, processor.Config{}) - assert.Error(t, err) - assert.Equal(t, pipeline.ErrPipelineRunning, err) - assert.Nil(t, got) + is.True(err != nil) + is.Equal(pipeline.ErrPipelineRunning, err) + is.True(got == nil) } func TestProcessorOrchestrator_CreateOnPipeline_PipelineProvisionedByConfig(t *testing.T) { is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -146,6 +152,8 @@ func TestProcessorOrchestrator_CreateOnPipeline_PipelineProvisionedByConfig(t *t } func TestProcessorOrchestrator_CreateOnPipeline_CreateProcessorError(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -176,12 +184,14 @@ func TestProcessorOrchestrator_CreateOnPipeline_CreateProcessorError(t *testing. orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Create(ctx, "test-processor", parent, processor.Config{}) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, wantErr), "errors did not match") - assert.Nil(t, got) + is.True(err != nil) + is.True(cerrors.Is(err, wantErr)) // errors did not match + is.True(got == nil) } func TestProcessorOrchestrator_CreateOnPipeline_AddProcessorError(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -226,12 +236,14 @@ func TestProcessorOrchestrator_CreateOnPipeline_AddProcessorError(t *testing.T) orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Create(ctx, proc.Type, proc.Parent, proc.Config) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, wantErr), "errors did not match") - assert.Nil(t, got) + is.True(err != nil) + is.True(cerrors.Is(err, wantErr)) // errors did not match + is.True(got == nil) } func TestProcessorOrchestrator_CreateOnConnector_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -278,11 +290,13 @@ func TestProcessorOrchestrator_CreateOnConnector_Success(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Create(ctx, want.Type, want.Parent, want.Config) - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) } func TestProcessorOrchestrator_CreateOnConnector_ConnectorNotExist(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -298,12 +312,14 @@ func TestProcessorOrchestrator_CreateOnConnector_ConnectorNotExist(t *testing.T) orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Create(ctx, "test-processor", parent, processor.Config{}) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, wantErr), "errors did not match") - assert.Nil(t, got) + is.True(err != nil) + is.True(cerrors.Is(err, wantErr)) // errors did not match + is.True(got == nil) } func TestProcessorOrchestrator_UpdateOnPipeline_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -350,11 +366,13 @@ func TestProcessorOrchestrator_UpdateOnPipeline_Success(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Update(ctx, before.ID, newConfig) - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) } func TestProcessorOrchestrator_UpdateOnPipeline_ProcessorNotExist(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -385,12 +403,14 @@ func TestProcessorOrchestrator_UpdateOnPipeline_ProcessorNotExist(t *testing.T) orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Update(ctx, before.ID, newConfig) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, wantErr), "errors did not match") - assert.Nil(t, got) + is.True(err != nil) + is.True(cerrors.Is(err, wantErr)) // errors did not match") + is.True(got == nil) } func TestProcessorOrchestrator_UpdateOnPipeline_PipelineRunning(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -423,13 +443,14 @@ func TestProcessorOrchestrator_UpdateOnPipeline_PipelineRunning(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Update(ctx, before.ID, newConfig) - assert.Error(t, err) - assert.Equal(t, pipeline.ErrPipelineRunning, err) - assert.Nil(t, got) + is.True(err != nil) + is.Equal(pipeline.ErrPipelineRunning, err) + is.True(got == nil) } func TestProcessorOrchestrator_UpdateOnPipeline_ProcessorProvisionedByConfig(t *testing.T) { is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -467,6 +488,8 @@ func TestProcessorOrchestrator_UpdateOnPipeline_ProcessorProvisionedByConfig(t * } func TestProcessorOrchestrator_UpdateOnPipeline_UpdateFail(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -514,12 +537,14 @@ func TestProcessorOrchestrator_UpdateOnPipeline_UpdateFail(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Update(ctx, before.ID, newConfig) - assert.Error(t, err) - assert.Equal(t, wantErr, err) - assert.Nil(t, got) + is.True(err != nil) + is.Equal(wantErr, err) + is.True(got == nil) } func TestProcessorOrchestrator_UpdateOnConnector_ConnectorNotExist(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -544,12 +569,14 @@ func TestProcessorOrchestrator_UpdateOnConnector_ConnectorNotExist(t *testing.T) orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) got, err := orc.Processors.Update(ctx, want.ID, processor.Config{}) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, wantErr), "errors did not match") - assert.Nil(t, got) + is.True(err != nil) + is.True(cerrors.Is(err, wantErr)) // errors did not match + is.True(got == nil) } func TestProcessorOrchestrator_DeleteOnPipeline_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -585,10 +612,12 @@ func TestProcessorOrchestrator_DeleteOnPipeline_Success(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) err := orc.Processors.Delete(ctx, want.ID) - assert.Ok(t, err) + is.NoErr(err) } func TestProcessorOrchestrator_DeleteOnPipeline_ProcessorNotExist(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -616,11 +645,13 @@ func TestProcessorOrchestrator_DeleteOnPipeline_ProcessorNotExist(t *testing.T) orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) err := orc.Processors.Delete(ctx, want.ID) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, wantErr), "errors did not match") + is.True(err != nil) + is.True(cerrors.Is(err, wantErr)) // errors did not match } func TestProcessorOrchestrator_DeleteOnPipeline_PipelineRunning(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -650,11 +681,13 @@ func TestProcessorOrchestrator_DeleteOnPipeline_PipelineRunning(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) err := orc.Processors.Delete(ctx, want.ID) - assert.Error(t, err) - assert.Equal(t, pipeline.ErrPipelineRunning, err) + is.True(err != nil) + is.Equal(pipeline.ErrPipelineRunning, err) } func TestProcessorOrchestrator_DeleteOnPipeline_Fail(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -688,11 +721,13 @@ func TestProcessorOrchestrator_DeleteOnPipeline_Fail(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) err := orc.Processors.Delete(ctx, want.ID) - assert.Error(t, err) - assert.True(t, cerrors.Is(err, wantErr), "errors did not match") + is.True(err != nil) + is.True(cerrors.Is(err, wantErr)) // errors did not match } func TestProcessorOrchestrator_DeleteOnPipeline_RemoveProcessorFail(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -740,10 +775,12 @@ func TestProcessorOrchestrator_DeleteOnPipeline_RemoveProcessorFail(t *testing.T orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) err := orc.Processors.Delete(ctx, want.ID) - assert.Error(t, err) + is.True(err != nil) } func TestProcessorOrchestrator_DeleteOnConnector_Fail(t *testing.T) { + is := is.New(t) + ctx := context.Background() db := &inmemory.DB{} plsMock, consMock, procsMock, pluginMock := newMockServices(t) @@ -798,5 +835,5 @@ func TestProcessorOrchestrator_DeleteOnConnector_Fail(t *testing.T) { orc := NewOrchestrator(db, log.Nop(), plsMock, consMock, procsMock, pluginMock) err := orc.Processors.Delete(ctx, want.ID) - assert.Error(t, err) + is.True(err != nil) } diff --git a/pkg/processor/procbuiltin/extractfield_test.go b/pkg/processor/procbuiltin/extractfield_test.go index 41c653534..3038bbdf3 100644 --- a/pkg/processor/procbuiltin/extractfield_test.go +++ b/pkg/processor/procbuiltin/extractfield_test.go @@ -68,8 +68,6 @@ func TestExtractFieldKey_Build(t *testing.T) { } func TestExtractFieldKey_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -136,6 +134,8 @@ func TestExtractFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := ExtractFieldKey(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) @@ -193,8 +193,6 @@ func TestExtractFieldPayload_Build(t *testing.T) { } func TestExtractFieldPayload_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -276,6 +274,8 @@ func TestExtractFieldPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := ExtractFieldPayload(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) diff --git a/pkg/processor/procbuiltin/filterfield_test.go b/pkg/processor/procbuiltin/filterfield_test.go index 5e738d531..0fb7abccc 100644 --- a/pkg/processor/procbuiltin/filterfield_test.go +++ b/pkg/processor/procbuiltin/filterfield_test.go @@ -101,8 +101,6 @@ func TestFilterFieldKey_Build(t *testing.T) { } func TestFilterFieldKey_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -232,6 +230,8 @@ func TestFilterFieldKey_Process(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := FilterFieldKey(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) @@ -318,8 +318,6 @@ func TestFilterFieldPayload_Build(t *testing.T) { } func TestFilterFieldPayload_Process(t *testing.T) { - is := is.New(t) - type args struct { config processor.Config r record.Record @@ -424,6 +422,8 @@ func TestFilterFieldPayload_Process(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := FilterFieldPayload(tt.args.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) diff --git a/pkg/processor/procbuiltin/hoistfield_test.go b/pkg/processor/procbuiltin/hoistfield_test.go index 7bc110b30..ecf5afd73 100644 --- a/pkg/processor/procbuiltin/hoistfield_test.go +++ b/pkg/processor/procbuiltin/hoistfield_test.go @@ -69,8 +69,6 @@ func TestHoistFieldKey_Build(t *testing.T) { } func TestHoistFieldKey_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -133,6 +131,8 @@ func TestHoistFieldKey_Process(t *testing.T) { }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := HoistFieldKey(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) @@ -191,8 +191,6 @@ func TestHoistFieldPayload_Build(t *testing.T) { } func TestHoistFieldPayload_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -270,6 +268,8 @@ func TestHoistFieldPayload_Process(t *testing.T) { }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := HoistFieldPayload(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) diff --git a/pkg/processor/procbuiltin/insertfield_test.go b/pkg/processor/procbuiltin/insertfield_test.go index e5476bc2a..054c02e0d 100644 --- a/pkg/processor/procbuiltin/insertfield_test.go +++ b/pkg/processor/procbuiltin/insertfield_test.go @@ -82,8 +82,6 @@ func TestInsertFieldKey_Build(t *testing.T) { } func TestInsertFieldKey_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -245,6 +243,8 @@ func TestInsertFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := InsertFieldKey(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) @@ -314,8 +314,6 @@ func TestInsertFieldPayload_Build(t *testing.T) { } func TestInsertFieldPayload_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -506,6 +504,8 @@ func TestInsertFieldPayload_Process(t *testing.T) { }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := InsertFieldPayload(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) diff --git a/pkg/processor/procbuiltin/maskfield_test.go b/pkg/processor/procbuiltin/maskfield_test.go index 3b80b23a6..a4043f3a6 100644 --- a/pkg/processor/procbuiltin/maskfield_test.go +++ b/pkg/processor/procbuiltin/maskfield_test.go @@ -68,8 +68,6 @@ func TestMaskFieldKey_Build(t *testing.T) { } func TestMaskFieldKey_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -161,6 +159,8 @@ func TestMaskFieldKey_Process(t *testing.T) { }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := MaskFieldKey(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) @@ -218,8 +218,6 @@ func TestMaskFieldPayload_Build(t *testing.T) { } func TestMaskFieldPayload_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -335,6 +333,8 @@ func TestMaskFieldPayload_Process(t *testing.T) { }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := MaskFieldPayload(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) diff --git a/pkg/processor/procbuiltin/parsejson_test.go b/pkg/processor/procbuiltin/parsejson_test.go index 664582288..0a938d514 100644 --- a/pkg/processor/procbuiltin/parsejson_test.go +++ b/pkg/processor/procbuiltin/parsejson_test.go @@ -72,6 +72,7 @@ func TestParseJSONKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { is := is.New(t) + underTest, err := ParseJSONKey(processor.Config{}) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.record) @@ -180,6 +181,7 @@ func TestParseJSONPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { is := is.New(t) + underTest, err := ParseJSONPayload(processor.Config{}) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.record) diff --git a/pkg/processor/procbuiltin/replacefield_test.go b/pkg/processor/procbuiltin/replacefield_test.go index 41a7441fc..2d7269ead 100644 --- a/pkg/processor/procbuiltin/replacefield_test.go +++ b/pkg/processor/procbuiltin/replacefield_test.go @@ -108,8 +108,6 @@ func TestReplaceFieldKey_Build(t *testing.T) { } func TestReplaceFieldKey_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -293,6 +291,8 @@ func TestReplaceFieldKey_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := ReplaceFieldKey(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) @@ -391,8 +391,6 @@ func TestReplaceFieldPayload_Build(t *testing.T) { } func TestReplaceFieldPayload_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -624,6 +622,8 @@ func TestReplaceFieldPayload_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := ReplaceFieldPayload(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) diff --git a/pkg/processor/procbuiltin/timestampconverter_test.go b/pkg/processor/procbuiltin/timestampconverter_test.go index 1e8d2b8b7..0bf3deeb4 100644 --- a/pkg/processor/procbuiltin/timestampconverter_test.go +++ b/pkg/processor/procbuiltin/timestampconverter_test.go @@ -101,8 +101,6 @@ func TestTimestampConverterKey_Build(t *testing.T) { } func TestTimestampConverterKey_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -299,6 +297,8 @@ func TestTimestampConverterKey_Process(t *testing.T) { }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := TimestampConverterKey(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) @@ -359,8 +359,6 @@ func TestTimestampConverterPayload_Build(t *testing.T) { } func TestTimestampConverterPayload_Process(t *testing.T) { - is := is.New(t) - type args struct { r record.Record } @@ -604,6 +602,8 @@ func TestTimestampConverterPayload_Process(t *testing.T) { }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := TimestampConverterPayload(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) diff --git a/pkg/processor/procbuiltin/unwrap_test.go b/pkg/processor/procbuiltin/unwrap_test.go index c70b81f18..513fe3180 100644 --- a/pkg/processor/procbuiltin/unwrap_test.go +++ b/pkg/processor/procbuiltin/unwrap_test.go @@ -406,6 +406,7 @@ func TestUnwrap_Process(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { is := is.New(t) + underTest, err := Unwrap(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.record) diff --git a/pkg/processor/procbuiltin/valuetokey_test.go b/pkg/processor/procbuiltin/valuetokey_test.go index 585fb2665..5921d2634 100644 --- a/pkg/processor/procbuiltin/valuetokey_test.go +++ b/pkg/processor/procbuiltin/valuetokey_test.go @@ -141,6 +141,8 @@ func TestValueToKey_Process(t *testing.T) { }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + underTest, err := ValueToKey(tt.config) is.NoErr(err) got, err := underTest.Process(context.Background(), tt.args.r) diff --git a/pkg/provisioning/config/validate_test.go b/pkg/provisioning/config/validate_test.go index 5cfcc94b6..16e308deb 100644 --- a/pkg/provisioning/config/validate_test.go +++ b/pkg/provisioning/config/validate_test.go @@ -94,6 +94,7 @@ func TestValidator_MandatoryFields(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { is := is.New(t) + err := Validate(tt.config) is.True(err != nil) is.True(cerrors.Is(err, ErrMandatoryField)) @@ -162,6 +163,7 @@ func TestValidator_InvalidFields(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { is := is.New(t) + err := Validate(tt.config) is.True(err != nil) is.True(cerrors.Is(err, ErrInvalidField)) diff --git a/pkg/web/api/status/status_test.go b/pkg/web/api/status/status_test.go index 6857a3253..9e1ce0631 100644 --- a/pkg/web/api/status/status_test.go +++ b/pkg/web/api/status/status_test.go @@ -28,8 +28,6 @@ import ( ) func TestPipelineError(t *testing.T) { - is := is.New(t) - type args struct { err error } @@ -55,14 +53,14 @@ func TestPipelineError(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + is.Equal(tt.want, PipelineError(tt.args.err)) }) } } func TestConnectorError(t *testing.T) { - is := is.New(t) - type args struct { err error } @@ -88,14 +86,14 @@ func TestConnectorError(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + is.Equal(tt.want, ConnectorError(tt.args.err)) }) } } func TestProcessorError(t *testing.T) { - is := is.New(t) - type args struct { err error } @@ -121,14 +119,14 @@ func TestProcessorError(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + is.Equal(tt.want, ProcessorError(tt.args.err)) }) } } func TestCodeFromError(t *testing.T) { - is := is.New(t) - type args struct { err error } @@ -210,6 +208,8 @@ func TestCodeFromError(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + is := is.New(t) + is.Equal(tt.want, codeFromError(tt.args.err)) }) } From 551376dc14c4e3529225fec0ec0daa340f2633b4 Mon Sep 17 00:00:00 2001 From: AdamHaffar Date: Sat, 16 Sep 2023 18:02:25 +0100 Subject: [PATCH 3/7] cerrors_test fix, .GetStackTrace would return [] or nil and could not be caught by isTrue(res == nil) alone --- pkg/foundation/cerrors/cerrors_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/foundation/cerrors/cerrors_test.go b/pkg/foundation/cerrors/cerrors_test.go index c9e18c304..ce72eb07b 100644 --- a/pkg/foundation/cerrors/cerrors_test.go +++ b/pkg/foundation/cerrors/cerrors_test.go @@ -140,7 +140,7 @@ func TestGetStackTrace(t *testing.T) { res := cerrors.GetStackTrace(tc.err) if tc.expected == nil { - is.True(res == nil) + is.True(res == nil || len(res.([]cerrors.Frame)) == 0) return } act, ok := res.([]cerrors.Frame) From 3c85db355bc482484e1230df6c9d9d90d06b01b2 Mon Sep 17 00:00:00 2001 From: AdamHaffar Date: Sat, 16 Sep 2023 18:06:26 +0100 Subject: [PATCH 4/7] lint fix --- pkg/foundation/cerrors/cerrors_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/foundation/cerrors/cerrors_test.go b/pkg/foundation/cerrors/cerrors_test.go index ce72eb07b..a40325471 100644 --- a/pkg/foundation/cerrors/cerrors_test.go +++ b/pkg/foundation/cerrors/cerrors_test.go @@ -146,7 +146,6 @@ func TestGetStackTrace(t *testing.T) { act, ok := res.([]cerrors.Frame) is.True(ok) // expected []cerrors.Frame is.Equal(tc.expected, act) - }) } } From cd27b00ff35bedf0c392ee6b7478a5aa3ccbb343 Mon Sep 17 00:00:00 2001 From: AdamHaffar Date: Mon, 18 Sep 2023 13:09:30 +0100 Subject: [PATCH 5/7] remove assert package --- pkg/foundation/assert/.keep | 0 pkg/foundation/assert/test.go | 84 ----------------------------------- 2 files changed, 84 deletions(-) delete mode 100644 pkg/foundation/assert/.keep delete mode 100644 pkg/foundation/assert/test.go diff --git a/pkg/foundation/assert/.keep b/pkg/foundation/assert/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/pkg/foundation/assert/test.go b/pkg/foundation/assert/test.go deleted file mode 100644 index 16c23b85a..000000000 --- a/pkg/foundation/assert/test.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright © 2022 Meroxa, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package assert declares dead-simple function testing helpers for Conduit that -// we can reasonably maintain ourselves. -package assert - -import ( - "fmt" - "path/filepath" - "reflect" - "runtime" - "testing" -) - -// True fails the test if the condition evaluates to false. -func True(tb testing.TB, condition bool, msg string, v ...interface{}) { - if !condition { - _, file, line, _ := runtime.Caller(1) - fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...) - tb.FailNow() - } -} - -// Ok fails the test if err is not nil. -func Ok(tb testing.TB, err error) { - if err != nil { - _, file, line, _ := runtime.Caller(1) - fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error()) - tb.FailNow() - } -} - -// Equal fails the test if exp is not equal to act. -func Equal(tb testing.TB, exp, act interface{}) { - if !reflect.DeepEqual(exp, act) { - _, file, line, _ := runtime.Caller(1) - fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act) - tb.FailNow() - } -} - -// Nil fails if the value is not nil. -func Nil(tb testing.TB, act interface{}) { - if act == nil { - return - } - // need to check for typed nil values - if !reflect.ValueOf(act).IsNil() { - _, file, line, _ := runtime.Caller(1) - fmt.Printf("\033[31m%s:%d: expected nil, got: %#v\033[39m\n\n", filepath.Base(file), line, act) - tb.FailNow() - } -} - -// NotNil fails if the value is nil. -func NotNil(tb testing.TB, act interface{}) { - // need to check for typed nil values - if act == nil || reflect.ValueOf(act).IsNil() { - _, file, line, _ := runtime.Caller(1) - fmt.Printf("\033[31m%s:%d: expected not nil, got: %#v\033[39m\n\n", filepath.Base(file), line, act) - tb.FailNow() - } -} - -// Error fails if the error is nil. -func Error(tb testing.TB, err error) { - if err == nil { - _, file, line, _ := runtime.Caller(1) - fmt.Printf("\033[31m%s:%d: expected error, got nil\033[39m\n\n", filepath.Base(file), line) - tb.FailNow() - } -} From f8d958834ecd74d8b51524d648e0cb6ecb89a35f Mon Sep 17 00:00:00 2001 From: AdamHaffar Date: Tue, 19 Sep 2023 13:34:48 +0100 Subject: [PATCH 6/7] refactor all tests in pkg/foundation/ that previously use assert package to use matryer instead --- pkg/foundation/ctxutil/filepath_test.go | 22 ++++-- pkg/foundation/ctxutil/messageid_test.go | 22 ++++-- pkg/foundation/ctxutil/requestid_test.go | 22 ++++-- pkg/foundation/database/acceptance_testing.go | 77 +++++++++++-------- pkg/foundation/database/badger/db_test.go | 8 +- .../database/postgres/db_integration_test.go | 7 +- pkg/foundation/grpcutil/interceptor_test.go | 42 +++++----- .../metrics/prometheus/counter_test.go | 18 +++-- .../metrics/prometheus/gauge_test.go | 18 +++-- .../metrics/prometheus/histogram_test.go | 18 +++-- .../metrics/prometheus/timer_test.go | 26 ++++--- pkg/foundation/rollback/rollback_test.go | 52 ++++++++----- 12 files changed, 207 insertions(+), 125 deletions(-) diff --git a/pkg/foundation/ctxutil/filepath_test.go b/pkg/foundation/ctxutil/filepath_test.go index 5b2b869a1..cc146ec3a 100644 --- a/pkg/foundation/ctxutil/filepath_test.go +++ b/pkg/foundation/ctxutil/filepath_test.go @@ -20,23 +20,27 @@ import ( "fmt" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/log" "github.com/google/uuid" + "github.com/matryer/is" "github.com/rs/zerolog" ) func TestContextWithFilepath_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() filepath := uuid.NewString() ctx = ContextWithFilepath(ctx, filepath) got := FilepathFromContext(ctx) - assert.Equal(t, filepath, got) + is.Equal(filepath, got) } func TestContextWithFilepath_Twice(t *testing.T) { + is := is.New(t) + ctx := context.Background() filepath := uuid.NewString() @@ -44,17 +48,21 @@ func TestContextWithFilepath_Twice(t *testing.T) { ctx = ContextWithFilepath(ctx, filepath) got := FilepathFromContext(ctx) - assert.Equal(t, filepath, got) + is.Equal(filepath, got) } func TestFilepathFromContext_Empty(t *testing.T) { + is := is.New(t) + ctx := context.Background() got := FilepathFromContext(ctx) - assert.Equal(t, "", got) + is.Equal("", got) } func TestFilepathLogCtxHook_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() filepath := uuid.NewString() @@ -66,10 +74,12 @@ func TestFilepathLogCtxHook_Success(t *testing.T) { FilepathLogCtxHook{}.Run(e, zerolog.InfoLevel, "") e.Send() - assert.Equal(t, fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.FilepathField, filepath)+"\n", logOutput.String()) + is.Equal(fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.FilepathField, filepath)+"\n", logOutput.String()) } func TestFilepathLogCtxHook_EmptyCtx(t *testing.T) { + is := is.New(t) + ctx := context.Background() var logOutput bytes.Buffer @@ -78,5 +88,5 @@ func TestFilepathLogCtxHook_EmptyCtx(t *testing.T) { FilepathLogCtxHook{}.Run(e, zerolog.InfoLevel, "") e.Send() - assert.Equal(t, `{"level":"info"}`+"\n", logOutput.String()) + is.Equal(`{"level":"info"}`+"\n", logOutput.String()) } diff --git a/pkg/foundation/ctxutil/messageid_test.go b/pkg/foundation/ctxutil/messageid_test.go index 993969b8a..f37882746 100644 --- a/pkg/foundation/ctxutil/messageid_test.go +++ b/pkg/foundation/ctxutil/messageid_test.go @@ -20,23 +20,27 @@ import ( "fmt" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/log" "github.com/google/uuid" + "github.com/matryer/is" "github.com/rs/zerolog" ) func TestContextWithMessageID_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() messageID := uuid.NewString() ctx = ContextWithMessageID(ctx, messageID) got := MessageIDFromContext(ctx) - assert.Equal(t, messageID, got) + is.Equal(messageID, got) } func TestContextWithMessageID_Twice(t *testing.T) { + is := is.New(t) + ctx := context.Background() messageID := uuid.NewString() @@ -44,17 +48,21 @@ func TestContextWithMessageID_Twice(t *testing.T) { ctx = ContextWithMessageID(ctx, messageID) got := MessageIDFromContext(ctx) - assert.Equal(t, messageID, got) + is.Equal(messageID, got) } func TestMessageIDFromContext_Empty(t *testing.T) { + is := is.New(t) + ctx := context.Background() got := MessageIDFromContext(ctx) - assert.Equal(t, "", got) + is.Equal("", got) } func TestMessageIDLogCtxHook_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() messageID := uuid.NewString() @@ -66,10 +74,12 @@ func TestMessageIDLogCtxHook_Success(t *testing.T) { MessageIDLogCtxHook{}.Run(e, zerolog.InfoLevel, "") e.Send() - assert.Equal(t, fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.MessageIDField, messageID)+"\n", logOutput.String()) + is.Equal(fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.MessageIDField, messageID)+"\n", logOutput.String()) } func TestMessageIDLogCtxHook_EmptyCtx(t *testing.T) { + is := is.New(t) + ctx := context.Background() var logOutput bytes.Buffer @@ -78,5 +88,5 @@ func TestMessageIDLogCtxHook_EmptyCtx(t *testing.T) { MessageIDLogCtxHook{}.Run(e, zerolog.InfoLevel, "") e.Send() - assert.Equal(t, `{"level":"info"}`+"\n", logOutput.String()) + is.Equal(`{"level":"info"}`+"\n", logOutput.String()) } diff --git a/pkg/foundation/ctxutil/requestid_test.go b/pkg/foundation/ctxutil/requestid_test.go index 5a90498e4..87e20cb8f 100644 --- a/pkg/foundation/ctxutil/requestid_test.go +++ b/pkg/foundation/ctxutil/requestid_test.go @@ -20,23 +20,27 @@ import ( "fmt" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/log" "github.com/google/uuid" + "github.com/matryer/is" "github.com/rs/zerolog" ) func TestContextWithRequestID_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() requestID := uuid.NewString() ctx = ContextWithRequestID(ctx, requestID) got := RequestIDFromContext(ctx) - assert.Equal(t, requestID, got) + is.Equal(requestID, got) } func TestContextWithRequestID_Twice(t *testing.T) { + is := is.New(t) + ctx := context.Background() requestID := uuid.NewString() @@ -44,17 +48,21 @@ func TestContextWithRequestID_Twice(t *testing.T) { ctx = ContextWithRequestID(ctx, requestID) got := RequestIDFromContext(ctx) - assert.Equal(t, requestID, got) + is.Equal(requestID, got) } func TestRequestIDFromContext_Empty(t *testing.T) { + is := is.New(t) + ctx := context.Background() got := RequestIDFromContext(ctx) - assert.Equal(t, "", got) + is.Equal("", got) } func TestRequestIDLogCtxHook_Success(t *testing.T) { + is := is.New(t) + ctx := context.Background() requestID := uuid.NewString() @@ -66,10 +74,12 @@ func TestRequestIDLogCtxHook_Success(t *testing.T) { RequestIDLogCtxHook{}.Run(e, zerolog.InfoLevel, "") e.Send() - assert.Equal(t, fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.RequestIDField, requestID)+"\n", logOutput.String()) + is.Equal(fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.RequestIDField, requestID)+"\n", logOutput.String()) } func TestRequestIDLogCtxHook_EmptyCtx(t *testing.T) { + is := is.New(t) + ctx := context.Background() var logOutput bytes.Buffer @@ -78,5 +88,5 @@ func TestRequestIDLogCtxHook_EmptyCtx(t *testing.T) { RequestIDLogCtxHook{}.Run(e, zerolog.InfoLevel, "") e.Send() - assert.Equal(t, `{"level":"info"}`+"\n", logOutput.String()) + is.Equal(`{"level":"info"}`+"\n", logOutput.String()) } diff --git a/pkg/foundation/database/acceptance_testing.go b/pkg/foundation/database/acceptance_testing.go index 048ce8431..b332ba128 100644 --- a/pkg/foundation/database/acceptance_testing.go +++ b/pkg/foundation/database/acceptance_testing.go @@ -17,15 +17,16 @@ package database import ( "context" "fmt" + "runtime" "sort" "strconv" "strings" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/cerrors" "github.com/google/uuid" + "github.com/matryer/is" ) // AcceptanceTest is the acceptance test that all implementations of DB should @@ -44,70 +45,78 @@ func AcceptanceTest(t *testing.T, db DB) { } func testSetGet(t *testing.T, db DB) { + is := is.New(t) + t.Run(testName(), func(t *testing.T) { txn, ctx, err := db.NewTransaction(context.Background(), true) - assert.Ok(t, err) + is.NoErr(err) defer txn.Discard() //nolint:goconst // we can turn off this check for test files key := "my-key" want := []byte(uuid.NewString()) err = db.Set(ctx, key, want) - assert.Ok(t, err) + is.NoErr(err) got, err := db.Get(ctx, key) - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } func testUpdate(t *testing.T, db DB) { + is := is.New(t) + t.Run(testName(), func(t *testing.T) { txn, ctx, err := db.NewTransaction(context.Background(), true) - assert.Ok(t, err) + is.NoErr(err) defer txn.Discard() key := "my-key" want := []byte(uuid.NewString()) err = db.Set(ctx, key, []byte("do not want this")) - assert.Ok(t, err) + is.NoErr(err) err = db.Set(ctx, key, want) - assert.Ok(t, err) + is.NoErr(err) got, err := db.Get(ctx, key) - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } func testDelete(t *testing.T, db DB) { + is := is.New(t) + t.Run(testName(), func(t *testing.T) { txn, ctx, err := db.NewTransaction(context.Background(), true) - assert.Ok(t, err) + is.NoErr(err) defer txn.Discard() key := "my-key" value := []byte(uuid.NewString()) err = db.Set(ctx, key, value) - assert.Ok(t, err) + is.NoErr(err) err = db.Set(ctx, key, nil) - assert.Ok(t, err) + is.NoErr(err) got, err := db.Get(ctx, key) - assert.Nil(t, got) - assert.True(t, cerrors.Is(err, ErrKeyNotExist), "expected error for non-existing key") + is.True(got == nil) + is.True(cerrors.Is(err, ErrKeyNotExist)) // expected error for non-existing key }) } func testGetKeys(t *testing.T, db DB) { + is := is.New(t) + const valuesSize = 100 t.Run(testName(), func(t *testing.T) { txn, ctx, err := db.NewTransaction(context.Background(), true) - assert.Ok(t, err) + is.NoErr(err) defer txn.Discard() keyPrefix := "key" @@ -116,61 +125,63 @@ func testGetKeys(t *testing.T, db DB) { key := fmt.Sprintf("key%2d", i) wantKeys = append(wantKeys, key) err := db.Set(ctx, key, []byte(strconv.Itoa(i))) - assert.Ok(t, err) + is.NoErr(err) } err = db.Set(ctx, "different prefix", []byte("should not be returned")) - assert.Ok(t, err) + is.NoErr(err) t.Run("withKeyPrefix", func(t *testing.T) { gotKeys, err := db.GetKeys(ctx, keyPrefix) - assert.Ok(t, err) - assert.True(t, len(gotKeys) == valuesSize, "expected %d keys, got %d", valuesSize, len(gotKeys)) + is.NoErr(err) + is.True(len(gotKeys) == valuesSize) // expects .GetKeys to return 100 keys sort.Strings(gotKeys) // sort so we can compare them - assert.Equal(t, wantKeys, gotKeys) + is.Equal(wantKeys, gotKeys) }) t.Run("emptyKeyPrefix", func(t *testing.T) { gotKeys, err := db.GetKeys(ctx, "") - assert.Ok(t, err) - assert.True(t, len(gotKeys) == valuesSize+1, "expected %d keys, got %d", valuesSize+1, len(gotKeys)) + is.NoErr(err) + is.True(len(gotKeys) == valuesSize+1) // expects .GetKeys to return 101 keys sort.Strings(gotKeys) // sort so we can compare them - assert.Equal(t, append([]string{"different prefix"}, wantKeys...), gotKeys) + is.Equal(append([]string{"different prefix"}, wantKeys...), gotKeys) }) t.Run("nonExistingPrefix", func(t *testing.T) { gotKeys, err := db.GetKeys(ctx, "non-existing-prefix") - assert.Ok(t, err) - assert.Equal(t, []string(nil), gotKeys) + is.NoErr(err) + is.Equal([]string(nil), gotKeys) }) }) } func testTransactionVisibility(t *testing.T, db DB) { + is := is.New(t) + t.Run(testName(), func(t *testing.T) { txn, ctx, err := db.NewTransaction(context.Background(), true) - assert.Ok(t, err) + is.NoErr(err) defer txn.Discard() key := "my-key" want := []byte("my-value") err = db.Set(ctx, key, want) - assert.Ok(t, err) + is.NoErr(err) // get the key outside of the transaction got, err := db.Get(context.Background(), key) - assert.Nil(t, got) - assert.True(t, cerrors.Is(err, ErrKeyNotExist), "expected error for non-existing key") + is.True(got == nil) + is.True(cerrors.Is(err, ErrKeyNotExist)) // expected error for non-existing key err = txn.Commit() - assert.Ok(t, err) + is.NoErr(err) defer db.Set(context.Background(), key, nil) //nolint:errcheck // cleanup // key should be visible now got, err = db.Get(context.Background(), key) - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } diff --git a/pkg/foundation/database/badger/db_test.go b/pkg/foundation/database/badger/db_test.go index 63d160eb8..f09979e57 100644 --- a/pkg/foundation/database/badger/db_test.go +++ b/pkg/foundation/database/badger/db_test.go @@ -18,18 +18,20 @@ import ( "path/filepath" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/database" + "github.com/matryer/is" "github.com/rs/zerolog" ) func TestDB(t *testing.T) { + is := is.New(t) + path := filepath.Join(t.TempDir(), "badger.db") badger, err := New(zerolog.Nop(), path) - assert.Ok(t, err) + is.NoErr(err) t.Cleanup(func() { err := badger.Close() - assert.Ok(t, err) + is.NoErr(err) }) database.AcceptanceTest(t, badger) } diff --git a/pkg/foundation/database/postgres/db_integration_test.go b/pkg/foundation/database/postgres/db_integration_test.go index 43cbcc556..191ab8c70 100644 --- a/pkg/foundation/database/postgres/db_integration_test.go +++ b/pkg/foundation/database/postgres/db_integration_test.go @@ -21,7 +21,6 @@ import ( "fmt" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/database" "github.com/conduitio/conduit/pkg/foundation/log" ) @@ -32,12 +31,12 @@ func TestDB(t *testing.T) { ctx := context.Background() logger := log.Nop() db, err := New(ctx, logger, "postgres://meroxauser:meroxapass@localhost:5432/meroxadb?sslmode=disable", testTable) - assert.Ok(t, err) + is.NoErr(err) t.Cleanup(func() { _, err := db.pool.Exec(ctx, fmt.Sprintf("DROP TABLE %q", testTable)) - assert.Ok(t, err) + is.NoErr(err) err = db.Close() - assert.Ok(t, err) + is.NoErr(err) }) database.AcceptanceTest(t, db) } diff --git a/pkg/foundation/grpcutil/interceptor_test.go b/pkg/foundation/grpcutil/interceptor_test.go index c9222235b..f6441e63a 100644 --- a/pkg/foundation/grpcutil/interceptor_test.go +++ b/pkg/foundation/grpcutil/interceptor_test.go @@ -20,10 +20,10 @@ import ( "encoding/json" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/ctxutil" "github.com/conduitio/conduit/pkg/foundation/log" "github.com/google/uuid" + "github.com/matryer/is" "github.com/rs/zerolog" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -31,6 +31,8 @@ import ( ) func TestRequestIDUnaryServerInterceptor_WithRequestIDHeader(t *testing.T) { + is := is.New(t) + requestID := uuid.NewString() ctx := metadata.NewIncomingContext(context.Background(), metadata.MD{ RequestIDHeader: []string{requestID}, @@ -48,18 +50,20 @@ func TestRequestIDUnaryServerInterceptor_WithRequestIDHeader(t *testing.T) { handlerIsCalled = true // supplied context should contain request ID gotRequestID := ctxutil.RequestIDFromContext(ctx) - assert.Equal(t, requestID, gotRequestID) - assert.Equal(t, nil, req) + is.Equal(requestID, gotRequestID) + is.Equal(nil, req) return want, nil }, ) - assert.Ok(t, err) - assert.Equal(t, want, got) - assert.True(t, handlerIsCalled, "expected handler to be called") + is.NoErr(err) + is.Equal(want, got) + is.True(handlerIsCalled) // expected handler to be called } func TestRequestIDUnaryServerInterceptor_GenerateRequestID(t *testing.T) { + is := is.New(t) + var handlerIsCalled bool want := "response" @@ -72,18 +76,20 @@ func TestRequestIDUnaryServerInterceptor_GenerateRequestID(t *testing.T) { handlerIsCalled = true // supplied context should contain request ID gotRequestID := ctxutil.RequestIDFromContext(ctx) - assert.True(t, gotRequestID != "", "request id should not be empty") - assert.Equal(t, nil, req) + is.True(gotRequestID != "") // request id should not be empty + is.Equal(nil, req) return want, nil }, ) - assert.Ok(t, err) - assert.Equal(t, want, got) - assert.True(t, handlerIsCalled, "expected handler to be called") + is.NoErr(err) + is.Equal(want, got) + is.True(handlerIsCalled) // expected handler to be called } func TestLoggerUnaryServerInterceptor(t *testing.T) { + is := is.New(t) + var logOutput bytes.Buffer logger := log.New(zerolog.New(&logOutput)) logger.Logger = logger.Hook(ctxutil.RequestIDLogCtxHook{}) @@ -110,19 +116,19 @@ func TestLoggerUnaryServerInterceptor(t *testing.T) { }, func(ctx context.Context, req interface{}) (interface{}, error) { handlerIsCalled = true - assert.Equal(t, incomingCtx, ctx) - assert.Equal(t, nil, req) + is.Equal(incomingCtx, ctx) + is.Equal(nil, req) return want, nil }, ) - assert.Ok(t, err) - assert.Equal(t, want, got) - assert.True(t, handlerIsCalled, "expected handler to be called") + is.NoErr(err) + is.Equal(want, got) + is.True(handlerIsCalled) // expected handler to be called var gotLog map[string]interface{} err = json.Unmarshal(logOutput.Bytes(), &gotLog) - assert.Ok(t, err) + is.NoErr(err) wantLog := map[string]interface{}{ "level": "info", @@ -134,5 +140,5 @@ func TestLoggerUnaryServerInterceptor(t *testing.T) { log.HTTPEndpointField: httpEndpoint, } - assert.Equal(t, wantLog, gotLog) + is.Equal(wantLog, gotLog) } diff --git a/pkg/foundation/metrics/prometheus/counter_test.go b/pkg/foundation/metrics/prometheus/counter_test.go index 33ca6b279..07f2b46e6 100644 --- a/pkg/foundation/metrics/prometheus/counter_test.go +++ b/pkg/foundation/metrics/prometheus/counter_test.go @@ -19,14 +19,16 @@ import ( "sort" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/metrics" + "github.com/matryer/is" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "google.golang.org/protobuf/proto" ) func TestCounter(t *testing.T) { + is := is.New(t) + testCases := []struct { name string observe func(m metrics.Counter) @@ -78,11 +80,11 @@ func TestCounter(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } } @@ -100,6 +102,8 @@ func TestCounter_IncNegative(t *testing.T) { } func TestLabeledCounter(t *testing.T) { + is := is.New(t) + testCases := []struct { name string observe func(m metrics.LabeledCounter) @@ -171,11 +175,11 @@ func TestLabeledCounter(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } } diff --git a/pkg/foundation/metrics/prometheus/gauge_test.go b/pkg/foundation/metrics/prometheus/gauge_test.go index 6dec7be20..ab0587476 100644 --- a/pkg/foundation/metrics/prometheus/gauge_test.go +++ b/pkg/foundation/metrics/prometheus/gauge_test.go @@ -19,14 +19,16 @@ import ( "sort" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/metrics" + "github.com/matryer/is" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "google.golang.org/protobuf/proto" ) func TestGauge(t *testing.T) { + is := is.New(t) + testCases := []struct { name string observe func(m metrics.Gauge) @@ -121,16 +123,18 @@ func TestGauge(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } } func TestLabeledGauge(t *testing.T) { + is := is.New(t) + testCases := []struct { name string observe func(m metrics.LabeledGauge) @@ -202,11 +206,11 @@ func TestLabeledGauge(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } } diff --git a/pkg/foundation/metrics/prometheus/histogram_test.go b/pkg/foundation/metrics/prometheus/histogram_test.go index 9dfd3e818..c9fd00c7a 100644 --- a/pkg/foundation/metrics/prometheus/histogram_test.go +++ b/pkg/foundation/metrics/prometheus/histogram_test.go @@ -19,14 +19,16 @@ import ( "sort" "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/metrics" + "github.com/matryer/is" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "google.golang.org/protobuf/proto" ) func TestHistogram(t *testing.T) { + is := is.New(t) + testCases := []struct { name string observe func(m metrics.Histogram) @@ -87,16 +89,18 @@ func TestHistogram(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } } func TestLabeledHistogram(t *testing.T) { + is := is.New(t) + testCases := []struct { name string observe func(m metrics.LabeledHistogram) @@ -188,11 +192,11 @@ func TestLabeledHistogram(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } } diff --git a/pkg/foundation/metrics/prometheus/timer_test.go b/pkg/foundation/metrics/prometheus/timer_test.go index b404c6005..1263c3630 100644 --- a/pkg/foundation/metrics/prometheus/timer_test.go +++ b/pkg/foundation/metrics/prometheus/timer_test.go @@ -20,14 +20,16 @@ import ( "testing" "time" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/metrics" + "github.com/matryer/is" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "google.golang.org/protobuf/proto" ) func TestTimer(t *testing.T) { + is := is.New(t) + testCases := []struct { name string observe func(m metrics.Timer) @@ -88,16 +90,18 @@ func TestTimer(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } } func TestTimer_Since(t *testing.T) { + is := is.New(t) + reg := NewRegistry(nil) m := reg.NewTimer("my_timer", "test timer") @@ -120,10 +124,10 @@ func TestTimer_Since(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) + is.NoErr(err) // first manually check the difference, we can't know the actual sum diff := *got[0].Metric[0].Histogram.SampleSum - *want[0].Metric[0].Histogram.SampleSum @@ -133,10 +137,12 @@ func TestTimer_Since(t *testing.T) { // add difference to our estimate and make sure everything else matches *want[0].Metric[0].Histogram.SampleSum += diff - assert.Equal(t, want, got) + is.Equal(want, got) } func TestLabeledTimer(t *testing.T) { + is := is.New(t) + testCases := []struct { name string observe func(m metrics.LabeledTimer) @@ -228,11 +234,11 @@ func TestLabeledTimer(t *testing.T) { promRegistry := prometheus.NewRegistry() err := promRegistry.Register(reg) - assert.Ok(t, err) + is.NoErr(err) got, err := promRegistry.Gather() - assert.Ok(t, err) - assert.Equal(t, want, got) + is.NoErr(err) + is.Equal(want, got) }) } } diff --git a/pkg/foundation/rollback/rollback_test.go b/pkg/foundation/rollback/rollback_test.go index 6362feda7..a08e9dafa 100644 --- a/pkg/foundation/rollback/rollback_test.go +++ b/pkg/foundation/rollback/rollback_test.go @@ -17,8 +17,8 @@ package rollback import ( "testing" - "github.com/conduitio/conduit/pkg/foundation/assert" "github.com/conduitio/conduit/pkg/foundation/cerrors" + "github.com/matryer/is" ) type callRecorder struct { @@ -35,27 +35,33 @@ func (cr *callRecorder) f() error { } func TestRollback_ExecuteEmpty(t *testing.T) { + is := is.New(t) + var r R err := r.Execute() - assert.Ok(t, err) + is.NoErr(err) } func TestRollback_ExecuteTwice(t *testing.T) { + is := is.New(t) + var r R var cr callRecorder r.Append(cr.f) err := r.Execute() - assert.Ok(t, err) - assert.Equal(t, 1, cr.calls) + is.NoErr(err) + is.Equal(1, cr.calls) err = r.Execute() - assert.Ok(t, err) - assert.Equal(t, 1, cr.calls) // still only 1 call + is.NoErr(err) + is.Equal(1, cr.calls) // still only 1 call } func TestRollback_ExecuteMany(t *testing.T) { + is := is.New(t) + var r R var cr callRecorder const wantCalls = 100 @@ -65,11 +71,13 @@ func TestRollback_ExecuteMany(t *testing.T) { } err := r.Execute() - assert.Ok(t, err) - assert.Equal(t, wantCalls, cr.calls) + is.NoErr(err) + is.Equal(wantCalls, cr.calls) } func TestRollback_ExecuteError(t *testing.T) { + is := is.New(t) + var r R var cr callRecorder cr.returnError = true // rollback will return an error @@ -77,18 +85,20 @@ func TestRollback_ExecuteError(t *testing.T) { r.Append(cr.f) err := r.Execute() - assert.Error(t, err) - assert.Equal(t, 1, cr.calls) + is.True(err != nil) + is.Equal(1, cr.calls) // calling Execute again should try the same rollback again cr.returnError = false // let's succeed this time err = r.Execute() - assert.Ok(t, err) - assert.Equal(t, 2, cr.calls) + is.NoErr(err) + is.Equal(2, cr.calls) } func TestRollback_MustExecuteSuccess(t *testing.T) { + is := is.New(t) + var r R var cr callRecorder @@ -96,7 +106,7 @@ func TestRollback_MustExecuteSuccess(t *testing.T) { if recover() != nil { t.Fatal("Execute should not have panicked") } - assert.Equal(t, 1, cr.calls) + is.Equal(1, cr.calls) }() r.Append(cr.f) @@ -104,6 +114,8 @@ func TestRollback_MustExecuteSuccess(t *testing.T) { } func TestRollback_MustExecutePanic(t *testing.T) { + is := is.New(t) + var r R var cr callRecorder cr.returnError = true // rollback will return an error @@ -112,7 +124,7 @@ func TestRollback_MustExecutePanic(t *testing.T) { if recover() == nil { t.Fatal("Execute should have panicked") } - assert.Equal(t, 1, cr.calls) + is.Equal(1, cr.calls) }() r.Append(cr.f) @@ -120,17 +132,21 @@ func TestRollback_MustExecutePanic(t *testing.T) { } func TestRollback_ExecutePure(t *testing.T) { + is := is.New(t) + var r R var called bool r.AppendPure(func() { called = true }) err := r.Execute() - assert.Ok(t, err) - assert.True(t, called, "rollback func was not called") + is.NoErr(err) + is.True(called) // rollback func was not called } func TestRollback_Skip(t *testing.T) { + is := is.New(t) + var r R var cr callRecorder @@ -138,6 +154,6 @@ func TestRollback_Skip(t *testing.T) { r.Skip() // skip should remove all rollback calls err := r.Execute() // execute does nothing - assert.Ok(t, err) - assert.Equal(t, 0, cr.calls) + is.NoErr(err) + is.Equal(0, cr.calls) } From f695c8be2068a1343d952222a2ac174b80b47a4d Mon Sep 17 00:00:00 2001 From: Haris Osmanagic Date: Tue, 19 Sep 2023 14:56:05 +0200 Subject: [PATCH 7/7] fix test --- pkg/foundation/database/postgres/db_integration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/foundation/database/postgres/db_integration_test.go b/pkg/foundation/database/postgres/db_integration_test.go index 191ab8c70..b3e36e8ee 100644 --- a/pkg/foundation/database/postgres/db_integration_test.go +++ b/pkg/foundation/database/postgres/db_integration_test.go @@ -19,6 +19,7 @@ package postgres import ( "context" "fmt" + "github.com/matryer/is" "testing" "github.com/conduitio/conduit/pkg/foundation/database" @@ -26,6 +27,7 @@ import ( ) func TestDB(t *testing.T) { + is := is.New(t) const testTable = "conduit_store_test" ctx := context.Background()