0815cb35fb
Basic Lint Checks * basic
123 lines
3.2 KiB
Go
123 lines
3.2 KiB
Go
package query_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/query"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParseQuery(t *testing.T) {
|
|
cfg := "example"
|
|
q := &query.Query{
|
|
ID: uuid.New(),
|
|
Type: resultprocessor.TypeJsonExtractor,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(2),
|
|
RequiredQueryIDs: &[]uuid.UUID{
|
|
uuid.New(),
|
|
},
|
|
Config: &cfg,
|
|
}
|
|
|
|
out := query.ParseQuery(q)
|
|
assert.EqualExportedValues(t, resultprocessor.Query{
|
|
ID: q.ID,
|
|
Type: q.Type,
|
|
Version: q.ActiveVersion,
|
|
RequiredQueryIDs: q.RequiredQueryIDs,
|
|
Config: q.Config,
|
|
}, *out)
|
|
}
|
|
|
|
func TestParseFullActiveQuery(t *testing.T) {
|
|
q := &repository.Fullactivequery{
|
|
ID: database.MustToDBUUID(uuid.New()),
|
|
Type: repository.QuerytypeContextFull,
|
|
Activeversion: int32(1),
|
|
Latestversion: int32(2),
|
|
Requiredids: []pgtype.UUID{
|
|
database.MustToDBUUID(uuid.New()),
|
|
},
|
|
Config: []byte("example"),
|
|
}
|
|
|
|
out, err := query.ParseFullActiveQuery(q)
|
|
assert.NoError(t, err)
|
|
bcfg := string(q.Config)
|
|
assert.EqualExportedValues(t, query.Query{
|
|
ID: database.MustToUUID(q.ID),
|
|
Type: resultprocessor.TypeContextFull,
|
|
ActiveVersion: q.Activeversion,
|
|
LatestVersion: q.Latestversion,
|
|
RequiredQueryIDs: &[]uuid.UUID{
|
|
database.MustToUUID(q.Requiredids[0]),
|
|
},
|
|
Config: &bcfg,
|
|
}, *out)
|
|
}
|
|
|
|
func TestFullActiveQueryEmpty(t *testing.T) {
|
|
dbQuery := &repository.Fullactivequery{
|
|
ID: database.MustToDBUUID(uuid.New()),
|
|
Type: repository.QuerytypeContextFull,
|
|
Activeversion: int32(1),
|
|
Latestversion: int32(2),
|
|
}
|
|
|
|
out, err := query.ParseFullActiveQuery(dbQuery)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, query.Query{
|
|
ID: database.MustToUUID(dbQuery.ID),
|
|
Type: resultprocessor.TypeContextFull,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(2),
|
|
}, *out)
|
|
}
|
|
|
|
func TestFullActiveQueryWithNullUUID(t *testing.T) {
|
|
dbQuery := &repository.Fullactivequery{
|
|
ID: database.MustToDBUUID(uuid.New()),
|
|
Type: repository.QuerytypeContextFull,
|
|
Activeversion: int32(1),
|
|
Latestversion: int32(2),
|
|
}
|
|
|
|
out, err := query.ParseFullActiveQuery(dbQuery)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, query.Query{
|
|
ID: database.MustToUUID(dbQuery.ID),
|
|
Type: resultprocessor.TypeContextFull,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(2),
|
|
}, *out)
|
|
}
|
|
|
|
func TestFullActiveQueryArray(t *testing.T) {
|
|
dbQueries := []*repository.Fullactivequery{
|
|
{
|
|
ID: database.MustToDBUUID(uuid.New()),
|
|
Type: repository.QuerytypeContextFull,
|
|
Activeversion: int32(1),
|
|
Latestversion: int32(2),
|
|
},
|
|
}
|
|
|
|
out, err := query.ParseFullActiveQueryArray(dbQueries)
|
|
assert.NoError(t, err)
|
|
assert.EqualExportedValues(t, []*query.Query{
|
|
{
|
|
ID: database.MustToUUID(dbQueries[0].ID),
|
|
Type: resultprocessor.TypeContextFull,
|
|
ActiveVersion: int32(1),
|
|
LatestVersion: int32(2),
|
|
},
|
|
}, out)
|
|
}
|