Merged in bugfix/integrationstests (pull request #7)
Add get, list, create, deprecate query service integration tests * showtestlines * more config * roundone * splituptests * splitfurther
This commit is contained in:
@@ -42,7 +42,7 @@ func (s *Service) submitCreate(ctx context.Context, entity *queryprocessor.Creat
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
// defer tx.Rollback(ctx)
|
||||
defer tx.Rollback(ctx)
|
||||
|
||||
qtx := s.db.Queries.WithTx(tx)
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Query, error) {
|
||||
}
|
||||
|
||||
func ParseFullActiveQuery(q *repository.Fullactivequery) (*Query, error) {
|
||||
reqQueryIDs := database.MustToUUIDArray(q.Requiredids)
|
||||
reqQueryIDs := []uuid.UUID{}
|
||||
if !(len(q.Requiredids) == 0 || len(q.Requiredids) == 1 && database.MustToUUID(q.Requiredids[0]) == uuid.Nil) {
|
||||
reqQueryIDs = database.MustToUUIDArray(q.Requiredids)
|
||||
}
|
||||
|
||||
qType, err := queryprocessor.ParseDBType(q.Type)
|
||||
if err != nil {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -51,3 +52,47 @@ func TestGet(t *testing.T) {
|
||||
|
||||
assert.EqualExportedValues(t, query, *returnQuery)
|
||||
}
|
||||
|
||||
func TestFullActiveQueryEmpty(t *testing.T) {
|
||||
dbQuery := &repository.Fullactivequery{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: int32(1),
|
||||
Latestversion: int32(2),
|
||||
Config: []byte(""),
|
||||
Requiredids: []pgtype.UUID{},
|
||||
}
|
||||
|
||||
out, err := query.ParseFullActiveQuery(dbQuery)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, query.Query{
|
||||
ID: database.MustToUUID(dbQuery.ID),
|
||||
Type: queryprocessor.TypeContextFull,
|
||||
ActiveVersion: int32(1),
|
||||
LatestVersion: int32(2),
|
||||
Config: "",
|
||||
RequiredQueryIDs: []uuid.UUID{},
|
||||
}, *out)
|
||||
}
|
||||
|
||||
func TestFullActiveQueryWithNullUUID(t *testing.T) {
|
||||
dbQuery := &repository.Fullactivequery{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: int32(1),
|
||||
Latestversion: int32(2),
|
||||
Config: []byte(""),
|
||||
Requiredids: []pgtype.UUID{database.MustToDBUUID(uuid.Nil)},
|
||||
}
|
||||
|
||||
out, err := query.ParseFullActiveQuery(dbQuery)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualExportedValues(t, query.Query{
|
||||
ID: database.MustToUUID(dbQuery.ID),
|
||||
Type: queryprocessor.TypeContextFull,
|
||||
ActiveVersion: int32(1),
|
||||
LatestVersion: int32(2),
|
||||
Config: "",
|
||||
RequiredQueryIDs: []uuid.UUID{},
|
||||
}, *out)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
serviceinterfaces "queryorchestration/api/serviceInterfaces"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestExportService(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := test.CreateAPIWithDependencies(t, ctx, "queryService")
|
||||
defer cleanup()
|
||||
|
||||
expClient := serviceinterfaces.NewExportServiceClient(conn)
|
||||
|
||||
idRes, err := expClient.Trigger(ctx, &serviceinterfaces.ExportTrigger{})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, idRes)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
serviceinterfaces "queryorchestration/api/serviceInterfaces"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestJobCollectorService(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := test.CreateAPIWithDependencies(t, ctx, "queryService")
|
||||
defer cleanup()
|
||||
|
||||
collClient := serviceinterfaces.NewJobCollectorServiceClient(conn)
|
||||
|
||||
idRes, err := collClient.Create(ctx, &serviceinterfaces.JobCollectorCreate{})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, idRes)
|
||||
|
||||
collRes, err := collClient.Get(ctx, &serviceinterfaces.IdMessage{})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, collRes)
|
||||
|
||||
res, err := collClient.Update(ctx, &serviceinterfaces.JobCollectorUpdate{})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
serviceinterfaces "queryorchestration/api/serviceInterfaces"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestQueryServiceList(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := test.CreateAPIWithDependencies(t, ctx, "queryService")
|
||||
defer cleanup()
|
||||
|
||||
client := serviceinterfaces.NewQueryServiceClient(conn)
|
||||
|
||||
idRes, err := client.Create(ctx, &serviceinterfaces.QueryCreate{
|
||||
Type: serviceinterfaces.QueryType_QUERY_TYPE_CONTEXT_FULL,
|
||||
Config: nil,
|
||||
RequiredQueries: []string{},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
id := idRes.GetId()
|
||||
assert.NotEmpty(t, id)
|
||||
|
||||
queriesRes, err := client.List(ctx, &serviceinterfaces.QueryFilter{})
|
||||
assert.Nil(t, err)
|
||||
assert.Len(t, queriesRes.Queries, 1)
|
||||
assert.Equal(t, id, queriesRes.Queries[0].Id)
|
||||
|
||||
res, err := client.Update(ctx, &serviceinterfaces.QueryUpdate{
|
||||
Id: id,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
serviceinterfaces "queryorchestration/api/serviceInterfaces"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestQueryService(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := test.CreateAPIWithDependencies(t, ctx, "queryService")
|
||||
defer cleanup()
|
||||
|
||||
client := serviceinterfaces.NewQueryServiceClient(conn)
|
||||
|
||||
idRes, err := client.Create(ctx, &serviceinterfaces.QueryCreate{
|
||||
Type: serviceinterfaces.QueryType_QUERY_TYPE_CONTEXT_FULL,
|
||||
Config: nil,
|
||||
RequiredQueries: []string{},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
id := idRes.GetId()
|
||||
assert.NotEmpty(t, id)
|
||||
|
||||
queryRes, err := client.Get(ctx, &serviceinterfaces.IdMessage{
|
||||
Id: id,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, id, queryRes.Id)
|
||||
assert.Equal(t, serviceinterfaces.QueryType_QUERY_TYPE_CONTEXT_FULL, queryRes.Type)
|
||||
assert.Equal(t, int32(1), queryRes.ActiveVersion)
|
||||
assert.Equal(t, int32(1), queryRes.LatestVersion)
|
||||
assert.Equal(t, "", *queryRes.Config)
|
||||
assert.Equal(t, []string(nil), queryRes.RequiredQueries)
|
||||
|
||||
res, err := client.Update(ctx, &serviceinterfaces.QueryUpdate{
|
||||
Id: id,
|
||||
Config: nil,
|
||||
ActiveVersion: nil,
|
||||
RequiredQueries: []string{},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, res)
|
||||
|
||||
queryRes, err = client.Get(ctx, &serviceinterfaces.IdMessage{
|
||||
Id: id,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, id, queryRes.Id)
|
||||
assert.Equal(t, serviceinterfaces.QueryType_QUERY_TYPE_CONTEXT_FULL, queryRes.Type)
|
||||
assert.Equal(t, int32(1), queryRes.ActiveVersion)
|
||||
assert.Equal(t, int32(1), queryRes.LatestVersion)
|
||||
assert.Equal(t, "", *queryRes.Config)
|
||||
assert.Equal(t, []string(nil), queryRes.RequiredQueries)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
serviceinterfaces "queryorchestration/api/serviceInterfaces"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestQueryServiceTest(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := test.CreateAPIWithDependencies(t, ctx, "queryService")
|
||||
defer cleanup()
|
||||
|
||||
client := serviceinterfaces.NewQueryServiceClient(conn)
|
||||
|
||||
idRes, err := client.Create(ctx, &serviceinterfaces.QueryCreate{
|
||||
Type: serviceinterfaces.QueryType_QUERY_TYPE_CONTEXT_FULL,
|
||||
Config: nil,
|
||||
RequiredQueries: []string{},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
id := idRes.GetId()
|
||||
assert.NotEmpty(t, id)
|
||||
|
||||
docId := uuid.New()
|
||||
|
||||
testRes, err := client.Test(ctx, &serviceinterfaces.QueryTestRequest{
|
||||
QueryId: id,
|
||||
DocumentId: docId.String(),
|
||||
QueryVersion: int32(1),
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, testRes)
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
serviceinterfaces "queryorchestration/api/serviceInterfaces"
|
||||
"queryorchestration/internal/test"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestQueryService(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := test.CreateAPIWithDependencies(t, ctx, "queryService")
|
||||
defer cleanup()
|
||||
|
||||
client := serviceinterfaces.NewQueryServiceClient(conn)
|
||||
|
||||
config := ""
|
||||
reqQueries := []string{}
|
||||
idRes, err := client.Create(ctx, &serviceinterfaces.QueryCreate{
|
||||
Type: 1,
|
||||
Config: &config,
|
||||
RequiredQueries: reqQueries,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
id := idRes.GetId()
|
||||
assert.NotEmpty(t, id)
|
||||
|
||||
// queryRes, err := client.Get(ctx, &serviceinterfaces.IdMessage{
|
||||
// Id: id,
|
||||
// })
|
||||
// log.Print(err)
|
||||
// assert.Nil(t, err)
|
||||
// assert.EqualExportedValues(t, serviceinterfaces.Query{
|
||||
// Id: id,
|
||||
// Type: serviceinterfaces.QueryType_QUERY_TYPE_CONTEXT_FULL,
|
||||
// ActiveVersion: int32(1),
|
||||
// LatestVersion: int32(1),
|
||||
// Config: &config,
|
||||
// RequiredQueries: reqQueries,
|
||||
// }, *queryRes)
|
||||
|
||||
//QueryService - List, Update, Test
|
||||
//JobController - Create, Update, Get
|
||||
//Export - Trigger
|
||||
}
|
||||
Reference in New Issue
Block a user