Skip to content

Commit 20884b5

Browse files
willie-yaocpuguy83
authored andcommitted
Add test
Signed-off-by: William Yao <william2000yao@gmail.com>
1 parent c99c412 commit 20884b5

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

test/linux_target_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,78 @@ func main() {
23452345
})
23462346
})
23472347

2348+
t.Run("git source with keep git dir and gomod replace", func(t *testing.T) {
2349+
t.Parallel()
2350+
ctx := startTestSpan(baseCtx, t)
2351+
2352+
// Verifies that sources with a .git directory work with gomod replace.
2353+
opts := dalec.ProgressGroup("keepgitdir-gomod-replace")
2354+
2355+
contextSt := llb.Scratch().
2356+
File(llb.Mkfile("/go.mod", 0644, []byte("module example.com/test\n\ngo 1.18\n\nrequire github.com/stretchr/testify v1.9.0\n")), opts).
2357+
File(llb.Mkfile("/main.go", 0644, []byte(`package main
2358+
import (
2359+
"fmt"
2360+
"github.com/stretchr/testify/assert"
2361+
)
2362+
func main() {
2363+
fmt.Println("hello")
2364+
assert.True(nil, true)
2365+
}
2366+
`)), opts).
2367+
File(llb.Mkdir("/.git", 0755), opts).
2368+
File(llb.Mkfile("/.git/config", 0644, []byte("[core]\nrepositoryformatversion = 0\n")), opts).
2369+
File(llb.Mkfile("/.git/HEAD", 0644, []byte("ref: refs/heads/main\n")), opts)
2370+
2371+
const contextName = "keepgitdir-context"
2372+
spec := &dalec.Spec{
2373+
Name: "test-keepgitdir-gomod-replace",
2374+
Version: "0.0.1",
2375+
Revision: "1",
2376+
License: "MIT",
2377+
Website: "https://github.com/project-dalec/dalec",
2378+
Vendor: "Dalec",
2379+
Packager: "Dalec",
2380+
Description: "Testing keepGitDir with gomod replace directive",
2381+
Sources: map[string]dalec.Source{
2382+
"src": {
2383+
Context: &dalec.SourceContext{Name: contextName},
2384+
Generate: []*dalec.SourceGenerator{
2385+
{
2386+
Gomod: &dalec.GeneratorGomod{
2387+
Edits: &dalec.GomodEdits{
2388+
Replace: []dalec.GomodReplace{
2389+
{Original: "github.com/stretchr/testify", Update: "github.com/stretchr/testify@v1.8.0"},
2390+
},
2391+
},
2392+
},
2393+
},
2394+
},
2395+
},
2396+
},
2397+
Dependencies: &dalec.PackageDependencies{
2398+
Build: map[string]dalec.PackageConstraints{
2399+
testConfig.GetPackage("golang"): {},
2400+
},
2401+
},
2402+
Build: dalec.ArtifactBuild{
2403+
Steps: []dalec.BuildStep{
2404+
// Verify go.mod was patched with replace directive
2405+
{Command: "grep -F 'replace github.com/stretchr/testify' ./src/go.mod"},
2406+
{Command: "grep -F 'github.com/stretchr/testify v1.8.0' ./src/go.mod"},
2407+
// Use -buildvcs=false since we have a fake .git directory
2408+
{Command: "cd ./src && go build -buildvcs=false"},
2409+
},
2410+
},
2411+
}
2412+
2413+
testEnv.RunTest(ctx, t, func(ctx context.Context, client gwclient.Client) {
2414+
req := newSolveRequest(withBuildTarget(testConfig.Target.Container), withSpec(ctx, t, spec), withBuildContext(ctx, t, contextName, contextSt))
2415+
req.Evaluate = true
2416+
solveT(ctx, t, client, req)
2417+
})
2418+
})
2419+
23482420
t.Run("cargo home", func(t *testing.T) {
23492421
t.Parallel()
23502422
ctx := startTestSpan(baseCtx, t)

0 commit comments

Comments
 (0)