tests: add basic cli tests
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
48e8b200ae
commit
429820036f
@ -208,7 +208,10 @@ func (v *Value) Source(opts ...cue.Option) ([]byte, error) {
|
||||
v.cc.rlock()
|
||||
defer v.cc.runlock()
|
||||
|
||||
return cueformat.Node(v.val.Eval().Syntax(opts...))
|
||||
return cueformat.Node(v.val.Eval().Syntax(opts...),
|
||||
cueformat.UseSpaces(4),
|
||||
cueformat.TabIndent(false),
|
||||
)
|
||||
}
|
||||
|
||||
func (v *Value) IsEmptyStruct() bool {
|
||||
|
@ -46,7 +46,11 @@ func NewStore(root string) (*Store, error) {
|
||||
}
|
||||
|
||||
func DefaultStore() (*Store, error) {
|
||||
return NewStore(os.ExpandEnv(defaultStoreRoot))
|
||||
root := defaultStoreRoot
|
||||
if r := os.Getenv("DAGGER_STORE"); r != "" {
|
||||
root = r
|
||||
}
|
||||
return NewStore(root)
|
||||
}
|
||||
|
||||
func (s *Store) deploymentPath(name string) string {
|
||||
|
3
tests/cli/nonconcrete/main.cue
Normal file
3
tests/cli/nonconcrete/main.cue
Normal file
@ -0,0 +1,3 @@
|
||||
package testing
|
||||
|
||||
nonConcrete: string
|
11
tests/cli/simple/main.cue
Normal file
11
tests/cli/simple/main.cue
Normal file
@ -0,0 +1,11 @@
|
||||
package testing
|
||||
|
||||
import "dagger.io/llb"
|
||||
|
||||
foo: "value"
|
||||
bar: "another value"
|
||||
|
||||
#compute: [
|
||||
llb.#FetchContainer & {ref: "busybox"},
|
||||
llb.#Exec & {args: ["true"]},
|
||||
]
|
@ -21,6 +21,7 @@ test::all(){
|
||||
test::dependencies "$dagger"
|
||||
test::compute "$dagger"
|
||||
test::daggerignore "$dagger"
|
||||
test::cli "$dagger"
|
||||
test::examples "$dagger"
|
||||
}
|
||||
|
||||
@ -109,6 +110,83 @@ test::daggerignore() {
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input-dir TestData="$d"/ignore/testdata "$d"/ignore
|
||||
}
|
||||
|
||||
test::cli() {
|
||||
local dagger="$1"
|
||||
|
||||
test::cli::list "$dagger"
|
||||
test::cli::newdir "$dagger"
|
||||
test::cli::query "$dagger"
|
||||
}
|
||||
|
||||
test::cli::list() {
|
||||
local dagger="$1"
|
||||
|
||||
# Create temporary store
|
||||
local DAGGER_STORE
|
||||
DAGGER_STORE="$(mktemp -d -t dagger-store-XXXXXX)"
|
||||
export DAGGER_STORE
|
||||
|
||||
test::one "CLI: list: no deployments" --stdout="" \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" list
|
||||
|
||||
test::one "CLI: list: create deployment" \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" new --plan-dir "$d"/cli/simple simple
|
||||
|
||||
test::one "CLI: list: with deployments" --stdout="simple" \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" list
|
||||
}
|
||||
|
||||
test::cli::newdir() {
|
||||
local dagger="$1"
|
||||
|
||||
# Create temporary store
|
||||
local DAGGER_STORE
|
||||
DAGGER_STORE="$(mktemp -d -t dagger-store-XXXXXX)"
|
||||
export DAGGER_STORE
|
||||
|
||||
test::one "CLI: new: --plan-dir" \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" new --plan-dir "$d"/cli/simple simple
|
||||
|
||||
test::one "CLI: new: duplicate name" --exit=1 \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" new --plan-dir "$d"/cli/simple simple
|
||||
|
||||
test::one "CLI: new: verify plan can be upped" \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" up -d "simple"
|
||||
|
||||
test::one "CLI: new: verify we have the right plan" --stdout='{
|
||||
foo: "value"
|
||||
bar: "another value"
|
||||
}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" query -d "simple" -c
|
||||
}
|
||||
|
||||
test::cli::query() {
|
||||
local dagger="$1"
|
||||
|
||||
# Create temporary store
|
||||
local DAGGER_STORE
|
||||
DAGGER_STORE="$(mktemp -d -t dagger-store-XXXXXX)"
|
||||
export DAGGER_STORE
|
||||
|
||||
test::one "CLI: query: initialize simple" \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" new --plan-dir "$d"/cli/simple simple
|
||||
|
||||
test::one "CLI: query: concrete" --stdout='{
|
||||
foo: "value"
|
||||
bar: "another value"
|
||||
}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" query -d "simple" -c
|
||||
|
||||
test::one "CLI: query: target" --stdout='"value"' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" query -d "simple" foo
|
||||
|
||||
test::one "CLI: query: initialize nonconcrete" \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" new --plan-dir "$d"/cli/nonconcrete nonconcrete
|
||||
|
||||
test::one "CLI: query: non concrete" --exit=1 \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" query -d "nonconcrete" -c
|
||||
}
|
||||
|
||||
test::examples() {
|
||||
test::secret "$d"/../examples/react-netlify/inputs.yaml "examples: React Netlify" --exit=0 \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/../examples/react-netlify
|
||||
|
Reference in New Issue
Block a user