basicintegrationsetup
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"gotemplate/api/grpc/spec"
|
"gotemplate/api/grpc/spec"
|
||||||
"gotemplate/internal/database"
|
"gotemplate/internal/database"
|
||||||
"gotemplate/internal/database/repository"
|
"gotemplate/internal/database/repository"
|
||||||
"gotemplate/internal/name"
|
|
||||||
"gotemplate/internal/otel"
|
"gotemplate/internal/otel"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|||||||
+2
-2
@@ -8,9 +8,9 @@ vars:
|
|||||||
tasks:
|
tasks:
|
||||||
lint:
|
lint:
|
||||||
cmds:
|
cmds:
|
||||||
- godolint {{.DOCKERFILE_DIR_WITH_CONTEXT}}/grpc/Dockerfile
|
#- godolint {{.DOCKERFILE_DIR_WITH_CONTEXT}}/grpc/Dockerfile
|
||||||
- godolint {{.DOCKERFILE_DIR_WITH_CONTEXT}}/queue/Dockerfile
|
- godolint {{.DOCKERFILE_DIR_WITH_CONTEXT}}/queue/Dockerfile
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- docker build -t {{.IMAGE_NAME}}_grpc -f {{.DOCKERFILE_DIR_WITH_CONTEXT}}/grpc/Dockerfile {{.CONTEXT}}
|
#- docker build -t {{.IMAGE_NAME}}_grpc -f {{.DOCKERFILE_DIR_WITH_CONTEXT}}/grpc/Dockerfile {{.CONTEXT}}
|
||||||
- docker build -t {{.IMAGE_NAME}}_queue -f {{.DOCKERFILE_DIR_WITH_CONTEXT}}/queue/Dockerfile {{.CONTEXT}}
|
- docker build -t {{.IMAGE_NAME}}_queue -f {{.DOCKERFILE_DIR_WITH_CONTEXT}}/queue/Dockerfile {{.CONTEXT}}
|
||||||
@@ -19,7 +19,7 @@ type containerConfig struct {
|
|||||||
Network *testcontainers.DockerNetwork
|
Network *testcontainers.DockerNetwork
|
||||||
}
|
}
|
||||||
|
|
||||||
func createContainer(t *testing.T, ctx context.Context, config *containerConfig) (*grpc.ClientConn, testcontainers.Container) {
|
func createContainer(t *testing.T, ctx context.Context, config *containerConfig) (*grpc.ClientConn, func()) {
|
||||||
port, err := nat.NewPort("tcp", "8080")
|
port, err := nat.NewPort("tcp", "8080")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create port: %v", err)
|
t.Fatalf("Failed to create port: %v", err)
|
||||||
@@ -70,7 +70,9 @@ func createContainer(t *testing.T, ctx context.Context, config *containerConfig)
|
|||||||
t.Fatalf("Failed to connect to gRPC server: %v", err)
|
t.Fatalf("Failed to connect to gRPC server: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn, container
|
return conn, func() {
|
||||||
|
container.Terminate(ctx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type dbConfig struct {
|
type dbConfig struct {
|
||||||
@@ -130,3 +132,21 @@ func createNetwork(t *testing.T, ctx context.Context) *testcontainers.DockerNetw
|
|||||||
|
|
||||||
return network
|
return network
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createDependencies(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{
|
||||||
|
DB: *dbconfig,
|
||||||
|
Network: network,
|
||||||
|
})
|
||||||
|
|
||||||
|
return conn, func() {
|
||||||
|
testcontainers.CleanupNetwork(t, network)
|
||||||
|
dbContainer.Terminate(ctx)
|
||||||
|
containerCleanup()
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,24 +7,13 @@ import (
|
|||||||
"gotemplate/api/grpc/spec"
|
"gotemplate/api/grpc/spec"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/testcontainers/testcontainers-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestName(t *testing.T) {
|
func TestName(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
network := createNetwork(t, ctx)
|
conn, cleanup := createDependencies(t, ctx)
|
||||||
defer testcontainers.CleanupNetwork(t, network)
|
defer cleanup()
|
||||||
|
|
||||||
dbconfig, dbContainer := createDB(t, ctx, network)
|
|
||||||
defer dbContainer.Terminate(ctx)
|
|
||||||
|
|
||||||
conn, container := createContainer(t, ctx, &containerConfig{
|
|
||||||
DB: *dbconfig,
|
|
||||||
Network: network,
|
|
||||||
})
|
|
||||||
defer container.Terminate(ctx)
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
client := spec.NewNameClient(conn)
|
client := spec.NewNameClient(conn)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
"github.com/aws/aws-sdk-go-v2/config"
|
"github.com/aws/aws-sdk-go-v2/config"
|
||||||
@@ -12,6 +13,7 @@ import (
|
|||||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/testcontainers/testcontainers-go"
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/network"
|
"github.com/testcontainers/testcontainers-go/network"
|
||||||
"github.com/testcontainers/testcontainers-go/wait"
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
@@ -236,3 +238,43 @@ func sendMessage(t *testing.T, ctx context.Context, queue *sqs.Client, message m
|
|||||||
t.Fatalf("Failed to send message: %v", err)
|
t.Fatalf("Failed to send message: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func assertMessageWait(t *testing.T, ctx context.Context, queue *queue, msgType string) {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
|
result, err := queue.Client.ReceiveMessage(ctx, &sqs.ReceiveMessageInput{
|
||||||
|
QueueUrl: &queue.Config.URL,
|
||||||
|
MaxNumberOfMessages: 1,
|
||||||
|
WaitTimeSeconds: 5,
|
||||||
|
VisibilityTimeout: 2,
|
||||||
|
MessageAttributeNames: []string{
|
||||||
|
"type",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.Nil(t, err)
|
||||||
|
for _, message := range result.Messages {
|
||||||
|
assert.Equal(t, msgType, *message.MessageAttributes["type"].StringValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func createDependencies(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{
|
||||||
|
Queue: *queue.Config,
|
||||||
|
DB: dbconfig,
|
||||||
|
Network: network,
|
||||||
|
})
|
||||||
|
|
||||||
|
return queue, func() {
|
||||||
|
testcontainers.CleanupNetwork(t, network)
|
||||||
|
dbContainer.Terminate(ctx)
|
||||||
|
(*queue.Container).Terminate(ctx)
|
||||||
|
container.Terminate(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
package queue_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/testcontainers/testcontainers-go"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestName(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
network := createNetwork(t, ctx)
|
|
||||||
defer testcontainers.CleanupNetwork(t, network)
|
|
||||||
|
|
||||||
dbconfig, dbContainer := createDB(t, ctx, network)
|
|
||||||
defer dbContainer.Terminate(ctx)
|
|
||||||
|
|
||||||
queue := createQueue(t, ctx, network)
|
|
||||||
defer (*queue.Container).Terminate(ctx)
|
|
||||||
|
|
||||||
container := createContainer(t, ctx, containerConfig{
|
|
||||||
Queue: *queue.Config,
|
|
||||||
DB: dbconfig,
|
|
||||||
Network: network,
|
|
||||||
})
|
|
||||||
defer container.Terminate(ctx)
|
|
||||||
|
|
||||||
sendMessage(t, ctx, queue.Client, message{
|
|
||||||
URL: queue.Config.URL,
|
|
||||||
Type: "CREATE_NAME",
|
|
||||||
Body: "{\"name\":\"Doczy.ai\"}",
|
|
||||||
})
|
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
|
|
||||||
result, err := queue.Client.ReceiveMessage(ctx, &sqs.ReceiveMessageInput{
|
|
||||||
QueueUrl: &queue.Config.URL,
|
|
||||||
MaxNumberOfMessages: 1,
|
|
||||||
WaitTimeSeconds: 5,
|
|
||||||
VisibilityTimeout: 2,
|
|
||||||
MessageAttributeNames: []string{
|
|
||||||
"type",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.Nil(t, err)
|
|
||||||
for _, message := range result.Messages {
|
|
||||||
assert.Equal(t, "CREATE_NAME_SUCCESS", *message.MessageAttributes["type"].StringValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package queue_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"gotemplate/internal/document"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestName(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
queue, cleanup := createDependencies(t, ctx)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
document := document.Document{
|
||||||
|
ID: uuid.New(),
|
||||||
|
JobID: uuid.New(),
|
||||||
|
Name: "document_name",
|
||||||
|
CleanVersion: int32(1),
|
||||||
|
TextVersion: int32(1),
|
||||||
|
}
|
||||||
|
docJson, err := json.Marshal(document)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
sendMessage(t, ctx, queue.Client, message{
|
||||||
|
URL: queue.Config.URL,
|
||||||
|
Type: "DOCTEXT",
|
||||||
|
Body: string(docJson),
|
||||||
|
})
|
||||||
|
|
||||||
|
assertMessageWait(t, ctx, queue, "DOCQUERY")
|
||||||
|
}
|
||||||
@@ -48,6 +48,36 @@ func TestJSONProcess(t *testing.T) {
|
|||||||
value, err := extractor.Process(ctx, queryID, queryVersion, values)
|
value, err := extractor.Process(ctx, queryID, queryVersion, values)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, entryValue, value)
|
assert.Equal(t, entryValue, value)
|
||||||
|
|
||||||
|
entryValue = ""
|
||||||
|
jsonString = fmt.Sprintf("{\"key\": \"%s\"}", entryValue)
|
||||||
|
values = &[]result.Value{
|
||||||
|
{ID: uuid.New(), QueryID: uuid.New(), Value: jsonString},
|
||||||
|
}
|
||||||
|
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||||
|
WillReturnRows(
|
||||||
|
pgxmock.NewRows([]string{"id", "config"}).
|
||||||
|
AddRow(pgtype.UUID{}, []byte(config)),
|
||||||
|
)
|
||||||
|
|
||||||
|
value, err = extractor.Process(ctx, queryID, queryVersion, values)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, entryValue, value)
|
||||||
|
|
||||||
|
entryValue = "1"
|
||||||
|
jsonString = fmt.Sprintf("{\"key\": %s", entryValue)
|
||||||
|
values = &[]result.Value{
|
||||||
|
{ID: uuid.New(), QueryID: uuid.New(), Value: jsonString},
|
||||||
|
}
|
||||||
|
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||||
|
WillReturnRows(
|
||||||
|
pgxmock.NewRows([]string{"id", "config"}).
|
||||||
|
AddRow(pgtype.UUID{}, []byte(config)),
|
||||||
|
)
|
||||||
|
|
||||||
|
value, err = extractor.Process(ctx, queryID, queryVersion, values)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, entryValue, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONProcessJSON(t *testing.T) {
|
func TestJSONProcessJSON(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user