Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/goruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (p *Project) goRuntime(ctx context.Context, gw bkgw.Client, progSock *Socke
return nil, err
}

//nolint:goconst
workdir := "/src"
ctr, err = ctr.UpdateImageConfig(ctx, func(cfg specs.ImageConfig) specs.ImageConfig {
cfg.WorkingDir = absPath(cfg.WorkingDir, workdir)
Expand Down
39 changes: 26 additions & 13 deletions core/integration/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ func TestProjectCmd(t *testing.T) {
expectedName: "basic",
expectedRoot: "../../../../../../",
},
// TODO: add ts projects once those are under testdata too
{
projectPath: "core/integration/testdata/projects/typescript/basic",
expectedSDK: "typescript",
expectedName: "basic",
expectedRoot: "../../../../../../",
},
} {
tc := tc
for _, testGitProject := range []bool{false, true} {
Expand All @@ -55,7 +60,7 @@ func TestProjectCmd(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
defer c.Close()
output, err := CLITestContainer(ctx, t, c).
output, err := CLITestContainer(ctx, t, c, "").
WithLoadedProject(tc.projectPath, testGitProject).
CallProject().
Stderr(ctx)
Expand Down Expand Up @@ -134,7 +139,7 @@ func TestProjectCmdInit(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
defer c.Close()
ctr := CLITestContainer(ctx, t, c).
ctr := CLITestContainer(ctx, t, c, tc.sdk).
WithProjectArg(tc.projectPath).
WithSDKArg(tc.sdk).
WithNameArg(tc.name).
Expand Down Expand Up @@ -166,7 +171,7 @@ func TestProjectCmdInit(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
defer c.Close()
_, err := CLITestContainer(ctx, t, c).
_, err := CLITestContainer(ctx, t, c, "").
WithLoadedProject("core/integration/testdata/projects/go/basic", false).
WithSDKArg("go").
WithNameArg("foo").
Expand All @@ -187,15 +192,15 @@ func TestProjectCommandHierarchy(t *testing.T) {
c, ctx := connect(t)
defer c.Close()

output, err := CLITestContainer(ctx, t, c).
output, err := CLITestContainer(ctx, t, c, sdk).
WithLoadedProject(projectDir, false).
WithTarget("level-1:level-2:level-3:foo").
CallDo().
Stderr(ctx)
require.NoError(t, err)
require.Contains(t, output, "hello from foo")

output, err = CLITestContainer(ctx, t, c).
output, err = CLITestContainer(ctx, t, c, sdk).
WithLoadedProject(projectDir, false).
WithTarget("level-1:level-2:level-3:bar").
CallDo().
Expand Down Expand Up @@ -224,6 +229,10 @@ func TestProjectHostExport(t *testing.T) {
sdk: "python",
expectedMainFile: "main.py",
},
{
sdk: "typescript",
expectedMainFile: "index.mts",
},
} {
tc := tc
projectDir := fmt.Sprintf("core/integration/testdata/projects/%s/basic", tc.sdk)
Expand All @@ -242,7 +251,7 @@ func TestProjectHostExport(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
defer c.Close()
ctr, err := CLITestContainer(ctx, t, c).
ctr, err := CLITestContainer(ctx, t, c, tc.sdk).
WithLoadedProject(projectDir, testGitProject).
WithTarget("test-file").
WithUserArg("file-prefix", prefix).
Expand All @@ -261,7 +270,7 @@ func TestProjectHostExport(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
defer c.Close()
ctr, err := CLITestContainer(ctx, t, c).
ctr, err := CLITestContainer(ctx, t, c, tc.sdk).
WithLoadedProject(projectDir, testGitProject).
WithTarget("test-dir").
WithUserArg("dir-prefix", prefix).
Expand All @@ -288,7 +297,7 @@ func TestProjectHostExport(t *testing.T) {
defer c.Close()

outputPath := "/var/blahblah.txt"
ctr, err := CLITestContainer(ctx, t, c).
ctr, err := CLITestContainer(ctx, t, c, tc.sdk).
WithLoadedProject(projectDir, testGitProject).
WithTarget("test-file").
WithOutputArg(outputPath).
Expand All @@ -305,7 +314,7 @@ func TestProjectHostExport(t *testing.T) {
defer c.Close()

outputDir := "/var"
ctr, err := CLITestContainer(ctx, t, c).
ctr, err := CLITestContainer(ctx, t, c, tc.sdk).
WithLoadedProject(projectDir, testGitProject).
WithTarget("test-file").
WithOutputArg(outputDir).
Expand All @@ -322,7 +331,7 @@ func TestProjectHostExport(t *testing.T) {
defer c.Close()

outputDir := "/var"
ctr, err := CLITestContainer(ctx, t, c).
ctr, err := CLITestContainer(ctx, t, c, tc.sdk).
WithLoadedProject(projectDir, testGitProject).
WithTarget("test-dir").
WithOutputArg(outputDir).
Expand All @@ -345,7 +354,7 @@ func TestProjectHostExport(t *testing.T) {
c, ctx := connect(t)
defer c.Close()
outputDir := "/var"
ctr, err := CLITestContainer(ctx, t, c).
ctr, err := CLITestContainer(ctx, t, c, tc.sdk).
WithLoadedProject(projectDir, testGitProject).
WithTarget("test-export-local-dir").
WithOutputArg(outputDir).
Expand Down Expand Up @@ -378,6 +387,10 @@ func TestProjectDirImported(t *testing.T) {
sdk: "python",
expectedMainFile: "main.py",
},
{
sdk: "typescript",
expectedMainFile: "index.mts",
},
} {
tc := tc
projectDir := fmt.Sprintf("core/integration/testdata/projects/%s/basic", tc.sdk)
Expand All @@ -393,7 +406,7 @@ func TestProjectDirImported(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
defer c.Close()
output, err := CLITestContainer(ctx, t, c).
output, err := CLITestContainer(ctx, t, c, tc.sdk).
WithLoadedProject(projectDir, testGitProject).
WithTarget("test-imported-project-dir").
CallDo().
Expand Down
16 changes: 15 additions & 1 deletion core/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func lastNLines(str string, n int) string {

const testCLIBinPath = "/bin/dagger"

func CLITestContainer(ctx context.Context, t *testing.T, c *dagger.Client) *DaggerCLIContainer {
func CLITestContainer(ctx context.Context, t *testing.T, c *dagger.Client, language string) *DaggerCLIContainer {
t.Helper()
ctr := c.Container().From("alpine:3.16.2").
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
Expand All @@ -275,6 +275,7 @@ func CLITestContainer(ctx context.Context, t *testing.T, c *dagger.Client) *Dagg
ctx: ctx,
t: t,
c: c,
Language: language,
}
}

Expand All @@ -286,6 +287,7 @@ type DaggerCLIContainer struct {

// common
ProjectArg string
Language string

// "do"
OutputArg string
Expand Down Expand Up @@ -313,9 +315,21 @@ func (ctr DaggerCLIContainer) WithLoadedProject(
})
projectArg := filepath.Join(cliContainerRepoMntPath, projectPath)

// Build typescript library so it can be used within dagger integration test
if ctr.Language == "typescript" {
thisRepoDir = ctr.c.Container().
From("node:18-alpine").
WithDirectory("/src", thisRepoDir, dagger.ContainerWithDirectoryOpts{}).
WithExec([]string{"yarn", "--cwd", "/src/sdk/nodejs"}, dagger.ContainerWithExecOpts{SkipEntrypoint: true}).
WithExec([]string{"yarn", "--cwd", "/src/sdk/nodejs", "build"}, dagger.ContainerWithExecOpts{SkipEntrypoint: true}).
WithExec([]string{"rm", "/src/sdk/nodejs/.gitignore"}, dagger.ContainerWithExecOpts{SkipEntrypoint: true}).
Directory("/src")
}

baseCtr := ctr.Container
if convertToGitProject {
gitSvc, _ := gitService(ctr.ctx, ctr.t, ctr.c, thisRepoDir)

baseCtr = baseCtr.WithServiceBinding("git", gitSvc)

endpoint, err := gitSvc.Endpoint(ctr.ctx)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic",
"sdk": "typescript",
"root": "../../../../../../"
}
27 changes: 27 additions & 0 deletions core/integration/testdata/projects/typescript/basic/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fs from "fs"
import Client, { serveCommands, File, Directory } from "@dagger.io/dagger"

serveCommands(testFile, testDir, testExportLocalDir, testImportedProjectDir)

function testFile(client: Client, filePrefix: string): File {
const name = filePrefix + "foo.txt"

return client.directory().withNewFile(name, "foo\n").file(name)
}

function testDir(client: Client, dirPrefix: string): Directory {
return client.directory()
.withNewDirectory(dirPrefix + "subdir")
.withNewFile(dirPrefix + "subdir/subbar1.txt", "subbar1\n")
.withNewFile(dirPrefix + "subdir/subbar2.txt", "subbar2\n")
.withNewFile(dirPrefix + "bar1.txt", "bar1\n")
.withNewFile(dirPrefix + "bar2.txt", "bar2\n")
}

function testExportLocalDir(client: Client): Directory {
return client.host().directory("./core/integration/testdata/projects/typescript/basic")
}

function testImportedProjectDir(client: Client): string {
return fs.readdirSync(".").join("\n")
}
Loading