From 1a15cbd30de0b62c4bed72e99f099bee781be56b Mon Sep 17 00:00:00 2001 From: fbuedding <100070891+fbuedding@users.noreply.github.com> Date: Mon, 18 Mar 2024 08:58:35 +0100 Subject: [PATCH] added integration tests --- docker-compose.yml | 56 ++++++++++++++++++++++++++++++++++++++++++++++ main_test.go | 8 ++++++- test.Dockerfile | 17 ++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml create mode 100644 test.Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4c6c456 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,56 @@ +version: "3" +services: + iot-agent-sdk-test: + environment: + - APP_ENV=test + - TEST_HOST=iot-agent1 + - LOG_LEVEL=DEBUG + - TZ:"Europe/Berlin" + build: + dockerfile: test.Dockerfile + context: ./ + ports: + - 8080:8080 + depends_on: + - iot-agent + - mongodb + - orion + iot-agent: + image: fiware/iotagent-ul:latest + hostname: iot-agent + depends_on: + - mongodb + expose: + - "4061" + - "7896" + ports: + - "4061:4061" + - "7896:7896" + environment: + - "IOTA_CB_HOST=orion" + - "IOTA_CB_PORT=1026" + - "IOTA_NORTH_PORT=4061" + - "IOTA_REGISTRY_TYPE=mongodb" + - "IOTA_MONGO_HOST=mongodb" + - "IOTA_MONGO_PORT=27017" + - "IOTA_MONGO_DB=iotagent-ul" + - "IOTA_HTTP_PORT=7896" + - "IOTA_PROVIDER_URL=http://iot-agent:4061" + mongodb: + image: mongo:4.2 + hostname: mongodb + ports: + - "27017:27017" + command: --bind_ip_all + orion: + image: fiware/orion + hostname: orion + depends_on: + - mongodb + expose: + - "1026" + ports: + - "1026:1026" + command: -dbhost mongodb + + diff --git a/main_test.go b/main_test.go index ecf92c5..a29d7e1 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,7 @@ package iotagentsdk_test import ( + "os" "testing" i "github.com/fbuedding/fiware-iot-agent-sdk" @@ -25,7 +26,12 @@ const ( ) func TestMain(m *testing.M) { - iota = i.IoTA{Host: "localhost", Port: 4061} + host := "localhost" + if os.Getenv("TEST_HOST") != "" { + host = os.Getenv("TEST_HOST") + } + log.Info().Msgf("Starting test with iot-agent host: %s", host) + iota = i.IoTA{Host: host, Port: 4061} fs = i.FiwareService{Service: service, ServicePath: servicePath} d = i.Device{Id: deviceId, EntityName: entityName} sg = i.ConfigGroup{ diff --git a/test.Dockerfile b/test.Dockerfile new file mode 100644 index 0000000..80f2193 --- /dev/null +++ b/test.Dockerfile @@ -0,0 +1,17 @@ +# Use the official Go image as a base image +FROM golang:latest + +# Set the working directory inside the container +WORKDIR /app + +# Copy the go mod and sum files +COPY go.mod go.sum ./ + +# Download all dependencies +RUN go mod download + +# Copy the source from the current directory to the working directory inside the container +COPY . . + +# Command to run the tests +CMD ["go", "test", "-v", "./..."]