(ctx context.Context, t *testctx.T)
| 385 | } |
| 386 | |
| 387 | func (CLISuite) TestDaggerDevelop(ctx context.Context, t *testctx.T) { |
| 388 | t.Run("name and sdk", func(ctx context.Context, t *testctx.T) { |
| 389 | c := connect(ctx, t) |
| 390 | |
| 391 | base := c.Container().From(golangImage). |
| 392 | WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). |
| 393 | WithWorkdir("/work/dep"). |
| 394 | With(daggerExec("init", "--source=.", "--name=dep", "--sdk=go")). |
| 395 | WithNewFile("/work/dep/main.go", `package main |
| 396 | |
| 397 | import "context" |
| 398 | |
| 399 | type Dep struct {} |
| 400 | |
| 401 | func (m *Dep) Fn(ctx context.Context) string { |
| 402 | return "hi from dep" |
| 403 | } |
| 404 | `, |
| 405 | ). |
| 406 | WithWorkdir("/work"). |
| 407 | With(daggerExec("init", "--source=.")). |
| 408 | With(daggerExec("install", "./dep")) |
| 409 | |
| 410 | // should be able to invoke dep without name+sdk set yet |
| 411 | out, err := base.With(daggerCallAt("dep", "fn")).Stdout(ctx) |
| 412 | require.NoError(t, err) |
| 413 | require.Equal(t, "hi from dep", strings.TrimSpace(out)) |
| 414 | |
| 415 | // test develop from source root and from subdir (in which case find-up should kick in) |
| 416 | for _, wd := range []string{"/work", "/work/from/some/otherdir"} { |
| 417 | t.Run(wd, func(ctx context.Context, t *testctx.T) { |
| 418 | sourceDir, err := filepath.Rel(wd, "/work/cool/subdir") |
| 419 | require.NoError(t, err) |
| 420 | |
| 421 | ctr := base. |
| 422 | WithWorkdir(wd). |
| 423 | With(daggerExec("develop", "--sdk", "go", "--source", sourceDir)). |
| 424 | WithNewFile("/work/cool/subdir/main.go", `package main |
| 425 | |
| 426 | import "context" |
| 427 | |
| 428 | type Work struct {} |
| 429 | |
| 430 | func (m *Work) Fn(ctx context.Context) (string, error) { |
| 431 | depStr, err := dag.Dep().Fn(ctx) |
| 432 | if err != nil { |
| 433 | return "", err |
| 434 | } |
| 435 | return "hi from work " + depStr, nil |
| 436 | } |
| 437 | `, |
| 438 | ) |
| 439 | |
| 440 | // should be able to invoke it directly now |
| 441 | out, err := ctr.With(daggerCall("fn")).Stdout(ctx) |
| 442 | require.NoError(t, err) |
| 443 | require.Equal(t, "hi from work hi from dep", strings.TrimSpace(out)) |
| 444 |
nothing calls this directly
no test coverage detected