Merge pull request #891 from TomChv/fix/input-git-subdir

Fix input git subdir argument
This commit is contained in:
Sam Alba 2021-08-19 20:30:15 +02:00 committed by GitHub
commit cb746e165f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 8 deletions

View File

@ -139,10 +139,16 @@ func (git gitInput) Compile(_ string, _ *State) (*compiler.Value, error) {
ref = git.Ref
}
dir := ""
if git.Dir != "" {
dir = fmt.Sprintf(`,{do:"subdir", dir:"%s"}`, git.Dir)
}
return compiler.Compile("", fmt.Sprintf(
`#up: [{do:"fetch-git", remote:"%s", ref:"%s"}]`,
`#up: [{do:"fetch-git", remote:"%s", ref:"%s"}%s]`,
git.Remote,
ref,
dir,
))
}

View File

@ -336,12 +336,15 @@ setup() {
@test "dagger input git" {
"$DAGGER" init
dagger_new_with_plan input "$TESTDIR"/cli/input/artifact
## Test simple input git
dagger_new_with_plan "input-simple-git" "$TESTDIR"/cli/input/artifact
# input git
"$DAGGER" input -e "input" git "source" https://github.com/samalba/dagger-test-simple.git
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input"
"$DAGGER" -e "input-simple-git" input list
"$DAGGER" -e "input-simple-git" input git source "https://github.com/samalba/dagger-test-simple"
"$DAGGER" -e "input-simple-git" input list
"$DAGGER" -e "input-simple-git" up --no-cache
run "$DAGGER" -l error query -e "input-simple-git"
assert_output '{
"bar": "testgit\n",
"foo": "bar",
@ -349,12 +352,21 @@ setup() {
}'
# unset input git
"$DAGGER" input -e "input" unset "source"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input"
"$DAGGER" input -e "input-simple-git" unset "source"
"$DAGGER" up -e "input-simple-git"
run "$DAGGER" -l error query -e "input-simple-git"
assert_output '{
"foo": "bar"
}'
## Test input git with subdir
dagger_new_with_plan "input-subdir-git" "$TESTDIR"/cli/input/git
# input git
"$DAGGER" -e "input-subdir-git" input git TestRepo "https://github.com/dagger/examples" "main" "todoapp"
# Assert success (test is directly in the cue file)
"$DAGGER" -e "input-subdir-git" up
}
@test "dagger input list" {

View File

@ -0,0 +1,18 @@
package testing
import (
"alpha.dagger.io/dagger"
"alpha.dagger.io/os"
)
// Input https://github.com/dagger/examples/tree/main/todoapp
TestRepo: dagger.#Input & {dagger.#Artifact}
// Check README.md
TestFolder: os.#Container & {
always: true
command: #"""
grep -q "Todo APP" /input/repo/README.md
"""#
mount: "/input/repo": from: TestRepo
}