Skip to content

Commit

Permalink
chore: separate integration tests in its own packages (#277)
Browse files Browse the repository at this point in the history
Change the behavior of the code generation from `_integration-tests` to
generate individual test files in each test package.

This speeds up significantly when running only one test suite, which is
particularly useful when developing a new integration.

Also, this change is required for
#273, where we are testing
both `confluent-kafka-go` v1 and v2. Since both of them depend on CGO
`librdkafka`, they cannot coexist in the same package.
  • Loading branch information
rarguelloF authored Sep 18, 2024
1 parent deedc8b commit 7dac678
Show file tree
Hide file tree
Showing 39 changed files with 715 additions and 234 deletions.
8 changes: 8 additions & 0 deletions _integration-tests/integration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-present Datadog, Inc.

package integration

//go:generate go run ./utils/generator ./tests
19 changes: 19 additions & 0 deletions _integration-tests/tests/aws.v1/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions _integration-tests/tests/aws.v2/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions _integration-tests/tests/chi.v5/chi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
"context"
"fmt"
"net/http"
"orchestrion/integration/validator/trace"
"testing"
"time"

"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"orchestrion/integration/utils"
"orchestrion/integration/validator/trace"
)

type TestCase struct {
Expand All @@ -29,7 +31,7 @@ func (tc *TestCase) Setup(t *testing.T) {

//dd:ignore
tc.Server = &http.Server{
Addr: "127.0.0.1:8080",
Addr: "127.0.0.1:" + utils.GetFreePort(t),
Handler: router,
}

Expand Down
19 changes: 19 additions & 0 deletions _integration-tests/tests/chi.v5/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions _integration-tests/tests/dd-span/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions _integration-tests/tests/echo.v4/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ import (
"context"
"io"
"net/http"
"orchestrion/integration/validator/trace"
"testing"
"time"

"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"orchestrion/integration/utils"
"orchestrion/integration/validator/trace"
)

type TestCase struct {
*echo.Echo
addr string
}

func (tc *TestCase) Setup(t *testing.T) {
Expand All @@ -31,12 +34,13 @@ func (tc *TestCase) Setup(t *testing.T) {
tc.Echo.GET("/ping", func(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]any{"message": "pong"})
})
tc.addr = "127.0.0.1:" + utils.GetFreePort(t)

go func() { assert.ErrorIs(t, tc.Echo.Start("127.0.0.1:8080"), http.ErrServerClosed) }()
go func() { assert.ErrorIs(t, tc.Echo.Start(tc.addr), http.ErrServerClosed) }()
}

func (*TestCase) Run(t *testing.T) {
resp, err := http.Get("http://127.0.0.1:8080/ping")
func (tc *TestCase) Run(t *testing.T) {
resp, err := http.Get("http://" + tc.addr + "/ping")
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
}
Expand All @@ -48,7 +52,7 @@ func (tc *TestCase) Teardown(t *testing.T) {
require.NoError(t, tc.Echo.Shutdown(ctx))
}

func (*TestCase) ExpectedTraces() trace.Spans {
func (tc *TestCase) ExpectedTraces() trace.Spans {
return trace.Spans{
{
// NB: Top-level span is from the HTTP Client, which is library-side instrumented.
Expand All @@ -66,7 +70,7 @@ func (*TestCase) ExpectedTraces() trace.Spans {
"type": "web",
},
Meta: map[string]any{
"http.url": "http://127.0.0.1:8080/ping",
"http.url": "http://" + tc.addr + "/ping",
},
},
},
Expand Down
19 changes: 19 additions & 0 deletions _integration-tests/tests/echo.v4/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions _integration-tests/tests/fiber.v2/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@ package fiber

import (
"net/http"
"orchestrion/integration/validator/trace"
"testing"
"time"

"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"orchestrion/integration/utils"
"orchestrion/integration/validator/trace"
)

type TestCase struct {
*fiber.App
addr string
}

func (tc *TestCase) Setup(t *testing.T) {
tc.App = fiber.New(fiber.Config{DisableStartupMessage: true})
tc.App.Get("/ping", func(c *fiber.Ctx) error { return c.JSON(map[string]any{"message": "pong"}) })
go func() { assert.NoError(t, tc.App.Listen("127.0.0.1:8080")) }()
tc.addr = "127.0.0.1:" + utils.GetFreePort(t)

go func() { assert.NoError(t, tc.App.Listen(tc.addr)) }()
}

func (*TestCase) Run(t *testing.T) {
resp, err := http.Get("http://127.0.0.1:8080/ping")
func (tc *TestCase) Run(t *testing.T) {
resp, err := http.Get("http://" + tc.addr + "/ping")
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
}
Expand All @@ -38,7 +43,7 @@ func (tc *TestCase) Teardown(t *testing.T) {
require.NoError(t, tc.App.ShutdownWithTimeout(time.Second))
}

func (*TestCase) ExpectedTraces() trace.Spans {
func (tc *TestCase) ExpectedTraces() trace.Spans {
return trace.Spans{
{
// NB: Top-level span is from the HTTP Client, which is library-side instrumented.
Expand All @@ -48,7 +53,7 @@ func (*TestCase) ExpectedTraces() trace.Spans {
"type": "http",
},
Meta: map[string]any{
"http.url": "http://127.0.0.1:8080/ping",
"http.url": "http://" + tc.addr + "/ping",
},
Children: trace.Spans{
{
Expand Down
19 changes: 19 additions & 0 deletions _integration-tests/tests/fiber.v2/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions _integration-tests/tests/gin/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions _integration-tests/tests/gin/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ package gin
import (
"context"
"net/http"
"orchestrion/integration/validator/trace"
"testing"
"time"

"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"orchestrion/integration/utils"
"orchestrion/integration/validator/trace"
)

type TestCase struct {
Expand All @@ -28,7 +30,7 @@ func (tc *TestCase) Setup(t *testing.T) {
engine := gin.New()

tc.Server = &http.Server{
Addr: "127.0.0.1:8080",
Addr: "127.0.0.1:" + utils.GetFreePort(t),
Handler: engine.Handler(),
}

Expand All @@ -37,8 +39,8 @@ func (tc *TestCase) Setup(t *testing.T) {
go func() { assert.ErrorIs(t, tc.Server.ListenAndServe(), http.ErrServerClosed) }()
}

func (*TestCase) Run(t *testing.T) {
resp, err := http.Get("http://127.0.0.1:8080/ping")
func (tc *TestCase) Run(t *testing.T) {
resp, err := http.Get("http://" + tc.Server.Addr + "/ping")
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
}
Expand All @@ -50,7 +52,7 @@ func (tc *TestCase) Teardown(t *testing.T) {
require.NoError(t, tc.Server.Shutdown(ctx))
}

func (*TestCase) ExpectedTraces() trace.Spans {
func (tc *TestCase) ExpectedTraces() trace.Spans {
return trace.Spans{
{
// NB: Top-level span is from the HTTP Client, which is library-side instrumented.
Expand All @@ -60,7 +62,7 @@ func (*TestCase) ExpectedTraces() trace.Spans {
"type": "http",
},
Meta: map[string]any{
"http.url": "http://127.0.0.1:8080/ping",
"http.url": "http://" + tc.Server.Addr + "/ping",
},
Children: trace.Spans{
{
Expand All @@ -70,7 +72,7 @@ func (*TestCase) ExpectedTraces() trace.Spans {
"type": "web",
},
Meta: map[string]any{
"http.url": "http://127.0.0.1:8080/ping",
"http.url": "http://" + tc.Server.Addr + "/ping",
},
},
},
Expand Down
19 changes: 19 additions & 0 deletions _integration-tests/tests/go-redis.v7/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7dac678

Please sign in to comment.