Merged in feature/tests (pull request #117)
Feature/tests * improvetests * generation * simplifiedtesting * simplifiedtesting * longfile
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -119,21 +120,7 @@ func TestListClientDocumentIDs(t *testing.T) {
|
||||
}, ids)
|
||||
}
|
||||
|
||||
func TestClientSync(t *testing.T) {
|
||||
t.Parallel()
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping long test in short mode")
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{
|
||||
RunMigrations: true,
|
||||
})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
func createDependentQueries(t testing.TB, ctx context.Context, queries *repository.Queries) (uuid.UUID, uuid.UUID) {
|
||||
contextQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeContextFull))
|
||||
require.NoError(t, err)
|
||||
contextQueryVersion, err := queries.AddLatestQueryVersion(ctx, contextQueryID)
|
||||
@@ -159,8 +146,12 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
return contextQueryID, jsonQueryID
|
||||
}
|
||||
|
||||
func createClientWithCollector(t testing.TB, ctx context.Context, queries *repository.Queries) string {
|
||||
clientId := "EXAMPLE"
|
||||
err = queries.CreateClient(ctx, &repository.CreateClientParams{
|
||||
err := queries.CreateClient(ctx, &repository.CreateClientParams{
|
||||
Name: "example_client",
|
||||
ID: clientId,
|
||||
})
|
||||
@@ -173,21 +164,42 @@ func TestClientSync(t *testing.T) {
|
||||
Clientid: clientId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = queries.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{
|
||||
Clientid: clientId,
|
||||
Queryid: jsonQueryID,
|
||||
Addedversion: collectorVersion,
|
||||
Name: "first_key",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err := queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
return clientId
|
||||
}
|
||||
|
||||
bucket := "example_bucket"
|
||||
func TestClientSync(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping long test in short mode")
|
||||
}
|
||||
|
||||
t.Run("document fail clean", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{
|
||||
RunMigrations: true,
|
||||
})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
_, jsonQueryID := createDependentQueries(t, ctx, queries)
|
||||
clientId := createClientWithCollector(t, ctx, queries)
|
||||
|
||||
err := queries.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{
|
||||
Clientid: clientId,
|
||||
Queryid: jsonQueryID,
|
||||
Addedversion: 1,
|
||||
Name: "first_key",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err := queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
|
||||
documentID, err := queries.CreateDocument(ctx, &repository.CreateDocumentParams{
|
||||
Clientid: clientId,
|
||||
Hash: "example_noclean",
|
||||
@@ -235,6 +247,34 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("valid extraction", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
net := test.DepNetwork.Get(t, ctx)
|
||||
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{
|
||||
RunMigrations: true,
|
||||
})
|
||||
|
||||
queries := cfg.GetDBQueries()
|
||||
|
||||
contextQueryID, jsonQueryID := createDependentQueries(t, ctx, queries)
|
||||
clientId := createClientWithCollector(t, ctx, queries)
|
||||
|
||||
err := queries.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{
|
||||
Clientid: clientId,
|
||||
Queryid: jsonQueryID,
|
||||
Addedversion: 1,
|
||||
Name: "first_key",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err := queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
|
||||
bucket := "example_bucket"
|
||||
|
||||
documentID, err := queries.CreateDocument(ctx, &repository.CreateDocumentParams{
|
||||
Clientid: clientId,
|
||||
Hash: "example_hash",
|
||||
@@ -320,7 +360,7 @@ func TestClientSync(t *testing.T) {
|
||||
Queryid: contextQueryID,
|
||||
Value: "example_context",
|
||||
Textentryid: textId,
|
||||
Queryversion: contextQueryVersion,
|
||||
Queryversion: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -340,7 +380,7 @@ func TestClientSync(t *testing.T) {
|
||||
Queryid: jsonQueryID,
|
||||
Value: "json_value",
|
||||
Textentryid: textId,
|
||||
Queryversion: jsonQueryVersion,
|
||||
Queryversion: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -421,7 +461,7 @@ func TestClientSync(t *testing.T) {
|
||||
Queryid: jsonQueryID,
|
||||
Value: "updated_context_value",
|
||||
Textentryid: textId,
|
||||
Queryversion: jsonQueryVersion,
|
||||
Queryversion: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -818,7 +858,7 @@ func TestClientSync(t *testing.T) {
|
||||
Queryid: jsonQueryID,
|
||||
Value: "json_with_super",
|
||||
Textentryid: textThreeId,
|
||||
Queryversion: jsonQueryVersion,
|
||||
Queryversion: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user