7001ca854c
Queuing Changes and Cfg Testing * staarting * staarting * startedpush * note * save * mocking * removederrs * fixtests * cleanuperrs * newenvsetup * preppingtests * queue * mmovetocfgpassunittests * sortoutconfig * passinginteg * deps * fixtests
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package database_test
|
|
|
|
import (
|
|
"queryorchestration/internal/database"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestToDBUUID(t *testing.T) {
|
|
id := uuid.New()
|
|
|
|
dbID, err := database.ToDBUUID(id)
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, dbID.Valid)
|
|
assert.Equal(t, id.String(), uuid.UUID(dbID.Bytes).String())
|
|
}
|
|
|
|
func TestToDBUUIDNil(t *testing.T) {
|
|
id := uuid.Nil
|
|
|
|
dbID, err := database.ToDBUUID(id)
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, dbID.Valid)
|
|
assert.Equal(t, id.String(), uuid.UUID(dbID.Bytes).String())
|
|
}
|
|
|
|
func TestToDBUUIDArray(t *testing.T) {
|
|
ids := []uuid.UUID{uuid.Nil, uuid.New()}
|
|
|
|
dbIDs, err := database.ToDBUUIDArray(ids)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, dbIDs, 1)
|
|
assert.ElementsMatch(t, []pgtype.UUID{database.MustToDBUUID(ids[1])}, dbIDs)
|
|
}
|
|
|
|
func TestToUUID(t *testing.T) {
|
|
dbID, err := database.ToDBUUID(uuid.New())
|
|
assert.NoError(t, err)
|
|
|
|
id, err := database.ToUUID(dbID)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, id.String(), uuid.UUID(dbID.Bytes).String())
|
|
}
|
|
|
|
func TestToUUIDArray(t *testing.T) {
|
|
ogIDs := []uuid.UUID{uuid.Nil, uuid.New()}
|
|
dbIDs := database.MustToDBUUIDArray(ogIDs)
|
|
|
|
ids, err := database.ToUUIDArray(dbIDs)
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, ids, 1)
|
|
assert.ElementsMatch(t, []uuid.UUID{ogIDs[1]}, ids)
|
|
}
|