Dawid Wysokiński
3b4f42e344
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#186
92 lines
1.7 KiB
Go
92 lines
1.7 KiB
Go
package bundb_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/bundb"
|
|
"gitea.dwysokinski.me/twhelp/core/internal/bundb/bundbtest"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestVersion_List_ListCount(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if testing.Short() {
|
|
t.Skip("skipping long-running test")
|
|
}
|
|
|
|
repo := bundb.NewVersion(bundbtest.NewDB(t))
|
|
|
|
allVersions := []string{
|
|
"pl",
|
|
"en",
|
|
"de",
|
|
"uk",
|
|
"it",
|
|
"fr",
|
|
"us",
|
|
"nl",
|
|
"es",
|
|
"ro",
|
|
"ru",
|
|
"gr",
|
|
"tr",
|
|
"cs",
|
|
"ch",
|
|
"pt",
|
|
"br",
|
|
"hu",
|
|
"sk",
|
|
}
|
|
|
|
resListCount, count, err := repo.ListCount(context.Background())
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(len(allVersions)), count)
|
|
assert.Len(t, resListCount, len(allVersions))
|
|
for _, versionCode := range allVersions {
|
|
found := false
|
|
for _, version := range resListCount {
|
|
if version.Code == versionCode {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found, "version (code=%s) not found", versionCode)
|
|
}
|
|
|
|
resList, err := repo.List(context.Background())
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, resListCount, resList)
|
|
}
|
|
|
|
func TestVersion_GetByCode(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if testing.Short() {
|
|
t.Skip("skipping long-running test")
|
|
}
|
|
|
|
repo := bundb.NewVersion(bundbtest.NewDB(t))
|
|
|
|
t.Run("OK", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
version, err := repo.GetByCode(context.Background(), "pl")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "pl", version.Code)
|
|
})
|
|
|
|
t.Run("ERR: version not found", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
code := "pl2"
|
|
version, err := repo.GetByCode(context.Background(), code)
|
|
assert.ErrorIs(t, err, domain.VersionNotFoundError{VerCode: code})
|
|
assert.Zero(t, version)
|
|
})
|
|
}
|