Skip to content

Commit

Permalink
use extracted testctx package (dagger#9527)
Browse files Browse the repository at this point in the history
* use extracted testctx package

Signed-off-by: Alex Suraci <alex@dagger.io>

* preserve our custom span attrs

Signed-off-by: Alex Suraci <alex@dagger.io>

---------

Signed-off-by: Alex Suraci <alex@dagger.io>
  • Loading branch information
vito authored Feb 19, 2025
1 parent 4bb955c commit bf712c4
Show file tree
Hide file tree
Showing 51 changed files with 178 additions and 531 deletions.
2 changes: 1 addition & 1 deletion core/integration/cacert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"dagger.io/dagger"
"github.com/creack/pty"
"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/stretchr/testify/require"
)

Expand Down
4 changes: 2 additions & 2 deletions core/integration/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"github.com/stretchr/testify/require"

"dagger.io/dagger"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

type CacheSuite struct{}

func TestCache(t *testing.T) {
testctx.Run(testCtx, t, CacheSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(CacheSuite{})
}

func (CacheSuite) TestVolume(ctx context.Context, t *testctx.T) {
Expand Down
13 changes: 7 additions & 6 deletions core/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (
"github.com/koron-go/prefixw"
"github.com/moby/buildkit/identity"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel"

"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

type ClientSuite struct{}

func TestClient(t *testing.T) {
testctx.Run(testCtx, t, ClientSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(ClientSuite{})
}

func (ClientSuite) TestClose(ctx context.Context, t *testctx.T) {
Expand All @@ -29,7 +30,7 @@ func (ClientSuite) TestClose(ctx context.Context, t *testctx.T) {
}

func (ClientSuite) TestMultiSameTrace(ctx context.Context, t *testctx.T) {
rootCtx, span := Tracer().Start(ctx, "root")
rootCtx, span := otel.Tracer("dagger").Start(ctx, "root")
defer span.End()

newClient := func(ctx context.Context, name string) (*dagger.Client, *safeBuffer) {
Expand All @@ -41,7 +42,7 @@ func (ClientSuite) TestMultiSameTrace(ctx context.Context, t *testctx.T) {
return c, out
}

ctx1, span := Tracer().Start(rootCtx, "client 1")
ctx1, span := otel.Tracer("dagger").Start(rootCtx, "client 1")
defer span.End()
c1, out1 := newClient(ctx1, "client 1")

Expand Down Expand Up @@ -74,7 +75,7 @@ func (ClientSuite) TestMultiSameTrace(ctx context.Context, t *testctx.T) {
return strings.Contains(out1.String(), "echoed: "+c1msg)
}, timeout, 10*time.Millisecond)

ctx2, span := Tracer().Start(rootCtx, "client 2")
ctx2, span := otel.Tracer("dagger").Start(rootCtx, "client 2")
defer span.End()

// the timeout has to be established before connecting, so we apply it to c2
Expand All @@ -89,7 +90,7 @@ func (ClientSuite) TestMultiSameTrace(ctx context.Context, t *testctx.T) {
return strings.Contains(out2.String(), "echoed: "+c2msg)
}, timeout, 10*time.Millisecond)

ctx3, span := Tracer().Start(rootCtx, "client 3")
ctx3, span := otel.Tracer("dagger").Start(rootCtx, "client 3")
defer span.End()
timeoutCtx3, cancelTimeout := context.WithTimeout(ctx3, timeout)
defer cancelTimeout()
Expand Down
4 changes: 2 additions & 2 deletions core/integration/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import (
"github.com/dagger/dagger/engine/buildkit"
"github.com/dagger/dagger/engine/distconsts"
"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

type ContainerSuite struct{}

func TestContainer(t *testing.T) {
testctx.Run(testCtx, t, ContainerSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(ContainerSuite{})
}

func (ContainerSuite) TestScratch(ctx context.Context, t *testctx.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/integration/dind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

func (ContainerSuite) TestDIND(ctx context.Context, t *testctx.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/integration/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"dagger.io/dagger"
"github.com/dagger/dagger/core"
"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

type DirectorySuite struct{}

func TestDirectory(t *testing.T) {
testctx.Run(testCtx, t, DirectorySuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(DirectorySuite{})
}

func (DirectorySuite) TestEmpty(ctx context.Context, t *testctx.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/integration/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
"github.com/dagger/dagger/engine/config"
"github.com/dagger/dagger/engine/distconsts"
"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/stretchr/testify/require"
)

type EngineSuite struct{}

func TestEngine(t *testing.T) {
testctx.Run(testCtx, t, EngineSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(EngineSuite{})
}

func devEngineContainerAsService(ctr *dagger.Container) *dagger.Service {
Expand Down
4 changes: 2 additions & 2 deletions core/integration/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (
"github.com/dagger/dagger/engine/buildkit"
"github.com/dagger/dagger/engine/distconsts"
"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

type FileSuite struct{}

func TestFile(t *testing.T) {
testctx.Run(testCtx, t, FileSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(FileSuite{})
}

func (FileSuite) TestFile(ctx context.Context, t *testctx.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/integration/future_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"dagger.io/dagger"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

// FutureSuite contains tests for behavior changes that are "scheduled" - that
Expand All @@ -16,7 +16,7 @@ import (
type FutureSuite struct{}

func TestFuture(t *testing.T) {
testctx.Run(testCtx, t, FutureSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(FutureSuite{})
}

//nolint:unused
Expand Down
4 changes: 2 additions & 2 deletions core/integration/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (

"dagger.io/dagger"
"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

type GitSuite struct{}

func TestGit(t *testing.T) {
testctx.Run(testCtx, t, GitSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(GitSuite{})
}

func (GitSuite) TestGit(ctx context.Context, t *testctx.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/integration/gitcredential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"strings"
"testing"

"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/stretchr/testify/require"
)

type GitCredentialSuite struct{}

func TestGitCredential(t *testing.T) {
testctx.Run(testCtx, t, GitCredentialSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(GitCredentialSuite{})
}

// TestGitCredentialErrors verifies Git authentication for private modules across different providers
Expand Down
4 changes: 2 additions & 2 deletions core/integration/gpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/stretchr/testify/require"

"dagger.io/dagger"
Expand All @@ -18,7 +18,7 @@ import (
type GPUSuite struct{}

func TestGPU(t *testing.T) {
testctx.Run(testCtx, t, GPUSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(GPUSuite{})
}

const (
Expand Down
4 changes: 2 additions & 2 deletions core/integration/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/moby/buildkit/identity"
"github.com/stretchr/testify/require"

Expand All @@ -20,7 +20,7 @@ import (
type HostSuite struct{}

func TestHost(t *testing.T) {
testctx.Run(testCtx, t, HostSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(HostSuite{})
}

func (HostSuite) TestWorkdir(ctx context.Context, t *testctx.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/integration/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"testing"

"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/moby/buildkit/identity"
"github.com/stretchr/testify/require"

Expand All @@ -14,7 +14,7 @@ import (
type HTTPSuite struct{}

func TestHTTP(t *testing.T) {
testctx.Run(testCtx, t, HTTPSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(HTTPSuite{})
}

func (HTTPSuite) TestHTTP(ctx context.Context, t *testctx.T) {
Expand Down
5 changes: 2 additions & 3 deletions core/integration/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import (
"time"

"github.com/creack/pty"
"github.com/dagger/testctx"
"github.com/stretchr/testify/require"

"github.com/dagger/dagger/testctx"
)

// LegacySuite contains tests for module versioning compatibility
type LegacySuite struct{}

func TestLegacy(t *testing.T) {
testctx.Run(testCtx, t, LegacySuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(LegacySuite{})
}

func (LegacySuite) TestLegacyExportAbsolutePath(ctx context.Context, t *testctx.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/integration/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

"dagger.io/dagger"
"github.com/containerd/continuity/fs/fstest"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
)

type LocalDirSuite struct{}

func TestLocalDir(t *testing.T) {
testctx.Run(testCtx, t, LocalDirSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(LocalDirSuite{})
}

func (LocalDirSuite) TestLocalImportsAcrossSessions(ctx context.Context, t *testctx.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/integration/localcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"dagger.io/dagger"
"github.com/dagger/dagger/engine/config"
"github.com/dagger/dagger/internal/testutil"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
)

func (EngineSuite) TestLocalCacheGCDisabled(ctx context.Context, t *testctx.T) {
Expand Down
15 changes: 8 additions & 7 deletions core/integration/module_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import (
"time"

"github.com/dagger/dagger/core/modules"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/iancoleman/strcase"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
)

func BenchmarkModule(b *testing.B) {
testctx.Bench(testCtx, b, ModuleSuite{}, BenchMiddleware()...)
testctx.New(b, BenchMiddleware()...).RunBenchmarks(ModuleSuite{})
}

func (ModuleSuite) BenchmarkLotsOfFunctions(ctx context.Context, b *testctx.B) {
const funcCount = 100

b.Run("go sdk", func(ctx context.Context, b *testctx.B) {
for range testctx.N(b) {
for range b.Unwrap().N {
c := connect(ctx, b)

mainSrc := `
Expand Down Expand Up @@ -154,7 +154,7 @@ export class PotatoSack {
}

func (ModuleSuite) BenchmarkLotsOfDeps(ctx context.Context, b *testctx.B) {
for range testctx.N(b) {
for range b.Unwrap().N {
c := connect(ctx, b)

modGen := goGitBase(b, c).
Expand Down Expand Up @@ -247,11 +247,12 @@ func (ModuleSuite) BenchmarkLotsOfDeps(ctx context.Context, b *testctx.B) {

// make sure we don't hit any limits when an object field value is large
func (ModuleSuite) BenchmarkLargeObjectFieldVal(ctx context.Context, b *testctx.B) {
for range testctx.N(b) {
for range b.Unwrap().N {
c := connect(ctx, b)

// put a timeout on this since failures modes could result in hangs
b = b.WithTimeout(60 * time.Second)
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
b.Cleanup(cancel)

_, err := goGitBase(b, c).
WithMountedFile(testCLIBinPath, daggerCliFile(b, c)).
Expand Down Expand Up @@ -286,7 +287,7 @@ func (m *Test) Fn() string {
// regression test for https://github.com/dagger/dagger/issues/7334
// and https://github.com/dagger/dagger/pull/7336
func (ModuleSuite) BenchmarkCallSameModuleInParallel(ctx context.Context, b *testctx.B) {
for range testctx.N(b) {
for range b.Unwrap().N {
c := connect(ctx, b)

ctr := goGitBase(b, c).
Expand Down
4 changes: 2 additions & 2 deletions core/integration/module_call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/containerd/platforms"
"github.com/dagger/dagger/engine/distconsts"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/moby/buildkit/identity"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
Expand All @@ -25,7 +25,7 @@ import (
type CallSuite struct{}

func TestCall(t *testing.T) {
testctx.Run(testCtx, t, CallSuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(CallSuite{})
}

func (CallSuite) TestHelp(ctx context.Context, t *testctx.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/integration/module_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

"dagger.io/dagger"
"github.com/dagger/dagger/core/modules"
"github.com/dagger/dagger/testctx"
"github.com/dagger/testctx"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
)

type CLISuite struct{}

func TestCLI(t *testing.T) {
testctx.Run(testCtx, t, CLISuite{}, Middleware()...)
testctx.New(t, Middleware()...).RunTests(CLISuite{})
}

func (CLISuite) TestDaggerInit(ctx context.Context, t *testctx.T) {
Expand Down
Loading

0 comments on commit bf712c4

Please sign in to comment.