Skip to content

Commit

Permalink
tests: Add test for NewStorageFromString (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinnyYi authored Aug 26, 2021
1 parent 841f5c1 commit b6c58a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
37 changes: 27 additions & 10 deletions tests/connstr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,35 @@ func TestFromString(t *testing.T) {

for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
servicer, err := services.NewServicerFromString(tt.connStr)
service, ok := servicer.(*Service)
t.Run("NewServicerFromString", func(t *testing.T) {
servicer, err := services.NewServicerFromString(tt.connStr)
service, ok := servicer.(*Service)

if tt.err == nil {
assert.Nil(t, err)
assert.True(t, ok)
} else {
assert.True(t, errors.Is(err, tt.err))
return
}
if tt.err == nil {
assert.Nil(t, err)
assert.True(t, ok)
} else {
assert.True(t, errors.Is(err, tt.err))
return
}

assert.Equal(t, service.Pairs, tt.pairs)
})
t.Run("NewStoragerFromString", func(t *testing.T) {
storager, err := services.NewStoragerFromString(tt.connStr)
storage, ok := storager.(*Storage)

if tt.err == nil {
assert.Nil(t, err)
assert.True(t, ok)
} else {
assert.True(t, errors.Is(err, tt.err))
return
}

assert.Equal(t, storage.Pairs, tt.pairs)
})

assert.Equal(t, service.Pairs, tt.pairs)
})
}
}
2 changes: 2 additions & 0 deletions tests/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Storage struct {

objects []*Object

Pairs []Pair

UnimplementedCopier
UnimplementedFetcher
UnimplementedMover
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func NewServicer(pairs ...typ.Pair) (typ.Servicer, error) {
}

func NewStorager(pairs ...typ.Pair) (typ.Storager, error) {
return &Storage{}, nil
return &Storage{Pairs: pairs}, nil
}

0 comments on commit b6c58a8

Please sign in to comment.