feat: format and add test
This commit is contained in:
28
client/cards_test.go
Normal file
28
client/cards_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetCardByID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cardID string
|
||||
wantErr bool
|
||||
wantCard *Card
|
||||
}{
|
||||
{"valid card", "xy1-1", false, &Card{ID: "xy1-1"}},
|
||||
{"invalid card", "invalid-id", true, nil},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
card, err := GetCardByID(tt.cardID)
|
||||
|
||||
require.ErrorIs(t, err, ErrNotFound)
|
||||
require.Equal(t, tt.wantCard, card, "expected card: %v, got: %v for cardID %v", tt.wantCard, card, tt.cardID)
|
||||
})
|
||||
}
|
||||
}
|
||||
28
client/series_test.go
Normal file
28
client/series_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetSeriesByID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
seriesID string
|
||||
wantErr bool
|
||||
wantSeries *Series
|
||||
}{
|
||||
{"valid series", "xy", false, &Series{ID: "xy"}},
|
||||
{"invalid series", "invalid-id", true, nil},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
series, err := GetSeriesByID(tt.seriesID)
|
||||
|
||||
require.ErrorIs(t, err, ErrNotFound)
|
||||
require.Equal(t, tt.wantSeries, series, "expected series: %v, got: %v for seriesID %v", tt.wantSeries, series, tt.seriesID)
|
||||
})
|
||||
}
|
||||
}
|
||||
28
client/sets_test.go
Normal file
28
client/sets_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetSetByID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
setID string
|
||||
wantErr bool
|
||||
wantSet *Set
|
||||
}{
|
||||
{"valid set", "xy1", false, &Set{ID: "xy1"}},
|
||||
{"invalid set", "invalid-id", true, nil},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
set, err := GetSetByID(tt.setID)
|
||||
|
||||
require.ErrorIs(t, err, ErrNotFound)
|
||||
require.Equal(t, tt.wantSet, set, "expected set: %v, got: %v for setID %v", tt.wantSet, set, tt.setID)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user