Fix input git to correctly handle subdir argument (solve #884)

Previously, the subdir argument wa ignored by dagger input git.
I've fix that behavior and add a test.

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-08-17 15:06:28 +02:00
parent 1e7c3cbc15
commit c637549b15
No known key found for this signature in database
GPG Key ID: 3C9847D981AAC1BF
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
}