Skip to content

Go demonstration app on how to use Microcks Testcontainers in your dev/test workflow

License

Notifications You must be signed in to change notification settings

microcks/microcks-testcontainers-go-demo

Repository files navigation

microcks-testcontainers-go-demo

Go demonstration app on how to use Microcks Testcontainers in your dev/test workflow

Basic commands

Start launching Microcks locally:

$ ./microcks.sh
==== OUTPUT ====
[...]

In another terminal, run the application:

$ go run cmd/main.go
==== OUTPUT ====
Starting Microcks TestContainers Go Demo application...
%4|1717762091.102|CONFWARN|rdkafka#producer-2| [thrd:app]: Configuration property group.id is a consumer property and will be ignored by this producer instance
%4|1717762091.102|CONFWARN|rdkafka#producer-2| [thrd:app]: Configuration property auto.offset.reset is a consumer property and will be ignored by this producer instance
Consumed event from topic OrderEventsAPI-0.1.0-orders-reviewed: key = 1717760701042 value = {"timestamp":1706087114133,"order":{"id":"123-456-789","customerId":"lbroudoux","status":"VALIDATED","productQuantities":[{"productName":"Croissant","quantity":1},{"productName":"Pain Chocolat","quantity":1}],"totalPrice":4.2},"changeReason":"Validation"}
[...]

In a third terminal, call the API:

Successful call

$ curl -XPOST localhost:9000/api/orders -H 'Content-Type: application/json' \ 
    -d '{"customerId": "lbroudoux", "productQuantities": [{"productName": "Millefeuille", "quantity": 1}], "totalPrice": 5.1}' -s | jq .
==== OUTPUT ====
{
  "customerId": "lbroudoux",
  "productQuantities": [
    {
      "productName": "Millefeuille",
      "quantity": 1
    }
  ],
  "totalPrice": 5.1,
  "id": "dded1111-8e99-4ba7-8755-e718972480e3",
  "status": "CREATED"
}

Error call

$ curl -XPOST localhost:9000/api/orders -H 'Content-Type: application/json' \ 
    -d '{"customerId": "lbroudoux", "productQuantities": [{"productName": "Eclair Chocolat", "quantity": 1}], "totalPrice": 5.1}' -s | jq .
==== OUTPUT ====
{
  "productName": "Eclair Chocolat",
  "details": "Pastry Eclair Chocolat is not available"
}

Running tests

$ go test -timeout 30s -run ^TestGetPastry$ github.com/microcks/microcks-testcontainers-go-demo/internal/client

=== RUN   TestGetPastry
2024/06/07 09:14:32 🐳 Creating container for image testcontainers/ryuk:0.7.0
2024/06/07 09:14:32 ✅ Container created: 409c6c59e370
2024/06/07 09:14:32 🐳 Starting container: 409c6c59e370
2024/06/07 09:14:33 ✅ Container started: 409c6c59e370
2024/06/07 09:14:33 🚧 Waiting for container id 409c6c59e370 image: testcontainers/ryuk:0.7.0. Waiting for: &{Port:8080/tcp timeout:<nil> PollInterval:100ms}
2024/06/07 09:14:33 🔔 Container is ready: 409c6c59e370
2024/06/07 09:14:33 🐳 Creating container for image quay.io/microcks/microcks-uber:1.9.0-native
2024/06/07 09:14:33 ✅ Container created: 5bc535cc9b57
2024/06/07 09:14:33 🐳 Starting container: 5bc535cc9b57
2024/06/07 09:14:33 ✅ Container started: 5bc535cc9b57
2024/06/07 09:14:33 🚧 Waiting for container id 5bc535cc9b57 image: quay.io/microcks/microcks-uber:1.9.0-native. Waiting for: &{timeout:<nil> Log:Started MicrocksApplication IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/06/07 09:14:35 🔔 Container is ready: 5bc535cc9b57
2024/06/07 09:14:35 🐳 Terminating container: 5bc535cc9b57
2024/06/07 09:14:35 🚫 Container terminated: 5bc535cc9b57
--- PASS: TestGetPastry (3.46s)
PASS
ok      github.com/microcks/microcks-testcontainers-go-demo/internal/client     (cached)
go test -timeout 30s -run ^TestListPastries$ github.com/microcks/microcks-testcontainers-go-demo/internal/client

=== RUN   TestListPastries
2024/06/07 09:14:46 🐳 Creating container for image testcontainers/ryuk:0.7.0
2024/06/07 09:14:46 ✅ Container created: 7260f7bb8990
2024/06/07 09:14:46 🐳 Starting container: 7260f7bb8990
2024/06/07 09:14:46 ✅ Container started: 7260f7bb8990
2024/06/07 09:14:46 🚧 Waiting for container id 7260f7bb8990 image: testcontainers/ryuk:0.7.0. Waiting for: &{Port:8080/tcp timeout:<nil> PollInterval:100ms}
2024/06/07 09:14:47 🔔 Container is ready: 7260f7bb8990
2024/06/07 09:14:47 🐳 Creating container for image quay.io/microcks/microcks-uber:1.9.0-native
2024/06/07 09:14:47 ✅ Container created: 7ae147635552
2024/06/07 09:14:47 🐳 Starting container: 7ae147635552
2024/06/07 09:14:47 ✅ Container started: 7ae147635552
2024/06/07 09:14:47 🚧 Waiting for container id 7ae147635552 image: quay.io/microcks/microcks-uber:1.9.0-native. Waiting for: &{timeout:<nil> Log:Started MicrocksApplication IsRegexp:false Occurrence:1 PollInterval:100ms}
2024/06/07 09:14:47 🔔 Container is ready: 7ae147635552
2024/06/07 09:14:47 🐳 Terminating container: 7ae147635552
2024/06/07 09:14:47 🚫 Container terminated: 7ae147635552
--- PASS: TestListPastries (1.22s)
PASS
ok      github.com/microcks/microcks-testcontainers-go-demo/internal/client     (cached)

About

Go demonstration app on how to use Microcks Testcontainers in your dev/test workflow

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published