synctest
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
with-expecter: true
|
||||
packages:
|
||||
gotemplate/internal:
|
||||
queryorchestration/internal:
|
||||
config:
|
||||
recursive: true
|
||||
all: true
|
||||
|
||||
+1
-1
@@ -13,6 +13,6 @@ includes:
|
||||
PROJECT_MAIN: cmd/grpc/main.go
|
||||
PROTOBUF_DIR: api/serviceInterfaces/queryOrchestration
|
||||
API_GRPC_DIR: api/grpc
|
||||
IMAGE_NAME: gotemplate
|
||||
IMAGE_NAME: queryorchestration
|
||||
DOCKERFILE_DIR: build/package
|
||||
COMPOSE_FILE: deployments/compose.yaml
|
||||
|
||||
@@ -2,8 +2,8 @@ package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/api/grpc/spec"
|
||||
"gotemplate/internal/export"
|
||||
"queryorchestration/api/grpc/spec"
|
||||
"queryorchestration/internal/export"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
@@ -2,8 +2,8 @@ package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/api/grpc/spec"
|
||||
"gotemplate/internal/collector"
|
||||
"queryorchestration/api/grpc/spec"
|
||||
"queryorchestration/internal/collector"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/api/grpc/spec"
|
||||
"gotemplate/internal/query"
|
||||
"queryorchestration/api/grpc/spec"
|
||||
"queryorchestration/internal/query"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package queue
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"gotemplate/internal/document"
|
||||
"gotemplate/internal/queue"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/queue"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
|
||||
|
||||
+1
-1
@@ -2,8 +2,8 @@ package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/queue"
|
||||
"log"
|
||||
"queryorchestration/internal/queue"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
)
|
||||
|
||||
+8
-8
@@ -2,16 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/api/grpc/controllers"
|
||||
"gotemplate/api/grpc/spec"
|
||||
"gotemplate/internal/collector"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/export"
|
||||
"gotemplate/internal/otel"
|
||||
"gotemplate/internal/query"
|
||||
"log"
|
||||
"net"
|
||||
"queryorchestration/api/grpc/controllers"
|
||||
"queryorchestration/api/grpc/spec"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/export"
|
||||
"queryorchestration/internal/otel"
|
||||
"queryorchestration/internal/query"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
|
||||
+7
-7
@@ -2,14 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/api/queue"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/document"
|
||||
"gotemplate/internal/env"
|
||||
"gotemplate/internal/otel"
|
||||
queueSVC "gotemplate/internal/queue"
|
||||
"log"
|
||||
"queryorchestration/api/queue"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/env"
|
||||
"queryorchestration/internal/otel"
|
||||
queueSVC "queryorchestration/internal/queue"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
|
||||
@@ -1 +1 @@
|
||||
CREATE TYPE queryType AS ENUM ('json_extractor');
|
||||
CREATE TYPE queryType AS ENUM ('context_full', 'json_extractor');
|
||||
@@ -2,8 +2,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package collector
|
||||
|
||||
import "gotemplate/internal/database/repository"
|
||||
import "queryorchestration/internal/database/repository"
|
||||
|
||||
type Service struct {
|
||||
db *repository.Queries
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package contextfull
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Result struct {
|
||||
value string
|
||||
}
|
||||
|
||||
func NewResult(value string) *Result {
|
||||
return &Result{value}
|
||||
}
|
||||
|
||||
func (r *Result) GetValue(ctx context.Context) (string, error) {
|
||||
// TODO - get value from s3
|
||||
return r.value, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package contextfull
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
)
|
||||
|
||||
type Extractor struct {
|
||||
}
|
||||
|
||||
func New() *Extractor {
|
||||
return &Extractor{}
|
||||
}
|
||||
|
||||
func (e *Extractor) Process(ctx context.Context, query query.Query, values *[]result.Value) (string, error) {
|
||||
if len(*values) > 0 {
|
||||
return "", fmt.Errorf("no requirements expected")
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package database
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gotemplate/internal/env"
|
||||
"log"
|
||||
"queryorchestration/internal/env"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
@@ -3,10 +3,10 @@ package database
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"gotemplate/internal/env"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"queryorchestration/internal/env"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
"github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
type Querytype string
|
||||
|
||||
const (
|
||||
QuerytypeContextFull Querytype = "context_full"
|
||||
QuerytypeJsonExtractor Querytype = "json_extractor"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/collector"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/queryQueue"
|
||||
"gotemplate/internal/result"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/queryQueue"
|
||||
"queryorchestration/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package export
|
||||
|
||||
import "gotemplate/internal/database/repository"
|
||||
import "queryorchestration/internal/database/repository"
|
||||
|
||||
type Service struct {
|
||||
db *repository.Queries
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package jsonextractor
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Result struct {
|
||||
value string
|
||||
}
|
||||
|
||||
func NewResult(value string) *Result {
|
||||
return &Result{value}
|
||||
}
|
||||
|
||||
func (r *Result) GetValue(ctx context.Context) (string, error) {
|
||||
return r.value, nil
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
@@ -29,7 +29,10 @@ func (e *Extractor) Process(ctx context.Context, query query.Query, values *[]re
|
||||
return "", fmt.Errorf("JSON Extraction requires 1 result")
|
||||
}
|
||||
|
||||
value := (*values)[0].Value
|
||||
value, err := (*values)[0].GetValue(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
byteConfig, err := e.db.GetQueryConfig(ctx, repository.GetQueryConfigParams{
|
||||
Queryid: database.MustToDBUUID(query.ID),
|
||||
|
||||
@@ -2,8 +2,8 @@ package query
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
)
|
||||
|
||||
func ParseDBQuery(dbQuery *repository.GetCollectorQueriesRow) (*Query, error) {
|
||||
@@ -28,6 +28,8 @@ func ParseDBType(qType repository.NullQuerytype) (Type, error) {
|
||||
switch qType.Querytype {
|
||||
case repository.QuerytypeJsonExtractor:
|
||||
return TypeJsonExtractor, nil
|
||||
case repository.QuerytypeContextFull:
|
||||
return TypeContextFull, nil
|
||||
default:
|
||||
return TypeJsonExtractor, fmt.Errorf("invalid database query type")
|
||||
}
|
||||
@@ -39,6 +41,8 @@ func ToDBQueryType(t Type) (repository.NullQuerytype, error) {
|
||||
switch t {
|
||||
case TypeJsonExtractor:
|
||||
dbType = repository.QuerytypeJsonExtractor
|
||||
case TypeContextFull:
|
||||
dbType = repository.QuerytypeContextFull
|
||||
default:
|
||||
return repository.NullQuerytype{}, fmt.Errorf("invalid database query type")
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/result"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -12,6 +12,7 @@ type Type int
|
||||
|
||||
const (
|
||||
TypeJsonExtractor = iota
|
||||
TypeContextFull
|
||||
)
|
||||
|
||||
type Query struct {
|
||||
|
||||
@@ -2,8 +2,8 @@ package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/query"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/query"
|
||||
)
|
||||
|
||||
func (q *Queue) getUnsyncedQueries() {
|
||||
@@ -75,7 +75,7 @@ func (q *Queue) Add(qu *query.Query) {
|
||||
}
|
||||
|
||||
if requiredIndex != -1 {
|
||||
*q.unsyncedQueue = append((*q.unsyncedQueue)[:requiredIndex], append([]query.Query{*qu}, (*q.unsyncedQueue)[requiredIndex:]...)...)
|
||||
*q.unsyncedQueue = append((*q.unsyncedQueue)[:requiredIndex+1], append([]query.Query{*qu}, (*q.unsyncedQueue)[requiredIndex+1:]...)...)
|
||||
} else {
|
||||
*q.unsyncedQueue = append([]query.Query{*qu}, *q.unsyncedQueue...)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,13 @@ package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
"fmt"
|
||||
contextfull "queryorchestration/internal/contextFull"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
jsonextractor "queryorchestration/internal/jsonExtractor"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
@@ -59,9 +63,13 @@ func (q *Queue) executeQuery(ctx context.Context, qu query.Query) error {
|
||||
}
|
||||
|
||||
cleanValues := make([]result.Value, len(values))
|
||||
for _, r := range values {
|
||||
cleanValue := result.ParseValue(&r)
|
||||
cleanValues = append(cleanValues, *cleanValue)
|
||||
for index, r := range values {
|
||||
cleanValue, err := q.getResultValue(&r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cleanValues[index] = cleanValue
|
||||
}
|
||||
|
||||
err = q.setResult(ctx, qu, &cleanValues)
|
||||
@@ -71,3 +79,21 @@ func (q *Queue) executeQuery(ctx context.Context, qu query.Query) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *Queue) getResultValue(res *repository.ListResultValuesByIDRow) (result.Value, error) {
|
||||
var queryType query.Type
|
||||
for _, qu := range *q.collectorQueries {
|
||||
if qu.ID == database.MustToUUID(res.Queryid) {
|
||||
queryType = qu.Type
|
||||
}
|
||||
}
|
||||
|
||||
switch queryType {
|
||||
case query.TypeJsonExtractor:
|
||||
return jsonextractor.NewResult(res.Value), nil
|
||||
case query.TypeContextFull:
|
||||
return contextfull.NewResult(res.Value), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("attempting to process invalid query type")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ package queryQueue
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
jsonextractor "gotemplate/internal/jsonExtractor"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
contextfull "queryorchestration/internal/contextFull"
|
||||
jsonextractor "queryorchestration/internal/jsonExtractor"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
)
|
||||
|
||||
func (q *Queue) setResult(ctx context.Context, qu query.Query, resultValues *[]result.Value) error {
|
||||
@@ -44,6 +45,8 @@ func (q *Queue) getProcessor(queryType query.Type) (query.Processor, error) {
|
||||
switch queryType {
|
||||
case query.TypeJsonExtractor:
|
||||
return jsonextractor.New(q.db), nil
|
||||
case query.TypeContextFull:
|
||||
return contextfull.New(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("attempting to process invalid query type")
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/collector"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
package result
|
||||
|
||||
import (
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
)
|
||||
|
||||
func ParseValue(result *repository.ListResultValuesByIDRow) *Value {
|
||||
return &Value{
|
||||
ID: database.MustToUUID(result.ID),
|
||||
QueryID: database.MustToUUID(result.Queryid),
|
||||
Value: result.Value,
|
||||
}
|
||||
}
|
||||
|
||||
func Parse(dbQuery *repository.ListResultsByDocumentIDRow) *Result {
|
||||
return &Result{
|
||||
ID: database.MustToUUID(dbQuery.ID),
|
||||
|
||||
@@ -2,8 +2,8 @@ package result
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -14,10 +14,8 @@ type Result struct {
|
||||
QueryVersion int32
|
||||
}
|
||||
|
||||
type Value struct {
|
||||
ID uuid.UUID
|
||||
QueryID uuid.UUID
|
||||
Value string
|
||||
type Value interface {
|
||||
GetValue(ctx context.Context) (string, error)
|
||||
}
|
||||
|
||||
type ResultStore struct {
|
||||
|
||||
@@ -26,7 +26,7 @@ func createContainer(t *testing.T, ctx context.Context, config *containerConfig)
|
||||
}
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: "gotemplate_grpc:latest",
|
||||
Image: "queryorchestration_grpc:latest",
|
||||
Env: map[string]string{
|
||||
"DB_USER": config.DB.User,
|
||||
"DB_PASS": config.DB.Password,
|
||||
@@ -85,7 +85,7 @@ func createDB(t *testing.T, ctx context.Context, network *testcontainers.DockerN
|
||||
}
|
||||
|
||||
config := dbConfig{
|
||||
Name: "gotemplate",
|
||||
Name: "queryorchestration",
|
||||
Password: "pass",
|
||||
User: "postgres",
|
||||
Port: port.Int(),
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gotemplate/api/grpc/spec"
|
||||
"queryorchestration/api/grpc/spec"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -32,7 +32,7 @@ func createContainer(t *testing.T, ctx context.Context, config containerConfig)
|
||||
}
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: "gotemplate_queue:latest",
|
||||
Image: "queryorchestration_queue:latest",
|
||||
Env: map[string]string{
|
||||
"QUEUE_URL": config.Queue.URL,
|
||||
"AWS_DEFAULT_REGION": config.Queue.Region,
|
||||
@@ -178,7 +178,7 @@ func createDB(t *testing.T, ctx context.Context, network *testcontainers.DockerN
|
||||
}
|
||||
|
||||
config := dbConfig{
|
||||
Name: "gotemplate",
|
||||
Name: "queryorchestration",
|
||||
Password: "pass",
|
||||
User: "postgres",
|
||||
Port: port.Int(),
|
||||
|
||||
@@ -3,7 +3,7 @@ package queue_test
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"gotemplate/internal/document"
|
||||
"queryorchestration/internal/document"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
@@ -2,9 +2,9 @@ package document_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/collector"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package document_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
contextfull "queryorchestration/internal/contextFull"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestContextFull(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
extractor := contextfull.New()
|
||||
|
||||
query := query.Query{
|
||||
ID: uuid.New(),
|
||||
Type: query.TypeJsonExtractor,
|
||||
RequiredQueryID: uuid.Nil,
|
||||
Version: int32(1),
|
||||
}
|
||||
|
||||
values := &[]result.Value{}
|
||||
|
||||
value, err := extractor.Process(ctx, query, values)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "", value)
|
||||
|
||||
values = &[]result.Value{
|
||||
contextfull.NewResult("example_result"),
|
||||
}
|
||||
|
||||
_, err = extractor.Process(ctx, query, values)
|
||||
assert.EqualError(t, err, "no requirements expected")
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package database_test
|
||||
|
||||
import (
|
||||
"gotemplate/internal/database"
|
||||
"queryorchestration/internal/database"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
@@ -2,9 +2,9 @@ package document_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/document"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
Vendored
+1
-1
@@ -1,8 +1,8 @@
|
||||
package env_test
|
||||
|
||||
import (
|
||||
"gotemplate/internal/env"
|
||||
"os"
|
||||
"queryorchestration/internal/env"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
package env_test
|
||||
|
||||
import (
|
||||
"gotemplate/internal/env"
|
||||
"os"
|
||||
"queryorchestration/internal/env"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
@@ -3,11 +3,12 @@ package document_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
jsonextractor "gotemplate/internal/jsonExtractor"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
contextfull "queryorchestration/internal/contextFull"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
jsonextractor "queryorchestration/internal/jsonExtractor"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -39,7 +40,7 @@ func TestJSONProcess(t *testing.T) {
|
||||
|
||||
jsonString := fmt.Sprintf("{\"key\": \"%s\"}", entryValue)
|
||||
values := &[]result.Value{
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: jsonString},
|
||||
contextfull.NewResult(jsonString),
|
||||
}
|
||||
|
||||
config := "{\"path\":\"key\"}"
|
||||
@@ -57,7 +58,7 @@ func TestJSONProcess(t *testing.T) {
|
||||
entryValue = ""
|
||||
jsonString = fmt.Sprintf("{\"key\": \"%s\"}", entryValue)
|
||||
values = &[]result.Value{
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: jsonString},
|
||||
contextfull.NewResult(jsonString),
|
||||
}
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
@@ -72,7 +73,7 @@ func TestJSONProcess(t *testing.T) {
|
||||
entryValue = "1"
|
||||
jsonString = fmt.Sprintf("{\"key\": %s", entryValue)
|
||||
values = &[]result.Value{
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: jsonString},
|
||||
contextfull.NewResult(jsonString),
|
||||
}
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
@@ -108,7 +109,7 @@ func TestJSONProcessJSON(t *testing.T) {
|
||||
|
||||
jsonString := fmt.Sprintf("{\"key\": \"%s\"}", entryValue)
|
||||
values := &[]result.Value{
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: jsonString},
|
||||
contextfull.NewResult(jsonString),
|
||||
}
|
||||
|
||||
config := "{\"path\":\"invalid_key\"}"
|
||||
@@ -185,17 +186,17 @@ func TestJSONProcessResults(t *testing.T) {
|
||||
assert.Empty(t, value)
|
||||
|
||||
results = &[]result.Value{
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
contextfull.NewResult(""),
|
||||
contextfull.NewResult(""),
|
||||
}
|
||||
value, err = extractor.Process(ctx, query, results)
|
||||
assert.EqualError(t, err, "JSON Extraction requires 1 result")
|
||||
assert.Empty(t, value)
|
||||
|
||||
results = &[]result.Value{
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
contextfull.NewResult(""),
|
||||
contextfull.NewResult(""),
|
||||
contextfull.NewResult(""),
|
||||
}
|
||||
value, err = extractor.Process(ctx, query, results)
|
||||
assert.EqualError(t, err, "JSON Extraction requires 1 result")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package document_test
|
||||
|
||||
import (
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -43,6 +43,11 @@ func TestParseDBType(t *testing.T) {
|
||||
qType = repository.NullQuerytype{Valid: true}
|
||||
_, err = query.ParseDBType(qType)
|
||||
assert.EqualError(t, err, "invalid database query type")
|
||||
|
||||
qType = repository.NullQuerytype{Valid: true, Querytype: repository.QuerytypeContextFull}
|
||||
value, err = query.ParseDBType(qType)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, query.Type(query.TypeContextFull), value)
|
||||
}
|
||||
|
||||
func TestToDBQueryType(t *testing.T) {
|
||||
@@ -54,4 +59,9 @@ func TestToDBQueryType(t *testing.T) {
|
||||
dbQueryType = query.Type(-1)
|
||||
_, err = query.ToDBQueryType(dbQueryType)
|
||||
assert.EqualError(t, err, "invalid database query type")
|
||||
|
||||
dbQueryType = query.Type(query.TypeContextFull)
|
||||
value, err = query.ToDBQueryType(dbQueryType)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, repository.NullQuerytype{Querytype: repository.QuerytypeContextFull, Valid: true}, value)
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package document_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
|
||||
@@ -2,12 +2,13 @@ package document_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/collector"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/queryQueue"
|
||||
"gotemplate/internal/result"
|
||||
"fmt"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/queryQueue"
|
||||
"queryorchestration/internal/result"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -52,14 +53,16 @@ func TestQueue(t *testing.T) {
|
||||
queryFiveVersion := int32(5)
|
||||
querySixID := uuid.New()
|
||||
querySixVersion := int32(6)
|
||||
contextID := uuid.New()
|
||||
contextVersion := int32(1)
|
||||
collectorQueries := []query.Query{
|
||||
{ID: queryOneID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryOneVersion},
|
||||
{ID: contextID, Type: query.TypeContextFull, RequiredQueryID: uuid.Nil, Version: contextVersion},
|
||||
{ID: queryOneID, Type: query.TypeJsonExtractor, RequiredQueryID: contextID, Version: queryOneVersion},
|
||||
{ID: queryTwoID, Type: query.TypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryTwoVersion},
|
||||
{ID: queryThreeID, Type: query.TypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryThreeVersion},
|
||||
{ID: queryThreeID, Type: query.TypeJsonExtractor, RequiredQueryID: queryTwoID, Version: queryThreeVersion},
|
||||
{ID: queryFourID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryFourVersion},
|
||||
{ID: queryFourID, Type: query.TypeJsonExtractor, RequiredQueryID: contextID, Version: queryFourVersion},
|
||||
{ID: queryFiveID, Type: query.TypeJsonExtractor, RequiredQueryID: querySixID, Version: queryFiveVersion},
|
||||
{ID: querySixID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: querySixVersion},
|
||||
{ID: querySixID, Type: query.TypeJsonExtractor, RequiredQueryID: contextID, Version: querySixVersion},
|
||||
}
|
||||
|
||||
rows := pgxmock.NewRows([]string{"collectorId", "queryId", "type", "requiredQueryId", "queryVersion"})
|
||||
@@ -74,18 +77,20 @@ func TestQueue(t *testing.T) {
|
||||
|
||||
db.ExpectQuery("name: GetCollectorQueries :many").WithArgs(dbCollectorID).WillReturnRows(rows)
|
||||
|
||||
contextResultID := uuid.New()
|
||||
results := []result.Result{
|
||||
{ID: contextResultID, QueryID: contextID, QueryVersion: contextVersion},
|
||||
{ID: uuid.New(), QueryID: queryFourID, QueryVersion: queryFourVersion},
|
||||
{ID: uuid.New(), QueryID: querySixID, QueryVersion: querySixVersion - 1},
|
||||
{ID: uuid.New(), QueryID: queryOneID, QueryVersion: queryOneVersion - 1},
|
||||
}
|
||||
|
||||
expectedQueries := []query.Query{
|
||||
{ID: querySixID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: querySixVersion},
|
||||
{ID: querySixID, Type: query.TypeJsonExtractor, RequiredQueryID: contextID, Version: querySixVersion},
|
||||
{ID: queryFiveID, Type: query.TypeJsonExtractor, RequiredQueryID: querySixID, Version: queryFiveVersion},
|
||||
{ID: queryThreeID, Type: query.TypeJsonExtractor, RequiredQueryID: queryTwoID, Version: queryThreeVersion},
|
||||
{ID: queryOneID, Type: query.TypeJsonExtractor, RequiredQueryID: contextID, Version: queryOneVersion},
|
||||
{ID: queryThreeID, Type: query.TypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryThreeVersion},
|
||||
{ID: queryTwoID, Type: query.TypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryTwoVersion},
|
||||
{ID: queryOneID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryOneVersion},
|
||||
}
|
||||
|
||||
docID := uuid.New()
|
||||
@@ -96,22 +101,67 @@ func TestQueue(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedQueries, q.GetQueue())
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs([]pgtype.UUID{}).WillReturnRows(rows)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(querySixID), database.MustToDBUUID(docID), pgxmock.AnyArg(), cleanVersion, textVersion, querySixVersion).
|
||||
keyLayerOne := "key"
|
||||
keyLayerTwo := "key5"
|
||||
valueLayerTwo := "value"
|
||||
valueLayerOne := fmt.Sprintf("{\"%s\":\"%s\"}", keyLayerTwo, valueLayerTwo)
|
||||
valueContext := fmt.Sprintf("{\"%s\":%s}", keyLayerOne, valueLayerOne)
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs([]pgtype.UUID{database.MustToDBUUID(contextResultID)}).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
AddRow(database.MustToDBUUID(contextResultID), database.MustToDBUUID(contextID), valueContext),
|
||||
)
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(querySixID), querySixVersion).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(fmt.Sprintf("{\"path\":\"%s\"}", keyLayerOne))),
|
||||
)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(querySixID), database.MustToDBUUID(docID), valueLayerOne, cleanVersion, textVersion, querySixVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(rows)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(queryFiveID), database.MustToDBUUID(docID), pgxmock.AnyArg(), cleanVersion, textVersion, queryFiveVersion).
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
AddRow(pgtype.UUID{}, database.MustToDBUUID(querySixID), valueLayerOne),
|
||||
)
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryFiveID), queryFiveVersion).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(fmt.Sprintf("{\"path\":\"%s\"}", keyLayerTwo))),
|
||||
)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(queryFiveID), database.MustToDBUUID(docID), valueLayerTwo, cleanVersion, textVersion, queryFiveVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(rows)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(queryThreeID), database.MustToDBUUID(docID), pgxmock.AnyArg(), cleanVersion, textVersion, queryThreeVersion).
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
AddRow(database.MustToDBUUID(contextResultID), database.MustToDBUUID(contextID), valueContext),
|
||||
)
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryOneID), queryOneVersion).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(fmt.Sprintf("{\"path\":\"%s\"}", keyLayerOne))),
|
||||
)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(queryOneID), database.MustToDBUUID(docID), valueLayerOne, cleanVersion, textVersion, queryOneVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(rows)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(queryTwoID), database.MustToDBUUID(docID), pgxmock.AnyArg(), cleanVersion, textVersion, queryTwoVersion).
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
AddRow(pgtype.UUID{}, database.MustToDBUUID(queryOneID), valueLayerOne),
|
||||
)
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryThreeID), queryThreeVersion).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(fmt.Sprintf("{\"path\":\"%s\"}", keyLayerTwo))),
|
||||
)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(queryThreeID), database.MustToDBUUID(docID), valueLayerTwo, cleanVersion, textVersion, queryThreeVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(rows)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(queryOneID), database.MustToDBUUID(docID), pgxmock.AnyArg(), cleanVersion, textVersion, queryOneVersion).
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
AddRow(pgtype.UUID{}, database.MustToDBUUID(queryOneID), valueLayerOne),
|
||||
)
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryTwoID), queryTwoVersion).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(fmt.Sprintf("{\"path\":\"%s\"}", keyLayerTwo))),
|
||||
)
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(queryTwoID), database.MustToDBUUID(docID), valueLayerTwo, cleanVersion, textVersion, queryTwoVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
|
||||
err = q.Execute(ctx)
|
||||
assert.EqualError(t, err, "JSON Extraction requires 1 result")
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package document_test
|
||||
|
||||
import (
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/result"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/result"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -10,19 +10,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseValue(t *testing.T) {
|
||||
dbResult := repository.ListResultValuesByIDRow{
|
||||
ID: pgtype.UUID{},
|
||||
Queryid: pgtype.UUID{},
|
||||
Value: "",
|
||||
}
|
||||
|
||||
value := result.ParseValue(&dbResult)
|
||||
assert.Equal(t, dbResult.Value, value.Value)
|
||||
assert.Equal(t, uuid.Nil, value.ID)
|
||||
assert.Equal(t, uuid.Nil, value.QueryID)
|
||||
}
|
||||
|
||||
func TestParseResultValue(t *testing.T) {
|
||||
dbResult := repository.ListResultsByDocumentIDRow{
|
||||
ID: pgtype.UUID{},
|
||||
|
||||
@@ -3,9 +3,9 @@ package document_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/result"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/result"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
Reference in New Issue
Block a user