Merged in bugfix/querytest (pull request #147)
Pass Test Query * passfullsutie
This commit is contained in:
@@ -152,18 +152,27 @@ func TestUpdateQuery(t *testing.T) {
|
|||||||
assert.Empty(t, rec.Body.String())
|
assert.Empty(t, rec.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QueryUpdateConfig struct {
|
||||||
|
serviceconfig.BaseConfig
|
||||||
|
queryversionsync.QueryVersionSyncConfig
|
||||||
|
}
|
||||||
|
|
||||||
func TestTestQuery(t *testing.T) {
|
func TestTestQuery(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
cfg := &serviceconfig.BaseConfig{}
|
cfg := &QueryUpdateConfig{}
|
||||||
net := test.GetNetwork(t)
|
net := test.GetNetwork(t)
|
||||||
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
||||||
|
|
||||||
docsvc := document.New(cfg)
|
docsvc := document.New(cfg)
|
||||||
col := collector.New(cfg)
|
col := collector.New(cfg)
|
||||||
que := query.New(cfg)
|
que := query.New(cfg)
|
||||||
|
queup := queryupdate.New(cfg, &queryupdate.Services{
|
||||||
|
Query: que,
|
||||||
|
})
|
||||||
cons := queryapi.NewControllers(&queryapi.Services{
|
cons := queryapi.NewControllers(&queryapi.Services{
|
||||||
Collector: col,
|
Collector: col,
|
||||||
Query: que,
|
Query: que,
|
||||||
|
QueryUpdate: queup,
|
||||||
QueryTest: querytest.New(cfg, &querytest.Services{
|
QueryTest: querytest.New(cfg, &querytest.Services{
|
||||||
Document: docsvc,
|
Document: docsvc,
|
||||||
Collector: col,
|
Collector: col,
|
||||||
@@ -239,6 +248,12 @@ func TestTestQuery(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
c = `{"path": "mykey"}`
|
||||||
|
err = queup.Update(t.Context(), &resultprocessor.Update{
|
||||||
|
ID: queryId,
|
||||||
|
Config: &c,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
body := queryapi.QueryTestRequest{
|
body := queryapi.QueryTestRequest{
|
||||||
DocumentId: docId,
|
DocumentId: docId,
|
||||||
@@ -252,4 +267,17 @@ func TestTestQuery(t *testing.T) {
|
|||||||
assertBody(t, rec, queryapi.QueryTestResponse{
|
assertBody(t, rec, queryapi.QueryTestResponse{
|
||||||
Value: "old_value",
|
Value: "old_value",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
body = queryapi.QueryTestRequest{
|
||||||
|
DocumentId: docId,
|
||||||
|
QueryVersion: 2,
|
||||||
|
}
|
||||||
|
ctx, rec = createContextWithBody(t, body)
|
||||||
|
|
||||||
|
err = cons.TestQuery(ctx, queryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusOK, rec.Code)
|
||||||
|
assertBody(t, rec, queryapi.QueryTestResponse{
|
||||||
|
Value: "example_value",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,10 +91,6 @@ func TestQueryRunner(t *testing.T) {
|
|||||||
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
||||||
AddRow(&requiredResultId, (*query.RequiredQueryIDs)[0], repository.QuerytypeContextFull, &strVal),
|
AddRow(&requiredResultId, (*query.RequiredQueryIDs)[0], repository.QuerytypeContextFull, &strVal),
|
||||||
)
|
)
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}).
|
|
||||||
AddRow([]byte(qcfg)),
|
|
||||||
)
|
|
||||||
pool.ExpectBegin()
|
pool.ExpectBegin()
|
||||||
resultId := uuid.New()
|
resultId := uuid.New()
|
||||||
pool.ExpectQuery("name: AddResult :one").WithArgs(query.ID, pgxmock.AnyArg(), textEntryId, query.Version).
|
pool.ExpectQuery("name: AddResult :one").WithArgs(query.ID, pgxmock.AnyArg(), textEntryId, query.Version).
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ definitions:
|
|||||||
- touch .env
|
- touch .env
|
||||||
|
|
||||||
- devbox install
|
- devbox install
|
||||||
- devbox run -- task build
|
|
||||||
- devbox run -- task fullsuite
|
- devbox run -- task fullsuite
|
||||||
|
|
||||||
pipelines:
|
pipelines:
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ func (s *Service) normalizeCreate(params *CreateParams) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the char ~ never makes way in as a valid client id character
|
||||||
|
// Reference bucket key filename
|
||||||
const CLIENT_ID_REGEX = `[a-zA-Z0-9\_#-]+`
|
const CLIENT_ID_REGEX = `[a-zA-Z0-9\_#-]+`
|
||||||
|
|
||||||
func normalizeID(id *string) error {
|
func normalizeID(id *string) error {
|
||||||
|
|||||||
+120
-24
@@ -3,13 +3,16 @@ package query_test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
"queryorchestration/internal/query"
|
"queryorchestration/internal/query"
|
||||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
"queryorchestration/internal/test"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
"github.com/pashagolub/pgxmock/v3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -51,38 +54,131 @@ func TestGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetWithVersion(t *testing.T) {
|
func TestGetWithVersion(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
cfg := &serviceconfig.BaseConfig{}
|
||||||
|
net := test.GetNetwork(t)
|
||||||
|
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
||||||
|
|
||||||
|
err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
|
||||||
|
Clientid: "client_id",
|
||||||
|
Name: "client_name",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
docId, err := cfg.GetDBQueries().CreateDocument(t.Context(), &repository.CreateDocumentParams{
|
||||||
|
Clientid: "client_id",
|
||||||
|
Hash: "hash",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
fill := "fill"
|
||||||
|
cleanId, err := cfg.GetDBQueries().AddDocumentClean(t.Context(), &repository.AddDocumentCleanParams{
|
||||||
|
Documentid: docId,
|
||||||
|
Bucket: &fill,
|
||||||
|
Key: &fill,
|
||||||
|
Hash: &fill,
|
||||||
|
Mimetype: repository.NullCleanmimetype{
|
||||||
|
Valid: true,
|
||||||
|
Cleanmimetype: repository.CleanmimetypeApplicationPdf,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddDocumentCleanEntry(t.Context(), &repository.AddDocumentCleanEntryParams{
|
||||||
|
Cleanid: cleanId,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
textId, err := cfg.GetDBQueries().AddDocumentText(t.Context(), &repository.AddDocumentTextParams{
|
||||||
|
Cleanid: cleanId,
|
||||||
|
Bucket: fill,
|
||||||
|
Key: fill,
|
||||||
|
Hash: fill,
|
||||||
|
Createdat: pgtype.Timestamp{
|
||||||
|
Time: time.Now(),
|
||||||
|
Valid: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddDocumentTextEntry(t.Context(), &repository.AddDocumentTextEntryParams{
|
||||||
|
Textid: textId,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
contextQueryId, err := cfg.GetDBQueries().CreateQuery(t.Context(), repository.QuerytypeContextFull)
|
||||||
|
require.NoError(t, err)
|
||||||
|
contextVersion, err := cfg.GetDBQueries().AddLatestQueryVersion(t.Context(), contextQueryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddActiveQueryVersion(t.Context(), &repository.AddActiveQueryVersionParams{
|
||||||
|
Queryid: contextQueryId,
|
||||||
|
Versionid: contextVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
queryId, err := cfg.GetDBQueries().CreateQuery(t.Context(), repository.QuerytypeJsonExtractor)
|
||||||
|
require.NoError(t, err)
|
||||||
|
latestVersion, err := cfg.GetDBQueries().AddLatestQueryVersion(t.Context(), queryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddActiveQueryVersion(t.Context(), &repository.AddActiveQueryVersionParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Versionid: latestVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddRequiredQuery(t.Context(), &repository.AddRequiredQueryParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Requiredqueryid: contextQueryId,
|
||||||
|
Addedversion: latestVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
c := `{"path":"oldkey"}`
|
||||||
|
err = cfg.GetDBQueries().SetQueryConfig(t.Context(), &repository.SetQueryConfigParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Config: []byte(c),
|
||||||
|
Addedversion: latestVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
strVal := `{"mykey": "example_value", "oldkey": "old_value"}`
|
||||||
|
_, err = cfg.GetDBQueries().AddResult(t.Context(), &repository.AddResultParams{
|
||||||
|
Queryid: contextQueryId,
|
||||||
|
Value: strVal,
|
||||||
|
Textentryid: textId,
|
||||||
|
Queryversion: contextVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
latestVersion, err = cfg.GetDBQueries().AddLatestQueryVersion(t.Context(), queryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
c = `{"path":"mykey"}`
|
||||||
|
err = cfg.GetDBQueries().SetQueryConfig(t.Context(), &repository.SetQueryConfigParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Config: []byte(c),
|
||||||
|
Addedversion: latestVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
|
||||||
require.NoError(t, err)
|
|
||||||
cfg := &serviceconfig.BaseConfig{}
|
|
||||||
cfg.DBPool = pool
|
|
||||||
cfg.DBQueries = repository.New(pool)
|
|
||||||
svc := query.New(cfg)
|
svc := query.New(cfg)
|
||||||
|
|
||||||
config := "{\"path\":\"example_path\"}"
|
returnQuery, err := svc.GetWithVersion(ctx, queryId, 1)
|
||||||
query := query.Query{
|
require.NoError(t, err)
|
||||||
ID: uuid.New(),
|
config := `{"path": "oldkey"}`
|
||||||
|
assert.EqualExportedValues(t, query.Query{
|
||||||
|
ID: queryId,
|
||||||
Type: resultprocessor.TypeJsonExtractor,
|
Type: resultprocessor.TypeJsonExtractor,
|
||||||
ActiveVersion: int32(1),
|
ActiveVersion: 1,
|
||||||
LatestVersion: int32(3),
|
LatestVersion: 2,
|
||||||
RequiredQueryIDs: &[]uuid.UUID{
|
RequiredQueryIDs: &[]uuid.UUID{
|
||||||
uuid.New(),
|
contextQueryId,
|
||||||
},
|
},
|
||||||
Config: &config,
|
Config: &config,
|
||||||
}
|
}, *returnQuery)
|
||||||
|
|
||||||
version := int32(2)
|
returnQuery, err = svc.GetWithVersion(ctx, queryId, 2)
|
||||||
|
|
||||||
dbReqIDs := *query.RequiredQueryIDs
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(&query.ID, &version).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
|
||||||
AddRow(query.ID, repository.QuerytypeJsonExtractor, query.ActiveVersion, query.LatestVersion, []byte(config), dbReqIDs),
|
|
||||||
)
|
|
||||||
|
|
||||||
returnQuery, err := svc.GetWithVersion(ctx, query.ID, version)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
config = `{"path": "mykey"}`
|
||||||
assert.EqualExportedValues(t, query, *returnQuery)
|
assert.EqualExportedValues(t, query.Query{
|
||||||
|
ID: queryId,
|
||||||
|
Type: resultprocessor.TypeJsonExtractor,
|
||||||
|
ActiveVersion: 1,
|
||||||
|
LatestVersion: 2,
|
||||||
|
RequiredQueryIDs: &[]uuid.UUID{
|
||||||
|
contextQueryId,
|
||||||
|
},
|
||||||
|
Config: &config,
|
||||||
|
}, *returnQuery)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
package result
|
package result
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
"queryorchestration/internal/serviceconfig/objectstore"
|
||||||
|
"queryorchestration/internal/test"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -29,33 +31,211 @@ func TestGetValueByType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetValueWithVersion(t *testing.T) {
|
func TestGetValueWithVersion(t *testing.T) {
|
||||||
ctx := context.Background()
|
t.Run("no entry", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
cfg := &serviceconfig.BaseConfig{}
|
||||||
|
net := test.GetNetwork(t)
|
||||||
|
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
svc := New(cfg, &Services{})
|
||||||
require.NoError(t, err)
|
|
||||||
cfg := &serviceconfig.BaseConfig{}
|
|
||||||
cfg.DBPool = pool
|
|
||||||
cfg.DBQueries = repository.New(pool)
|
|
||||||
|
|
||||||
svc := New(cfg, &Services{})
|
params := &GetValueWithVersionParams{
|
||||||
|
Type: resultprocessor.TypeJsonExtractor,
|
||||||
|
QueryID: uuid.New(),
|
||||||
|
DocumentID: uuid.New(),
|
||||||
|
QueryVersion: 1,
|
||||||
|
}
|
||||||
|
|
||||||
params := &GetValueWithVersionParams{
|
_, err := svc.GetValueWithVersion(t.Context(), params)
|
||||||
Type: resultprocessor.TypeJsonExtractor,
|
require.EqualError(t, err, "no rows in result set")
|
||||||
QueryID: uuid.New(),
|
})
|
||||||
DocumentID: uuid.New(),
|
t.Run("existing entry", func(t *testing.T) {
|
||||||
QueryVersion: 1,
|
t.Parallel()
|
||||||
}
|
cfg := &serviceconfig.BaseConfig{}
|
||||||
|
net := test.GetNetwork(t)
|
||||||
|
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
||||||
|
|
||||||
value := "exaple_value"
|
svc := New(cfg, &Services{})
|
||||||
pool.ExpectQuery("name: GetResultValueWithVersion :one").WithArgs(¶ms.QueryID, ¶ms.QueryVersion, ¶ms.DocumentID).
|
|
||||||
WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"id", "value"}).
|
|
||||||
AddRow(&uuid.UUID{}, &value),
|
|
||||||
)
|
|
||||||
|
|
||||||
val, err := svc.GetValueWithVersion(ctx, params)
|
err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
|
||||||
require.NoError(t, err)
|
Clientid: "client_id",
|
||||||
v := jsonextractor.NewResult(value)
|
Name: "client_name",
|
||||||
assert.Equal(t, v, val)
|
})
|
||||||
assert.Equal(t, value, v.GetStoreValue())
|
require.NoError(t, err)
|
||||||
|
docId, err := cfg.GetDBQueries().CreateDocument(t.Context(), &repository.CreateDocumentParams{
|
||||||
|
Clientid: "client_id",
|
||||||
|
Hash: "hash",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
filetype := "pdf"
|
||||||
|
part := uint16(1)
|
||||||
|
key := objectstore.BucketKey{
|
||||||
|
CreatedAt: time.Now().UTC(),
|
||||||
|
ClientID: "clientid",
|
||||||
|
EntityID: uuid.New(),
|
||||||
|
Location: objectstore.Import,
|
||||||
|
Part: &part,
|
||||||
|
FileType: &filetype,
|
||||||
|
}
|
||||||
|
err = cfg.GetDBQueries().AddDocumentEntry(t.Context(), &repository.AddDocumentEntryParams{
|
||||||
|
Documentid: docId,
|
||||||
|
Bucket: "bucket",
|
||||||
|
Key: key.String(),
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
bucket := "bucket"
|
||||||
|
hash := "hash"
|
||||||
|
keyStr := key.String()
|
||||||
|
cleanId, err := cfg.GetDBQueries().AddDocumentClean(t.Context(), &repository.AddDocumentCleanParams{
|
||||||
|
Documentid: docId,
|
||||||
|
Bucket: &bucket,
|
||||||
|
Hash: &hash,
|
||||||
|
Key: &keyStr,
|
||||||
|
Mimetype: repository.NullCleanmimetype{
|
||||||
|
Valid: true,
|
||||||
|
Cleanmimetype: repository.CleanmimetypeApplicationPdf,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddDocumentCleanEntry(t.Context(), &repository.AddDocumentCleanEntryParams{
|
||||||
|
Cleanid: cleanId,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
textId, err := cfg.GetDBQueries().AddDocumentText(t.Context(), &repository.AddDocumentTextParams{
|
||||||
|
Cleanid: cleanId,
|
||||||
|
Bucket: bucket,
|
||||||
|
Hash: hash,
|
||||||
|
Key: keyStr,
|
||||||
|
Part: part,
|
||||||
|
Createdat: pgtype.Timestamp{
|
||||||
|
Valid: true,
|
||||||
|
Time: time.Now(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddDocumentTextEntry(t.Context(), &repository.AddDocumentTextEntryParams{
|
||||||
|
Textid: textId,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
queryId, err := cfg.GetDBQueries().CreateQuery(t.Context(), repository.QuerytypeJsonExtractor)
|
||||||
|
require.NoError(t, err)
|
||||||
|
queryVersion, err := cfg.GetDBQueries().AddLatestQueryVersion(t.Context(), queryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
value := "exaple_value"
|
||||||
|
_, err = cfg.GetDBQueries().AddResult(t.Context(), &repository.AddResultParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Value: value,
|
||||||
|
Textentryid: textId,
|
||||||
|
Queryversion: queryVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
params := &GetValueWithVersionParams{
|
||||||
|
Type: resultprocessor.TypeJsonExtractor,
|
||||||
|
QueryID: queryId,
|
||||||
|
DocumentID: docId,
|
||||||
|
QueryVersion: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err := svc.GetValueWithVersion(t.Context(), params)
|
||||||
|
require.NoError(t, err)
|
||||||
|
v := jsonextractor.NewResult(value)
|
||||||
|
assert.Equal(t, v, val)
|
||||||
|
assert.Equal(t, value, v.GetStoreValue())
|
||||||
|
})
|
||||||
|
t.Run("not existing version", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
cfg := &serviceconfig.BaseConfig{}
|
||||||
|
net := test.GetNetwork(t)
|
||||||
|
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
||||||
|
|
||||||
|
svc := New(cfg, &Services{})
|
||||||
|
|
||||||
|
err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
|
||||||
|
Clientid: "client_id",
|
||||||
|
Name: "client_name",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
docId, err := cfg.GetDBQueries().CreateDocument(t.Context(), &repository.CreateDocumentParams{
|
||||||
|
Clientid: "client_id",
|
||||||
|
Hash: "hash",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
filetype := "pdf"
|
||||||
|
part := uint16(1)
|
||||||
|
key := objectstore.BucketKey{
|
||||||
|
CreatedAt: time.Now().UTC(),
|
||||||
|
ClientID: "clientid",
|
||||||
|
EntityID: uuid.New(),
|
||||||
|
Location: objectstore.Import,
|
||||||
|
Part: &part,
|
||||||
|
FileType: &filetype,
|
||||||
|
}
|
||||||
|
err = cfg.GetDBQueries().AddDocumentEntry(t.Context(), &repository.AddDocumentEntryParams{
|
||||||
|
Documentid: docId,
|
||||||
|
Bucket: "bucket",
|
||||||
|
Key: key.String(),
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
bucket := "bucket"
|
||||||
|
hash := "hash"
|
||||||
|
keyStr := key.String()
|
||||||
|
cleanId, err := cfg.GetDBQueries().AddDocumentClean(t.Context(), &repository.AddDocumentCleanParams{
|
||||||
|
Documentid: docId,
|
||||||
|
Bucket: &bucket,
|
||||||
|
Hash: &hash,
|
||||||
|
Key: &keyStr,
|
||||||
|
Mimetype: repository.NullCleanmimetype{
|
||||||
|
Valid: true,
|
||||||
|
Cleanmimetype: repository.CleanmimetypeApplicationPdf,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddDocumentCleanEntry(t.Context(), &repository.AddDocumentCleanEntryParams{
|
||||||
|
Cleanid: cleanId,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
textId, err := cfg.GetDBQueries().AddDocumentText(t.Context(), &repository.AddDocumentTextParams{
|
||||||
|
Cleanid: cleanId,
|
||||||
|
Bucket: bucket,
|
||||||
|
Hash: hash,
|
||||||
|
Key: keyStr,
|
||||||
|
Part: part,
|
||||||
|
Createdat: pgtype.Timestamp{
|
||||||
|
Valid: true,
|
||||||
|
Time: time.Now(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddDocumentTextEntry(t.Context(), &repository.AddDocumentTextEntryParams{
|
||||||
|
Textid: textId,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
queryId, err := cfg.GetDBQueries().CreateQuery(t.Context(), repository.QuerytypeJsonExtractor)
|
||||||
|
require.NoError(t, err)
|
||||||
|
queryVersion, err := cfg.GetDBQueries().AddLatestQueryVersion(t.Context(), queryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
value := "exaple_value"
|
||||||
|
_, err = cfg.GetDBQueries().AddResult(t.Context(), &repository.AddResultParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Value: value,
|
||||||
|
Textentryid: textId,
|
||||||
|
Queryversion: queryVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
params := &GetValueWithVersionParams{
|
||||||
|
Type: resultprocessor.TypeJsonExtractor,
|
||||||
|
QueryID: queryId,
|
||||||
|
DocumentID: docId,
|
||||||
|
QueryVersion: 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.GetValueWithVersion(t.Context(), params)
|
||||||
|
require.EqualError(t, err, "no value found")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (s *Service) Process(ctx context.Context, p *Process) (resultprocessor.Valu
|
|||||||
if processQuery.RequiredQueryIDs != nil {
|
if processQuery.RequiredQueryIDs != nil {
|
||||||
elength = len(*processQuery.RequiredQueryIDs)
|
elength = len(*processQuery.RequiredQueryIDs)
|
||||||
}
|
}
|
||||||
slog.Debug("requirements", "length", len(values), "expected_length", elength)
|
slog.Info("requirements", "length", len(values), "expected_length", elength)
|
||||||
}
|
}
|
||||||
|
|
||||||
processor, err := s.getProcessor(query.Type)
|
processor, err := s.getProcessor(query.Type)
|
||||||
|
|||||||
@@ -3,64 +3,138 @@ package result
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"queryorchestration/internal/database/repository"
|
"queryorchestration/internal/database/repository"
|
||||||
"queryorchestration/internal/query"
|
"queryorchestration/internal/query"
|
||||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
"queryorchestration/internal/test"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"github.com/pashagolub/pgxmock/v3"
|
"github.com/pashagolub/pgxmock/v3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestProcess(t *testing.T) {
|
func TestProcess(t *testing.T) {
|
||||||
ctx := context.Background()
|
t.Parallel()
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
|
||||||
require.NoError(t, err)
|
|
||||||
cfg := &serviceconfig.BaseConfig{}
|
cfg := &serviceconfig.BaseConfig{}
|
||||||
cfg.DBPool = pool
|
net := test.GetNetwork(t)
|
||||||
cfg.DBQueries = repository.New(pool)
|
test.CreateDB(t, cfg, net, &test.CreateDatabaseConfig{})
|
||||||
|
|
||||||
svc := Service{
|
err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
|
||||||
cfg: cfg,
|
Clientid: "client_id",
|
||||||
svc: &Services{
|
Name: "client_name",
|
||||||
Query: query.New(cfg),
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
docId, err := cfg.GetDBQueries().CreateDocument(t.Context(), &repository.CreateDocumentParams{
|
||||||
|
Clientid: "client_id",
|
||||||
|
Hash: "hash",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
fill := "fill"
|
||||||
|
cleanId, err := cfg.GetDBQueries().AddDocumentClean(t.Context(), &repository.AddDocumentCleanParams{
|
||||||
|
Documentid: docId,
|
||||||
|
Bucket: &fill,
|
||||||
|
Key: &fill,
|
||||||
|
Hash: &fill,
|
||||||
|
Mimetype: repository.NullCleanmimetype{
|
||||||
|
Valid: true,
|
||||||
|
Cleanmimetype: repository.CleanmimetypeApplicationPdf,
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddDocumentCleanEntry(t.Context(), &repository.AddDocumentCleanEntryParams{
|
||||||
|
Cleanid: cleanId,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
textId, err := cfg.GetDBQueries().AddDocumentText(t.Context(), &repository.AddDocumentTextParams{
|
||||||
|
Cleanid: cleanId,
|
||||||
|
Bucket: fill,
|
||||||
|
Key: fill,
|
||||||
|
Hash: fill,
|
||||||
|
Createdat: pgtype.Timestamp{
|
||||||
|
Time: time.Now(),
|
||||||
|
Valid: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddDocumentTextEntry(t.Context(), &repository.AddDocumentTextEntryParams{
|
||||||
|
Textid: textId,
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
contextQueryId, err := cfg.GetDBQueries().CreateQuery(t.Context(), repository.QuerytypeContextFull)
|
||||||
|
require.NoError(t, err)
|
||||||
|
contextVersion, err := cfg.GetDBQueries().AddLatestQueryVersion(t.Context(), contextQueryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddActiveQueryVersion(t.Context(), &repository.AddActiveQueryVersionParams{
|
||||||
|
Queryid: contextQueryId,
|
||||||
|
Versionid: contextVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
queryId, err := cfg.GetDBQueries().CreateQuery(t.Context(), repository.QuerytypeJsonExtractor)
|
||||||
|
require.NoError(t, err)
|
||||||
|
latestVersion, err := cfg.GetDBQueries().AddLatestQueryVersion(t.Context(), queryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddActiveQueryVersion(t.Context(), &repository.AddActiveQueryVersionParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Versionid: latestVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = cfg.GetDBQueries().AddRequiredQuery(t.Context(), &repository.AddRequiredQueryParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Requiredqueryid: contextQueryId,
|
||||||
|
Addedversion: latestVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
c := `{"path":"oldkey"}`
|
||||||
|
err = cfg.GetDBQueries().SetQueryConfig(t.Context(), &repository.SetQueryConfigParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Config: []byte(c),
|
||||||
|
Addedversion: latestVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
strVal := `{"mykey": "example_value", "oldkey": "old_value"}`
|
||||||
|
_, err = cfg.GetDBQueries().AddResult(t.Context(), &repository.AddResultParams{
|
||||||
|
Queryid: contextQueryId,
|
||||||
|
Value: strVal,
|
||||||
|
Textentryid: textId,
|
||||||
|
Queryversion: contextVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
latestVersion, err = cfg.GetDBQueries().AddLatestQueryVersion(t.Context(), queryId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
c = `{"path": "mykey"}`
|
||||||
|
err = cfg.GetDBQueries().SetQueryConfig(t.Context(), &repository.SetQueryConfigParams{
|
||||||
|
Queryid: queryId,
|
||||||
|
Config: []byte(c),
|
||||||
|
Addedversion: latestVersion,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
qcfg := "{\"path\":\"examplekey\"}"
|
svc := New(cfg, &Services{
|
||||||
query := &resultprocessor.Query{
|
Query: query.New(cfg),
|
||||||
ID: uuid.New(),
|
})
|
||||||
Version: 2,
|
|
||||||
RequiredQueryIDs: &[]uuid.UUID{uuid.New()},
|
|
||||||
Config: &qcfg,
|
|
||||||
}
|
|
||||||
params := Process{
|
|
||||||
DocumentID: uuid.New(),
|
|
||||||
QueryID: query.ID,
|
|
||||||
QueryVersion: query.Version,
|
|
||||||
}
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(&query.ID, &query.Version).WillReturnRows(
|
val, err := svc.Process(t.Context(), &Process{
|
||||||
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
DocumentID: docId,
|
||||||
AddRow(query.ID, repository.QuerytypeJsonExtractor, query.Version, query.Version, []byte(*query.Config), *query.RequiredQueryIDs),
|
QueryID: queryId,
|
||||||
)
|
QueryVersion: 1,
|
||||||
strVal := `{"examplekey":"example_value"}`
|
})
|
||||||
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(&query.ID, &query.Version, ¶ms.DocumentID).
|
require.NoError(t, err)
|
||||||
WillReturnRows(
|
assert.NotNil(t, val)
|
||||||
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
assert.Equal(t, "old_value", val.GetStoreValue())
|
||||||
AddRow(&uuid.UUID{}, query.ID, repository.QuerytypeContextFull, &strVal),
|
|
||||||
)
|
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}).
|
|
||||||
AddRow([]byte(qcfg)),
|
|
||||||
)
|
|
||||||
|
|
||||||
val, err := svc.Process(ctx, ¶ms)
|
val, err = svc.Process(t.Context(), &Process{
|
||||||
|
DocumentID: docId,
|
||||||
|
QueryID: queryId,
|
||||||
|
QueryVersion: 2,
|
||||||
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, val)
|
assert.NotNil(t, val)
|
||||||
assert.Equal(t, "example_value", val.GetStoreValue())
|
assert.Equal(t, "example_value", val.GetStoreValue())
|
||||||
|
|||||||
@@ -85,10 +85,6 @@ func TestSet(t *testing.T) {
|
|||||||
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
||||||
AddRow(&requiredResultId, (*query.RequiredQueryIDs)[0], repository.QuerytypeContextFull, &strVal),
|
AddRow(&requiredResultId, (*query.RequiredQueryIDs)[0], repository.QuerytypeContextFull, &strVal),
|
||||||
)
|
)
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}).
|
|
||||||
AddRow([]byte(qcfg)),
|
|
||||||
)
|
|
||||||
pool.ExpectBegin()
|
pool.ExpectBegin()
|
||||||
resultId := uuid.New()
|
resultId := uuid.New()
|
||||||
pool.ExpectQuery("name: AddResult :one").WithArgs(query.ID, pgxmock.AnyArg(), textEntryId, query.Version).
|
pool.ExpectQuery("name: AddResult :one").WithArgs(query.ID, pgxmock.AnyArg(), textEntryId, query.Version).
|
||||||
|
|||||||
@@ -29,10 +29,12 @@ func TestJSONProcess(t *testing.T) {
|
|||||||
|
|
||||||
extractor := jsonextractor.NewExtractor(cfg)
|
extractor := jsonextractor.NewExtractor(cfg)
|
||||||
|
|
||||||
|
config := "{\"path\":\"key\"}"
|
||||||
query := &resultprocessor.Query{
|
query := &resultprocessor.Query{
|
||||||
ID: uuid.New(),
|
ID: uuid.New(),
|
||||||
Type: resultprocessor.TypeJsonExtractor,
|
Type: resultprocessor.TypeJsonExtractor,
|
||||||
Version: int32(1),
|
Version: int32(1),
|
||||||
|
Config: &config,
|
||||||
}
|
}
|
||||||
entryValue := "value"
|
entryValue := "value"
|
||||||
|
|
||||||
@@ -41,14 +43,6 @@ func TestJSONProcess(t *testing.T) {
|
|||||||
contextfull.NewResult(jsonString),
|
contextfull.NewResult(jsonString),
|
||||||
}
|
}
|
||||||
|
|
||||||
config := "{\"path\":\"key\"}"
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).
|
|
||||||
WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}).
|
|
||||||
AddRow([]byte(config)),
|
|
||||||
)
|
|
||||||
|
|
||||||
value, err := extractor.Process(ctx, query, values)
|
value, err := extractor.Process(ctx, query, values)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, entryValue, value)
|
assert.Equal(t, entryValue, value)
|
||||||
@@ -87,11 +81,7 @@ func TestJSONProcess(t *testing.T) {
|
|||||||
func TestJSONProcessJSON(t *testing.T) {
|
func TestJSONProcessJSON(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
pool, err := pgxmock.NewPool()
|
|
||||||
require.NoError(t, err)
|
|
||||||
cfg := &serviceconfig.BaseConfig{}
|
cfg := &serviceconfig.BaseConfig{}
|
||||||
cfg.DBPool = pool
|
|
||||||
cfg.DBQueries = repository.New(pool)
|
|
||||||
|
|
||||||
extractor := jsonextractor.NewExtractor(cfg)
|
extractor := jsonextractor.NewExtractor(cfg)
|
||||||
|
|
||||||
@@ -107,62 +97,34 @@ func TestJSONProcessJSON(t *testing.T) {
|
|||||||
contextfull.NewResult(jsonString),
|
contextfull.NewResult(jsonString),
|
||||||
}
|
}
|
||||||
|
|
||||||
config := "{\"path\":\"invalid_key\"}"
|
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).
|
|
||||||
WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}).
|
|
||||||
AddRow([]byte(config)),
|
|
||||||
)
|
|
||||||
|
|
||||||
value, err := extractor.Process(ctx, query, values)
|
value, err := extractor.Process(ctx, query, values)
|
||||||
|
assert.EqualError(t, err, "config required")
|
||||||
|
assert.Empty(t, value)
|
||||||
|
|
||||||
|
config := "{\"path\":\"invalid_key\"}"
|
||||||
|
query.Config = &config
|
||||||
|
|
||||||
|
value, err = extractor.Process(ctx, query, values)
|
||||||
assert.EqualError(t, err, "JSON path does not exist: invalid_key")
|
assert.EqualError(t, err, "JSON path does not exist: invalid_key")
|
||||||
assert.Empty(t, value)
|
assert.Empty(t, value)
|
||||||
|
|
||||||
config = ""
|
config = ""
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).
|
|
||||||
WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}).
|
|
||||||
AddRow([]byte(config)),
|
|
||||||
)
|
|
||||||
|
|
||||||
value, err = extractor.Process(ctx, query, values)
|
value, err = extractor.Process(ctx, query, values)
|
||||||
assert.EqualError(t, err, "unexpected end of JSON input")
|
assert.EqualError(t, err, "unexpected end of JSON input")
|
||||||
assert.Empty(t, value)
|
assert.Empty(t, value)
|
||||||
|
|
||||||
config = "{\"path\":\"\"}"
|
config = "{\"path\":\"\"}"
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).
|
|
||||||
WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}).
|
|
||||||
AddRow([]byte(config)),
|
|
||||||
)
|
|
||||||
|
|
||||||
value, err = extractor.Process(ctx, query, values)
|
value, err = extractor.Process(ctx, query, values)
|
||||||
assert.EqualError(t, err, "JSON path does not exist: ")
|
assert.EqualError(t, err, "JSON path does not exist: ")
|
||||||
assert.Empty(t, value)
|
assert.Empty(t, value)
|
||||||
|
|
||||||
config = "{\"path\":}"
|
config = "{\"path\":}"
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).
|
|
||||||
WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}).
|
|
||||||
AddRow([]byte(config)),
|
|
||||||
)
|
|
||||||
|
|
||||||
value, err = extractor.Process(ctx, query, values)
|
value, err = extractor.Process(ctx, query, values)
|
||||||
assert.EqualError(t, err, "invalid character '}' looking for beginning of value")
|
assert.EqualError(t, err, "invalid character '}' looking for beginning of value")
|
||||||
assert.Empty(t, value)
|
assert.Empty(t, value)
|
||||||
|
|
||||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).
|
|
||||||
WillReturnRows(
|
|
||||||
pgxmock.NewRows([]string{"config"}),
|
|
||||||
)
|
|
||||||
|
|
||||||
value, err = extractor.Process(ctx, query, values)
|
|
||||||
assert.EqualError(t, err, "no rows in result set")
|
|
||||||
assert.Empty(t, value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONProcessResults(t *testing.T) {
|
func TestJSONProcessResults(t *testing.T) {
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ func NewExtractor(cfg serviceconfig.ConfigProvider) *Extractor {
|
|||||||
func (e *Extractor) Process(ctx context.Context, query *resultprocessor.Query, values []resultprocessor.Value) (string, error) {
|
func (e *Extractor) Process(ctx context.Context, query *resultprocessor.Query, values []resultprocessor.Value) (string, error) {
|
||||||
if len(values) != 1 {
|
if len(values) != 1 {
|
||||||
return "", fmt.Errorf("JSON Extraction requires 1 result")
|
return "", fmt.Errorf("JSON Extraction requires 1 result")
|
||||||
|
} else if query.Config == nil {
|
||||||
|
return "", fmt.Errorf("config required")
|
||||||
}
|
}
|
||||||
|
|
||||||
value, err := values[0].GetValue(ctx)
|
value, err := values[0].GetValue(ctx)
|
||||||
@@ -33,13 +35,8 @@ func (e *Extractor) Process(ctx context.Context, query *resultprocessor.Query, v
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
byteConfig, err := e.cfg.GetDBQueries().GetActiveQueryConfig(ctx, query.ID)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config Config
|
var config Config
|
||||||
err = json.Unmarshal(byteConfig, &config)
|
err = json.Unmarshal([]byte(*query.Config), &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
queryapi "queryorchestration/api/queryAPI"
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
|
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
@@ -18,7 +17,7 @@ import (
|
|||||||
type APIName string
|
type APIName string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
QueryAPIName APIName = queryapi.Name
|
QueryAPIName APIName = "queryAPI"
|
||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
|
|||||||
+9
-19
@@ -4,16 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
clientsyncrunner "queryorchestration/api/clientSyncRunner"
|
|
||||||
doccleanrunner "queryorchestration/api/docCleanRunner"
|
|
||||||
docinitrunner "queryorchestration/api/docInitRunner"
|
|
||||||
docsyncrunner "queryorchestration/api/docSyncRunner"
|
|
||||||
doctextrunner "queryorchestration/api/docTextRunner"
|
|
||||||
queryrunner "queryorchestration/api/queryRunner"
|
|
||||||
querysyncrunner "queryorchestration/api/querySyncRunner"
|
|
||||||
queryversionsyncrunner "queryorchestration/api/queryVersionSyncRunner"
|
|
||||||
storeeventrunner "queryorchestration/api/storeEventRunner"
|
|
||||||
|
|
||||||
"queryorchestration/internal/serviceconfig"
|
"queryorchestration/internal/serviceconfig"
|
||||||
"queryorchestration/internal/serviceconfig/queue/clientsync"
|
"queryorchestration/internal/serviceconfig/queue/clientsync"
|
||||||
"queryorchestration/internal/serviceconfig/queue/documentclean"
|
"queryorchestration/internal/serviceconfig/queue/documentclean"
|
||||||
@@ -29,15 +19,15 @@ import (
|
|||||||
type RunnerName string
|
type RunnerName string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
StoreEventRunnerName RunnerName = storeeventrunner.Name
|
StoreEventRunnerName RunnerName = "storeEventRunner"
|
||||||
DocInitRunnerName RunnerName = docinitrunner.Name
|
DocInitRunnerName RunnerName = "docInitRunner"
|
||||||
DocSyncRunnerName RunnerName = docsyncrunner.Name
|
DocSyncRunnerName RunnerName = "docSyncRunner"
|
||||||
DocCleanRunnerName RunnerName = doccleanrunner.Name
|
DocCleanRunnerName RunnerName = "docCleanRunner"
|
||||||
DocTextRunnerName RunnerName = doctextrunner.Name
|
DocTextRunnerName RunnerName = "docTextRunner"
|
||||||
QuerySyncRunnerName RunnerName = querysyncrunner.Name
|
QuerySyncRunnerName RunnerName = "querySyncRunner"
|
||||||
QueryRunnerName RunnerName = queryrunner.Name
|
QueryRunnerName RunnerName = "queryRunner"
|
||||||
ClientSyncRunnerName RunnerName = clientsyncrunner.Name
|
ClientSyncRunnerName RunnerName = "clientSyncRunner"
|
||||||
QueryVersionSyncRunnerName RunnerName = queryversionsyncrunner.Name
|
QueryVersionSyncRunnerName RunnerName = "queryVersionSyncRunner"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RunnerEnv string
|
type RunnerEnv string
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ includes:
|
|||||||
tasks:
|
tasks:
|
||||||
fullsuite:
|
fullsuite:
|
||||||
- task: build:deps
|
- task: build:deps
|
||||||
|
- task: docker:build
|
||||||
- task: fullsuite:test
|
- task: fullsuite:test
|
||||||
fullsuite:test:
|
fullsuite:test:
|
||||||
internal: true
|
internal: true
|
||||||
|
|||||||
+3
-3
@@ -40,20 +40,20 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- mkdir -p {{.OUT_DIR}}
|
- mkdir -p {{.OUT_DIR}}
|
||||||
- |
|
- |
|
||||||
GOMAXPROCS={{.TEST_PARALLEL}} go test -count=1 -parallel {{.CPU_COUNT}} \
|
GOMAXPROCS={{.TEST_PARALLEL}} go test -parallel {{.CPU_COUNT}} \
|
||||||
-coverpkg={{.INTERNAL}},{{.API}},{{.PKG}} \
|
-coverpkg={{.INTERNAL}},{{.API}},{{.PKG}} \
|
||||||
-coverprofile={{.COVERAGE_FILE}} \
|
-coverprofile={{.COVERAGE_FILE}} \
|
||||||
./...
|
./...
|
||||||
- task: coverage
|
- task: coverage
|
||||||
race:
|
race:
|
||||||
cmds:
|
cmds:
|
||||||
- GOMAXPROCS={{.TEST_PARALLEL}} go test -count=1 -parallel {{.CPU_COUNT}} -race ./...
|
- GOMAXPROCS={{.TEST_PARALLEL}} go test -parallel {{.CPU_COUNT}} -race ./...
|
||||||
perf:
|
perf:
|
||||||
vars:
|
vars:
|
||||||
NUM_RESULTS: 5
|
NUM_RESULTS: 5
|
||||||
cmds:
|
cmds:
|
||||||
- |
|
- |
|
||||||
GOMAXPROCS={{.TEST_PARALLEL}} go test -count=1 -parallel {{.CPU_COUNT}} -json ./... \
|
GOMAXPROCS={{.TEST_PARALLEL}} go test -parallel {{.CPU_COUNT}} -count=1 -json ./... \
|
||||||
> {{.TEST_FILE}}
|
> {{.TEST_FILE}}
|
||||||
- |
|
- |
|
||||||
echo -e "🐢 TOP {{.NUM_RESULTS}} SLOWEST INDIVIDUAL PACKAGE RUNS:"
|
echo -e "🐢 TOP {{.NUM_RESULTS}} SLOWEST INDIVIDUAL PACKAGE RUNS:"
|
||||||
|
|||||||
+255
-104
@@ -25,133 +25,284 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestProcess(t *testing.T) {
|
func TestProcess(t *testing.T) {
|
||||||
cfg := &Config{}
|
t.Run("basic upload", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
cfg := &Config{}
|
||||||
|
|
||||||
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||||
defer clean()
|
defer clean()
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var clientId queryapi.ClientID
|
var clientId queryapi.ClientID
|
||||||
var jsonId queryapi.QueryID
|
var jsonId queryapi.QueryID
|
||||||
var textractExpectation test.MockExpectation
|
var textractExpectation test.MockExpectation
|
||||||
textractBody := "Hello World"
|
textractBody := "Hello World"
|
||||||
wg.Add(3)
|
wg.Add(3)
|
||||||
go func(t testing.TB) {
|
go func(t testing.TB) {
|
||||||
_, jsonId = queryapitest.CreateDependentQueries(t, net.Client)
|
_, jsonId = queryapitest.CreateDependentQueries(t, net.Client)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(t)
|
}(t)
|
||||||
go func(t testing.TB) {
|
go func(t testing.TB) {
|
||||||
clientId = queryapitest.CreateClientWithSync(t, net.Client)
|
clientId = queryapitest.CreateClientWithSync(t, net.Client)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(t)
|
}(t)
|
||||||
go func(t testing.TB) {
|
go func(t testing.TB) {
|
||||||
textractExpectation = test.CreateDetectDocumentTextExpectation(
|
textractExpectation = test.CreateDetectDocumentTextExpectation(
|
||||||
t,
|
t,
|
||||||
net.Dependencies.MockServer,
|
net.Dependencies.MockServer,
|
||||||
textractBody,
|
textractBody,
|
||||||
)
|
)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(t)
|
}(t)
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||||
|
|
||||||
part := uint16(0)
|
part := uint16(0)
|
||||||
importKey := objectstore.BucketKey{
|
importKey := objectstore.BucketKey{
|
||||||
ClientID: clientId,
|
ClientID: clientId,
|
||||||
EntityID: uuid.New(),
|
EntityID: uuid.New(),
|
||||||
Location: objectstore.Import,
|
Location: objectstore.Import,
|
||||||
CreatedAt: time.Now().UTC(),
|
CreatedAt: time.Now().UTC(),
|
||||||
Part: &part,
|
Part: &part,
|
||||||
}
|
}
|
||||||
inputFile := strings.NewReader(pdfHelloWorld)
|
inputFile := strings.NewReader(pdfHelloWorld)
|
||||||
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
||||||
File: inputFile,
|
File: inputFile,
|
||||||
Key: importKey,
|
Key: importKey,
|
||||||
|
})
|
||||||
|
|
||||||
|
test.WaitForMockEndpoint(t, net.Dependencies.MockServer, textractExpectation.Request)
|
||||||
|
textKey := objectstore.BucketKey{
|
||||||
|
ClientID: clientId,
|
||||||
|
EntityID: uuid.New(),
|
||||||
|
Location: objectstore.Text,
|
||||||
|
CreatedAt: time.Now().UTC(),
|
||||||
|
Part: &part,
|
||||||
|
}
|
||||||
|
inputFile = strings.NewReader(textractBody)
|
||||||
|
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
||||||
|
File: inputFile,
|
||||||
|
Key: textKey,
|
||||||
|
})
|
||||||
|
|
||||||
|
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||||
|
|
||||||
|
docs, err := net.Client.ListDocumentsByClientIdWithResponse(t.Context(), clientId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Len(t, *docs.JSON200, 1)
|
||||||
|
doc := (*docs.JSON200)[0]
|
||||||
|
|
||||||
|
expectedDoc := queryapi.Document{
|
||||||
|
Id: doc.Id,
|
||||||
|
Hash: doc.Hash,
|
||||||
|
ClientId: clientId,
|
||||||
|
Fields: map[string]any{
|
||||||
|
"JSON_QUERY": "valueone",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
docRes, err := net.Client.GetDocumentWithResponse(t.Context(), doc.Id)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, docRes)
|
||||||
|
require.NotNil(t, docRes.JSON200)
|
||||||
|
fullDoc := *docRes.JSON200
|
||||||
|
assert.EqualExportedValues(t, expectedDoc, fullDoc)
|
||||||
})
|
})
|
||||||
|
t.Run("update config", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
cfg := &Config{}
|
||||||
|
|
||||||
test.WaitForMockEndpoint(t, net.Dependencies.MockServer, textractExpectation.Request)
|
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||||
textKey := objectstore.BucketKey{
|
defer clean()
|
||||||
ClientID: clientId,
|
|
||||||
EntityID: uuid.New(),
|
|
||||||
Location: objectstore.Text,
|
|
||||||
CreatedAt: time.Now().UTC(),
|
|
||||||
Part: &part,
|
|
||||||
}
|
|
||||||
inputFile = strings.NewReader(textractBody)
|
|
||||||
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
|
||||||
File: inputFile,
|
|
||||||
Key: textKey,
|
|
||||||
})
|
|
||||||
|
|
||||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
var wg sync.WaitGroup
|
||||||
|
var clientId queryapi.ClientID
|
||||||
|
var jsonId queryapi.QueryID
|
||||||
|
var textractExpectation test.MockExpectation
|
||||||
|
textractBody := "Hello World"
|
||||||
|
wg.Add(3)
|
||||||
|
go func(t testing.TB) {
|
||||||
|
_, jsonId = queryapitest.CreateDependentQueries(t, net.Client)
|
||||||
|
wg.Done()
|
||||||
|
}(t)
|
||||||
|
go func(t testing.TB) {
|
||||||
|
clientId = queryapitest.CreateClientWithSync(t, net.Client)
|
||||||
|
wg.Done()
|
||||||
|
}(t)
|
||||||
|
go func(t testing.TB) {
|
||||||
|
textractExpectation = test.CreateDetectDocumentTextExpectation(
|
||||||
|
t,
|
||||||
|
net.Dependencies.MockServer,
|
||||||
|
textractBody,
|
||||||
|
)
|
||||||
|
wg.Done()
|
||||||
|
}(t)
|
||||||
|
|
||||||
docs, err := net.Client.ListDocumentsByClientIdWithResponse(t.Context(), clientId)
|
wg.Wait()
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Len(t, *docs.JSON200, 1)
|
|
||||||
doc := (*docs.JSON200)[0]
|
|
||||||
|
|
||||||
expectedDoc := queryapi.Document{
|
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||||
Id: doc.Id,
|
|
||||||
Hash: doc.Hash,
|
|
||||||
ClientId: clientId,
|
|
||||||
Fields: map[string]any{
|
|
||||||
"JSON_QUERY": "valueone",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
docRes, err := net.Client.GetDocumentWithResponse(t.Context(), doc.Id)
|
part := uint16(0)
|
||||||
require.NoError(t, err)
|
importKey := objectstore.BucketKey{
|
||||||
require.NotNil(t, docRes)
|
ClientID: clientId,
|
||||||
require.NotNil(t, docRes.JSON200)
|
EntityID: uuid.New(),
|
||||||
fullDoc := *docRes.JSON200
|
Location: objectstore.Import,
|
||||||
assert.EqualExportedValues(t, expectedDoc, fullDoc)
|
CreatedAt: time.Now().UTC(),
|
||||||
|
Part: &part,
|
||||||
|
}
|
||||||
|
inputFile := strings.NewReader(pdfHelloWorld)
|
||||||
|
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
||||||
|
File: inputFile,
|
||||||
|
Key: importKey,
|
||||||
|
})
|
||||||
|
|
||||||
jcfg := `{"path":"keytwo"}`
|
test.WaitForMockEndpoint(t, net.Dependencies.MockServer, textractExpectation.Request)
|
||||||
av := int32(2)
|
textKey := objectstore.BucketKey{
|
||||||
_, err = net.Client.UpdateQueryWithResponse(t.Context(), jsonId, queryapi.QueryUpdate{
|
ClientID: clientId,
|
||||||
ActiveVersion: &av,
|
EntityID: uuid.New(),
|
||||||
Config: &jcfg,
|
Location: objectstore.Text,
|
||||||
})
|
CreatedAt: time.Now().UTC(),
|
||||||
require.NoError(t, err)
|
Part: &part,
|
||||||
expectedDoc.Fields = map[string]any{
|
}
|
||||||
"JSON_QUERY": "valuetwo",
|
inputFile = strings.NewReader(textractBody)
|
||||||
}
|
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
||||||
|
File: inputFile,
|
||||||
|
Key: textKey,
|
||||||
|
})
|
||||||
|
|
||||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||||
|
|
||||||
wg.Add(3)
|
jcfg := `{"path":"keytwo"}`
|
||||||
go func(t testing.TB) {
|
av := int32(2)
|
||||||
docRes, err = net.Client.GetDocumentWithResponse(t.Context(), doc.Id)
|
_, err := net.Client.UpdateQueryWithResponse(t.Context(), jsonId, queryapi.QueryUpdate{
|
||||||
|
ActiveVersion: &av,
|
||||||
|
Config: &jcfg,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||||
|
|
||||||
|
docs, err := net.Client.ListDocumentsByClientIdWithResponse(t.Context(), clientId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Len(t, *docs.JSON200, 1)
|
||||||
|
doc := (*docs.JSON200)[0]
|
||||||
|
|
||||||
|
expectedDoc := queryapi.Document{
|
||||||
|
Id: doc.Id,
|
||||||
|
Hash: doc.Hash,
|
||||||
|
ClientId: clientId,
|
||||||
|
Fields: map[string]any{
|
||||||
|
"JSON_QUERY": "valuetwo",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
docRes, err := net.Client.GetDocumentWithResponse(t.Context(), doc.Id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, docRes)
|
require.NotNil(t, docRes)
|
||||||
require.NotNil(t, docRes.JSON200)
|
require.NotNil(t, docRes.JSON200)
|
||||||
assert.EqualExportedValues(t, expectedDoc, *docRes.JSON200)
|
assert.EqualExportedValues(t, expectedDoc, *docRes.JSON200)
|
||||||
wg.Done()
|
})
|
||||||
}(t)
|
t.Run("test multiple versions", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
cfg := &Config{}
|
||||||
|
|
||||||
go func(t testing.TB) {
|
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||||
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
defer clean()
|
||||||
QueryVersion: 1,
|
|
||||||
DocumentId: doc.Id,
|
var wg sync.WaitGroup
|
||||||
|
var clientId queryapi.ClientID
|
||||||
|
var jsonId queryapi.QueryID
|
||||||
|
var textractExpectation test.MockExpectation
|
||||||
|
textractBody := "Hello World"
|
||||||
|
wg.Add(3)
|
||||||
|
go func(t testing.TB) {
|
||||||
|
_, jsonId = queryapitest.CreateDependentQueries(t, net.Client)
|
||||||
|
|
||||||
|
jcfg := `{"path":"keytwo"}`
|
||||||
|
_, err := net.Client.UpdateQueryWithResponse(t.Context(), jsonId, queryapi.QueryUpdate{
|
||||||
|
Config: &jcfg,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
wg.Done()
|
||||||
|
}(t)
|
||||||
|
go func(t testing.TB) {
|
||||||
|
clientId = queryapitest.CreateClientWithSync(t, net.Client)
|
||||||
|
wg.Done()
|
||||||
|
}(t)
|
||||||
|
go func(t testing.TB) {
|
||||||
|
textractExpectation = test.CreateDetectDocumentTextExpectation(
|
||||||
|
t,
|
||||||
|
net.Dependencies.MockServer,
|
||||||
|
textractBody,
|
||||||
|
)
|
||||||
|
wg.Done()
|
||||||
|
}(t)
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||||
|
|
||||||
|
part := uint16(0)
|
||||||
|
importKey := objectstore.BucketKey{
|
||||||
|
ClientID: clientId,
|
||||||
|
EntityID: uuid.New(),
|
||||||
|
Location: objectstore.Import,
|
||||||
|
CreatedAt: time.Now().UTC(),
|
||||||
|
Part: &part,
|
||||||
|
}
|
||||||
|
inputFile := strings.NewReader(pdfHelloWorld)
|
||||||
|
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
||||||
|
File: inputFile,
|
||||||
|
Key: importKey,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, "valueone", testRes.JSON200.Value)
|
|
||||||
wg.Done()
|
|
||||||
}(t)
|
|
||||||
|
|
||||||
go func(t testing.TB) {
|
test.WaitForMockEndpoint(t, net.Dependencies.MockServer, textractExpectation.Request)
|
||||||
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
textKey := objectstore.BucketKey{
|
||||||
QueryVersion: 2,
|
ClientID: clientId,
|
||||||
DocumentId: doc.Id,
|
EntityID: uuid.New(),
|
||||||
|
Location: objectstore.Text,
|
||||||
|
CreatedAt: time.Now().UTC(),
|
||||||
|
Part: &part,
|
||||||
|
}
|
||||||
|
inputFile = strings.NewReader(textractBody)
|
||||||
|
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
||||||
|
File: inputFile,
|
||||||
|
Key: textKey,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, "valuetwo", testRes.JSON200.Value)
|
|
||||||
wg.Done()
|
|
||||||
}(t)
|
|
||||||
|
|
||||||
wg.Wait()
|
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||||
|
|
||||||
|
docs, err := net.Client.ListDocumentsByClientIdWithResponse(t.Context(), clientId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Len(t, *docs.JSON200, 1)
|
||||||
|
doc := (*docs.JSON200)[0]
|
||||||
|
|
||||||
|
wg.Add(2)
|
||||||
|
go func(t testing.TB) {
|
||||||
|
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
||||||
|
QueryVersion: 1,
|
||||||
|
DocumentId: doc.Id,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "valueone", testRes.JSON200.Value)
|
||||||
|
wg.Done()
|
||||||
|
}(t)
|
||||||
|
|
||||||
|
go func(t testing.TB) {
|
||||||
|
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
||||||
|
QueryVersion: 2,
|
||||||
|
DocumentId: doc.Id,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "valuetwo", testRes.JSON200.Value)
|
||||||
|
wg.Done()
|
||||||
|
}(t)
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const pdfHelloWorld = `%PDF-1.4
|
const pdfHelloWorld = `%PDF-1.4
|
||||||
|
|||||||
Reference in New Issue
Block a user