moveservicesInterfaces
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package grpc_test
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -8,18 +8,17 @@ import (
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/network"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type containerConfig struct {
|
||||
type apiContainerConfig struct {
|
||||
DB dbConfig
|
||||
Network *testcontainers.DockerNetwork
|
||||
}
|
||||
|
||||
func createContainer(t *testing.T, ctx context.Context, config *containerConfig) (*grpc.ClientConn, func()) {
|
||||
func createAPIContainer(t *testing.T, ctx context.Context, config *apiContainerConfig) (*grpc.ClientConn, func()) {
|
||||
port, err := nat.NewPort("tcp", "8080")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create port: %v", err)
|
||||
@@ -69,70 +68,12 @@ func createContainer(t *testing.T, ctx context.Context, config *containerConfig)
|
||||
}
|
||||
}
|
||||
|
||||
type dbConfig struct {
|
||||
Name string
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
}
|
||||
|
||||
func createDB(t *testing.T, ctx context.Context, network *testcontainers.DockerNetwork) (*dbConfig, testcontainers.Container) {
|
||||
alias := "postgres"
|
||||
port, err := nat.NewPort("tcp", "5432")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create port: %v", err)
|
||||
}
|
||||
|
||||
config := dbConfig{
|
||||
Name: "queryorchestration",
|
||||
Password: "pass",
|
||||
User: "postgres",
|
||||
Port: port.Int(),
|
||||
Host: alias,
|
||||
}
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: "postgres:latest",
|
||||
Env: map[string]string{
|
||||
"POSTGRES_DB": config.Name,
|
||||
"POSTGRES_USER": config.User,
|
||||
"POSTGRES_PASSWORD": config.Password,
|
||||
},
|
||||
Networks: []string{network.Name},
|
||||
NetworkAliases: map[string][]string{
|
||||
network.Name: {alias},
|
||||
},
|
||||
ExposedPorts: []string{port.Port()},
|
||||
WaitingFor: wait.ForListeningPort(port),
|
||||
}
|
||||
|
||||
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
||||
ContainerRequest: req,
|
||||
Started: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to start container: %v", err)
|
||||
}
|
||||
|
||||
return &config, container
|
||||
}
|
||||
|
||||
func createNetwork(t *testing.T, ctx context.Context) *testcontainers.DockerNetwork {
|
||||
network, err := network.New(ctx, network.WithDriver("bridge"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return network
|
||||
}
|
||||
|
||||
func createDependencies(t *testing.T, ctx context.Context) (*grpc.ClientConn, func()) {
|
||||
func createAPIDependencies(t *testing.T, ctx context.Context) (*grpc.ClientConn, func()) {
|
||||
network := createNetwork(t, ctx)
|
||||
|
||||
dbconfig, dbContainer := createDB(t, ctx, network)
|
||||
|
||||
conn, containerCleanup := createContainer(t, ctx, &containerConfig{
|
||||
conn, containerCleanup := createAPIContainer(t, ctx, &apiContainerConfig{
|
||||
DB: *dbconfig,
|
||||
Network: network,
|
||||
})
|
||||
@@ -0,0 +1,69 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/network"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
func createNetwork(t *testing.T, ctx context.Context) *testcontainers.DockerNetwork {
|
||||
network, err := network.New(ctx, network.WithDriver("bridge"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return network
|
||||
}
|
||||
|
||||
type dbConfig struct {
|
||||
Name string
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
}
|
||||
|
||||
func createDB(t *testing.T, ctx context.Context, network *testcontainers.DockerNetwork) (*dbConfig, testcontainers.Container) {
|
||||
alias := "postgres"
|
||||
port, err := nat.NewPort("tcp", "5432")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create port: %v", err)
|
||||
}
|
||||
|
||||
config := dbConfig{
|
||||
Name: "queryorchestration",
|
||||
Password: "pass",
|
||||
User: "postgres",
|
||||
Port: port.Int(),
|
||||
Host: alias,
|
||||
}
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: "postgres:latest",
|
||||
Env: map[string]string{
|
||||
"POSTGRES_DB": config.Name,
|
||||
"POSTGRES_USER": config.User,
|
||||
"POSTGRES_PASSWORD": config.Password,
|
||||
},
|
||||
Networks: []string{network.Name},
|
||||
NetworkAliases: map[string][]string{
|
||||
network.Name: {alias},
|
||||
},
|
||||
ExposedPorts: []string{port.Port()},
|
||||
WaitingFor: wait.ForListeningPort(port),
|
||||
}
|
||||
|
||||
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
||||
ContainerRequest: req,
|
||||
Started: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to start container: %v", err)
|
||||
}
|
||||
|
||||
return &config, container
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package grpc_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/api/grpc/spec"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestQuery(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := createDependencies(t, ctx)
|
||||
defer cleanup()
|
||||
|
||||
client := spec.NewQueryServiceClient(conn)
|
||||
|
||||
id := "sample_id"
|
||||
|
||||
_, err := client.Get(ctx, &spec.IdMessage{
|
||||
Id: id,
|
||||
})
|
||||
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package queue_test
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
func TestName(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
queue, cleanup := createDependencies(t, ctx)
|
||||
queue, cleanup := createQueueDependencies(t, ctx)
|
||||
defer cleanup()
|
||||
|
||||
document := document.Document{
|
||||
@@ -0,0 +1,26 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
serviceinterfaces "queryorchestration/api/serviceInterfaces"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestQuery(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := createAPIDependencies(t, ctx)
|
||||
defer cleanup()
|
||||
|
||||
client := serviceinterfaces.NewQueryServiceClient(conn)
|
||||
|
||||
id := "sample_id"
|
||||
|
||||
_, err := client.Get(ctx, &serviceinterfaces.IdMessage{
|
||||
Id: id,
|
||||
})
|
||||
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package queue_test
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -15,17 +15,16 @@ import (
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/network"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
type containerConfig struct {
|
||||
type queueContainerConfig struct {
|
||||
Queue queueConfig
|
||||
DB *dbConfig
|
||||
Network *testcontainers.DockerNetwork
|
||||
}
|
||||
|
||||
func createContainer(t *testing.T, ctx context.Context, config containerConfig) testcontainers.Container {
|
||||
func createQueueContainer(t *testing.T, ctx context.Context, config *queueContainerConfig) testcontainers.Container {
|
||||
queueCredentials, err := config.Queue.Credentials.Retrieve(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -153,64 +152,6 @@ func createQueue(t *testing.T, ctx context.Context, network *testcontainers.Dock
|
||||
}
|
||||
}
|
||||
|
||||
func createNetwork(t *testing.T, ctx context.Context) *testcontainers.DockerNetwork {
|
||||
network, err := network.New(ctx, network.WithDriver("bridge"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return network
|
||||
}
|
||||
|
||||
type dbConfig struct {
|
||||
Name string
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
}
|
||||
|
||||
func createDB(t *testing.T, ctx context.Context, network *testcontainers.DockerNetwork) (*dbConfig, testcontainers.Container) {
|
||||
alias := "postgres"
|
||||
port, err := nat.NewPort("tcp", "5432")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create port: %v", err)
|
||||
}
|
||||
|
||||
config := dbConfig{
|
||||
Name: "queryorchestration",
|
||||
Password: "pass",
|
||||
User: "postgres",
|
||||
Port: port.Int(),
|
||||
Host: alias,
|
||||
}
|
||||
|
||||
req := testcontainers.ContainerRequest{
|
||||
Image: "postgres:latest",
|
||||
Env: map[string]string{
|
||||
"POSTGRES_DB": config.Name,
|
||||
"POSTGRES_USER": config.User,
|
||||
"POSTGRES_PASSWORD": config.Password,
|
||||
},
|
||||
Networks: []string{network.Name},
|
||||
NetworkAliases: map[string][]string{
|
||||
network.Name: {alias},
|
||||
},
|
||||
ExposedPorts: []string{port.Port()},
|
||||
WaitingFor: wait.ForListeningPort(port),
|
||||
}
|
||||
|
||||
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
||||
ContainerRequest: req,
|
||||
Started: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to start container: %v", err)
|
||||
}
|
||||
|
||||
return &config, container
|
||||
}
|
||||
|
||||
type message struct {
|
||||
URL string
|
||||
Type string
|
||||
@@ -252,14 +193,14 @@ func assertMessageWait(t *testing.T, ctx context.Context, queue *queue, msgType
|
||||
}
|
||||
}
|
||||
|
||||
func createDependencies(t *testing.T, ctx context.Context) (*queue, func()) {
|
||||
func createQueueDependencies(t *testing.T, ctx context.Context) (*queue, func()) {
|
||||
network := createNetwork(t, ctx)
|
||||
|
||||
dbconfig, dbContainer := createDB(t, ctx, network)
|
||||
|
||||
queue := createQueue(t, ctx, network)
|
||||
|
||||
container := createContainer(t, ctx, containerConfig{
|
||||
container := createQueueContainer(t, ctx, &queueContainerConfig{
|
||||
Queue: *queue.Config,
|
||||
DB: dbconfig,
|
||||
Network: network,
|
||||
@@ -116,8 +116,11 @@ func TestQueue(t *testing.T) {
|
||||
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: SetResult :one").WithArgs(database.MustToDBUUID(querySixID), database.MustToDBUUID(docID), valueLayerOne, cleanVersion, textVersion, querySixVersion).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(pgtype.UUID{}),
|
||||
)
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
@@ -127,8 +130,11 @@ func TestQueue(t *testing.T) {
|
||||
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: SetResult :one").WithArgs(database.MustToDBUUID(queryFiveID), database.MustToDBUUID(docID), valueLayerTwo, cleanVersion, textVersion, queryFiveVersion).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(pgtype.UUID{}),
|
||||
)
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
@@ -138,8 +144,11 @@ func TestQueue(t *testing.T) {
|
||||
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: SetResult :one").WithArgs(database.MustToDBUUID(queryOneID), database.MustToDBUUID(docID), valueLayerOne, cleanVersion, textVersion, queryOneVersion).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(pgtype.UUID{}),
|
||||
)
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
@@ -149,8 +158,11 @@ func TestQueue(t *testing.T) {
|
||||
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: SetResult :one").WithArgs(database.MustToDBUUID(queryThreeID), database.MustToDBUUID(docID), valueLayerTwo, cleanVersion, textVersion, queryThreeVersion).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(pgtype.UUID{}),
|
||||
)
|
||||
|
||||
db.ExpectQuery("name: ListResultValuesByID :many").WithArgs(pgxmock.AnyArg()).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "value"}).
|
||||
@@ -160,8 +172,11 @@ func TestQueue(t *testing.T) {
|
||||
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))
|
||||
db.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(queryTwoID), database.MustToDBUUID(docID), valueLayerTwo, cleanVersion, textVersion, queryTwoVersion).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(pgtype.UUID{}),
|
||||
)
|
||||
|
||||
err = q.Execute(ctx)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -32,15 +33,18 @@ func TestStore(t *testing.T) {
|
||||
QueryVersion: int32(1),
|
||||
}
|
||||
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
db.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(pgtype.UUID{}),
|
||||
)
|
||||
|
||||
id, err := result.Store(ctx, queries, &resultStore)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, id)
|
||||
|
||||
errr := "database failing"
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
|
||||
db.ExpectQuery("name: SetResult :one").WithArgs(database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
|
||||
WillReturnError(fmt.Errorf(errr))
|
||||
|
||||
id, err = result.Store(ctx, queries, &resultStore)
|
||||
|
||||
Reference in New Issue
Block a user