dagger: unset input tests
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
ced9ab07e5
commit
13b0debbd0
@ -80,20 +80,3 @@ func readInput(ctx context.Context, source string) string {
|
|||||||
|
|
||||||
return string(data)
|
return string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeEnvironmentInput(ctx context.Context, key string) {
|
|
||||||
lg := log.Ctx(ctx)
|
|
||||||
|
|
||||||
store, err := dagger.DefaultStore()
|
|
||||||
if err != nil {
|
|
||||||
lg.Fatal().Err(err).Msg("failed to load store")
|
|
||||||
}
|
|
||||||
|
|
||||||
st := common.GetCurrentEnvironmentState(ctx, store)
|
|
||||||
st.RemoveInputs(key)
|
|
||||||
|
|
||||||
if err := store.UpdateEnvironment(ctx, st, nil); err != nil {
|
|
||||||
lg.Fatal().Err(err).Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("cannot update environment")
|
|
||||||
}
|
|
||||||
lg.Info().Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("updated environment")
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package input
|
package input
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"dagger.io/go/cmd/dagger/cmd/common"
|
||||||
"dagger.io/go/cmd/dagger/logger"
|
"dagger.io/go/cmd/dagger/logger"
|
||||||
|
"dagger.io/go/dagger"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@ -21,6 +23,17 @@ var unsetCmd = &cobra.Command{
|
|||||||
lg := logger.New()
|
lg := logger.New()
|
||||||
ctx := lg.WithContext(cmd.Context())
|
ctx := lg.WithContext(cmd.Context())
|
||||||
|
|
||||||
removeEnvironmentInput(ctx, args[0])
|
store, err := dagger.DefaultStore()
|
||||||
|
if err != nil {
|
||||||
|
lg.Fatal().Err(err).Msg("failed to load store")
|
||||||
|
}
|
||||||
|
|
||||||
|
st := common.GetCurrentEnvironmentState(ctx, store)
|
||||||
|
st.RemoveInputs(args[0])
|
||||||
|
|
||||||
|
if err := store.UpdateEnvironment(ctx, st, nil); err != nil {
|
||||||
|
lg.Fatal().Err(err).Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("cannot update environment")
|
||||||
|
}
|
||||||
|
lg.Info().Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("updated environment")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,13 @@ setup() {
|
|||||||
assert_success
|
assert_success
|
||||||
assert_output '"my input"'
|
assert_output '"my input"'
|
||||||
|
|
||||||
|
# unset simple input
|
||||||
|
"$DAGGER" input -e "input" unset "input"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" input
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
# nested input
|
# nested input
|
||||||
"$DAGGER" input -e "input" text "nested.input" "nested input"
|
"$DAGGER" input -e "input" text "nested.input" "nested input"
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
@ -128,6 +135,13 @@ setup() {
|
|||||||
"input": "nested input"
|
"input": "nested input"
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset nested input
|
||||||
|
"$DAGGER" input -e "input" unset "nested.input"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" nested
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
# file input
|
# file input
|
||||||
"$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/input.txt
|
"$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/input.txt
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
@ -135,6 +149,13 @@ setup() {
|
|||||||
assert_success
|
assert_success
|
||||||
assert_output '"from file\n"'
|
assert_output '"from file\n"'
|
||||||
|
|
||||||
|
# unset file input
|
||||||
|
"$DAGGER" input -e "input" unset "input"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" input
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
# invalid file
|
# invalid file
|
||||||
run "$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/notexist
|
run "$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/notexist
|
||||||
assert_failure
|
assert_failure
|
||||||
@ -145,11 +166,19 @@ setup() {
|
|||||||
run "$DAGGER" -l error query -e "input" input
|
run "$DAGGER" -l error query -e "input" input
|
||||||
assert_success
|
assert_success
|
||||||
assert_output '"from stdin"'
|
assert_output '"from stdin"'
|
||||||
|
|
||||||
|
# unset stdin input
|
||||||
|
"$DAGGER" input -e "input" unset "input"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" input
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input json" {
|
@test "dagger input json" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
|
||||||
|
|
||||||
|
# simple json
|
||||||
"$DAGGER" input -e "input" json "structured" '{"a": "foo", "b": 42}'
|
"$DAGGER" input -e "input" json "structured" '{"a": "foo", "b": 42}'
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input" structured
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
@ -159,6 +188,14 @@ setup() {
|
|||||||
"b": 42
|
"b": 42
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset simple json
|
||||||
|
"$DAGGER" input -e "input" unset "structured"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
|
# json from file
|
||||||
"$DAGGER" input -e "input" json "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.json
|
"$DAGGER" input -e "input" json "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.json
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input" structured
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
@ -167,11 +204,19 @@ setup() {
|
|||||||
"a": "from file",
|
"a": "from file",
|
||||||
"b": 42
|
"b": 42
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset json from file
|
||||||
|
"$DAGGER" input -e "input" unset "structured"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input yaml" {
|
@test "dagger input yaml" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
|
||||||
|
|
||||||
|
# simple yaml
|
||||||
"$DAGGER" input -e "input" yaml "structured" '{"a": "foo", "b": 42}'
|
"$DAGGER" input -e "input" yaml "structured" '{"a": "foo", "b": 42}'
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input" structured
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
@ -181,6 +226,14 @@ setup() {
|
|||||||
"b": 42
|
"b": 42
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset simple yaml
|
||||||
|
"$DAGGER" input -e "input" unset "structured"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
|
# yaml from file
|
||||||
"$DAGGER" input -e "input" yaml "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.yaml
|
"$DAGGER" input -e "input" yaml "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.yaml
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input" structured
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
@ -189,11 +242,19 @@ setup() {
|
|||||||
"a": "from file",
|
"a": "from file",
|
||||||
"b": 42
|
"b": 42
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset yaml from file
|
||||||
|
"$DAGGER" input -e "input" unset "structured"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input dir" {
|
@test "dagger input dir" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
||||||
|
|
||||||
|
# input dir
|
||||||
"$DAGGER" input -e "input" dir "source" "$TESTDIR"/cli/input/artifact/testdata
|
"$DAGGER" input -e "input" dir "source" "$TESTDIR"/cli/input/artifact/testdata
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input"
|
run "$DAGGER" -l error query -e "input"
|
||||||
@ -203,11 +264,21 @@ setup() {
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"source": {}
|
"source": {}
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset dir
|
||||||
|
"$DAGGER" input -e "input" unset "source"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input"
|
||||||
|
assert_success
|
||||||
|
assert_output '{
|
||||||
|
"foo": "bar"
|
||||||
|
}'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input git" {
|
@test "dagger input git" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
||||||
|
|
||||||
|
# input git
|
||||||
"$DAGGER" input -e "input" git "source" https://github.com/samalba/dagger-test-simple.git
|
"$DAGGER" input -e "input" git "source" https://github.com/samalba/dagger-test-simple.git
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input"
|
run "$DAGGER" -l error query -e "input"
|
||||||
@ -216,11 +287,20 @@ setup() {
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"source": {}
|
"source": {}
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset input git
|
||||||
|
"$DAGGER" input -e "input" unset "source"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input"
|
||||||
|
assert_output '{
|
||||||
|
"foo": "bar"
|
||||||
|
}'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input scan" {
|
@test "dagger input scan" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/scan "scan"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/scan "scan"
|
||||||
|
|
||||||
|
# TODO "scan" option isn't implemented
|
||||||
run "$DAGGER" input scan -e "input"
|
run "$DAGGER" input scan -e "input"
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user