Skip to content

Commit

Permalink
Remove Assert Package 1/3 (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamHaffar authored Aug 31, 2023
1 parent 7a8f41b commit 784f05f
Show file tree
Hide file tree
Showing 12 changed files with 532 additions and 368 deletions.
8 changes: 5 additions & 3 deletions pkg/conduit/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ package conduit
import (
"testing"

"github.com/conduitio/conduit/pkg/foundation/assert"
"github.com/conduitio/conduit/pkg/foundation/database/inmemory"
"github.com/matryer/is"
)

func TestConfig_Validate(t *testing.T) {
is := is.New(t)

testCases := []struct {
name string
setupConfig func(Config) Config
Expand Down Expand Up @@ -162,9 +164,9 @@ func TestConfig_Validate(t *testing.T) {
underTest := tc.setupConfig(validConfig)
got := underTest.Validate()
if got == nil {
assert.Nil(t, tc.want)
is.True(tc.want == nil)
} else {
assert.Equal(t, tc.want.Error(), got.Error())
is.Equal(tc.want.Error(), got.Error())
}
})
}
Expand Down
27 changes: 15 additions & 12 deletions pkg/pipeline/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"fmt"
"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/google/uuid"
"github.com/matryer/is"
)

type boringError struct {
Expand Down Expand Up @@ -63,6 +63,7 @@ func TestConfigStore_SetGet(t *testing.T) {
}

func testConfigStoreSetGet(t *testing.T, e error) {
is := is.New(t)
ctx := context.Background()
db := &inmemory.DB{}

Expand All @@ -81,14 +82,15 @@ func testConfigStoreSetGet(t *testing.T, e error) {
}

err := s.Set(ctx, want.ID, want)
assert.Ok(t, err)
is.NoErr(err)

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{}

Expand All @@ -106,16 +108,17 @@ func TestConfigStore_GetAll(t *testing.T) {
ProcessorIDs: []string{uuid.NewString(), uuid.NewString()},
}
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{}

Expand All @@ -124,13 +127,13 @@ func TestConfigStore_Delete(t *testing.T) {
want := &Instance{ID: uuid.NewString()}

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)
}
Loading

0 comments on commit 784f05f

Please sign in to comment.