Merged in bugfix/querytest (pull request #147)
Pass Test Query * passfullsutie
This commit is contained in:
+255
-104
@@ -25,133 +25,284 @@ type Config struct {
|
||||
}
|
||||
|
||||
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)
|
||||
defer clean()
|
||||
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer clean()
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
wg.Wait()
|
||||
wg.Wait()
|
||||
|
||||
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||
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,
|
||||
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,
|
||||
})
|
||||
|
||||
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)
|
||||
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,
|
||||
})
|
||||
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer clean()
|
||||
|
||||
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)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, *docs.JSON200, 1)
|
||||
doc := (*docs.JSON200)[0]
|
||||
wg.Wait()
|
||||
|
||||
expectedDoc := queryapi.Document{
|
||||
Id: doc.Id,
|
||||
Hash: doc.Hash,
|
||||
ClientId: clientId,
|
||||
Fields: map[string]any{
|
||||
"JSON_QUERY": "valueone",
|
||||
},
|
||||
}
|
||||
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||
|
||||
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)
|
||||
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,
|
||||
})
|
||||
|
||||
jcfg := `{"path":"keytwo"}`
|
||||
av := int32(2)
|
||||
_, err = net.Client.UpdateQueryWithResponse(t.Context(), jsonId, queryapi.QueryUpdate{
|
||||
ActiveVersion: &av,
|
||||
Config: &jcfg,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
expectedDoc.Fields = map[string]any{
|
||||
"JSON_QUERY": "valuetwo",
|
||||
}
|
||||
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)
|
||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||
|
||||
wg.Add(3)
|
||||
go func(t testing.TB) {
|
||||
docRes, err = net.Client.GetDocumentWithResponse(t.Context(), doc.Id)
|
||||
jcfg := `{"path":"keytwo"}`
|
||||
av := int32(2)
|
||||
_, 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.NotNil(t, docRes)
|
||||
require.NotNil(t, 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) {
|
||||
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
||||
QueryVersion: 1,
|
||||
DocumentId: doc.Id,
|
||||
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer clean()
|
||||
|
||||
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) {
|
||||
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
||||
QueryVersion: 2,
|
||||
DocumentId: doc.Id,
|
||||
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,
|
||||
})
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user