tests: fix integration tests

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-05-25 15:14:39 -07:00
parent 12b771a43b
commit c7c8c5fa8d
8 changed files with 74 additions and 75 deletions

View File

@ -38,6 +38,7 @@ var computeCmd = &cobra.Command{
st := &state.State{
Name: "FIXME",
Path: args[0],
Plan: args[0],
}
for _, input := range viper.GetStringSlice("input-string") {

View File

@ -10,6 +10,7 @@ import (
func TestLocalDirs(t *testing.T) {
st := &state.State{
Path: "/tmp/source",
Plan: "/tmp/source/plan",
}
require.NoError(t, st.SetInput("www.source", state.DirInput("/", []string{})))

View File

@ -1,7 +1,5 @@
package state
import "path"
// Contents of an environment serialized to a file
type State struct {
// State path
@ -10,6 +8,9 @@ type State struct {
// Workspace path
Workspace string `yaml:"-"`
// Plan path
Plan string `yaml:"-"`
// Human-friendly environment name.
// A environment may have more than one name.
// FIXME: store multiple names?
@ -25,7 +26,7 @@ type State struct {
// Cue module containing the environment plan
// The input's top-level artifact is used as a module directory.
func (s *State) PlanSource() Input {
return DirInput(path.Join(s.Path, planDir), []string{"*.cue", "cue.mod"})
return DirInput(s.Plan, []string{"*.cue", "cue.mod"})
}
func (s *State) SetInput(key string, value Input) error {

View File

@ -155,6 +155,7 @@ func (w *Workspace) Get(ctx context.Context, name string) (*State, error) {
return nil, err
}
st.Path = envPath
st.Plan = path.Join(envPath, planDir)
st.Workspace = w.Path
computed, err := os.ReadFile(path.Join(envPath, stateDir, computedFile))
@ -237,6 +238,7 @@ func (w *Workspace) Create(ctx context.Context, name string) (*State, error) {
st := &State{
Path: envPath,
Workspace: w.Path,
Plan: path.Join(envPath, planDir),
Name: name,
}
data, err := yaml.Marshal(st)

View File

@ -4,55 +4,45 @@ setup() {
common_setup
}
@test "dagger list" {
run "$DAGGER" list
@test "dagger init" {
run "$DAGGER" init
assert_success
assert_output ""
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
run "$DAGGER" list
assert_success
assert_output --partial "simple"
refute_output
run "$DAGGER" init
assert_failure
}
@test "dagger new --plan-dir" {
run "$DAGGER" list
assert_success
assert_output ""
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
# duplicate name
run "$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
@test "dagger new" {
run "$DAGGER" new "test"
assert_failure
# verify the plan works
"$DAGGER" up -e "simple"
# verify we have the right plan
run "$DAGGER" query -f cue -e "simple" -c -f json
run "$DAGGER" init
assert_success
assert_output --partial '{
"bar": "another value",
"computed": "test",
"foo": "value"
}'
}
@test "dagger new --plan-git" {
"$DAGGER" new --plan-git https://github.com/samalba/dagger-test.git simple
"$DAGGER" up -e "simple"
run "$DAGGER" query -f cue -e "simple" -c
run "$DAGGER" list
assert_success
assert_output --partial '{
foo: "value"
bar: "another value"
}'
refute_output
run "$DAGGER" new "test"
assert_success
run "$DAGGER" list
assert_success
assert_output --partial "test"
run "$DAGGER" new "test"
assert_failure
}
@test "dagger query" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
"$DAGGER" init
dagger_new_with_plan simple "$TESTDIR"/cli/simple
run "$DAGGER" query -l error -e "simple"
assert_success
assert_output '{
@ -93,24 +83,10 @@ setup() {
}'
}
@test "dagger plan" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
# plan dir
"$DAGGER" -e "simple" plan dir "$TESTDIR"/cli/simple
run "$DAGGER" -e "simple" query
assert_success
assert_output --partial '"foo": "value"'
# plan git
"$DAGGER" -e "simple" plan git https://github.com/samalba/dagger-test.git
run "$DAGGER" -e "simple" query
assert_success
assert_output --partial '"foo": "value"'
}
@test "dagger input text" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
"$DAGGER" init
dagger_new_with_plan input "$TESTDIR"/cli/input/simple
# simple input
"$DAGGER" input -e "input" text "input" "my input"
@ -176,7 +152,9 @@ setup() {
}
@test "dagger input json" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
"$DAGGER" init
dagger_new_with_plan input "$TESTDIR"/cli/input/simple
# simple json
"$DAGGER" input -e "input" json "structured" '{"a": "foo", "b": 42}'
@ -214,7 +192,9 @@ setup() {
}
@test "dagger input yaml" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
"$DAGGER" init
dagger_new_with_plan input "$TESTDIR"/cli/input/simple
# simple yaml
"$DAGGER" input -e "input" yaml "structured" '{"a": "foo", "b": 42}'
@ -252,10 +232,17 @@ setup() {
}
@test "dagger input dir" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
"$DAGGER" init
# input dir
"$DAGGER" input -e "input" dir "source" "$TESTDIR"/cli/input/artifact/testdata
dagger_new_with_plan input "$TESTDIR"/cli/input/artifact
# input dir outside the workspace
run "$DAGGER" input -e "input" dir "source" /tmp
assert_failure
# input dir inside the workspace
cp -R "$TESTDIR"/cli/input/artifact/testdata/ "$DAGGER_WORKSPACE"/testdata
"$DAGGER" input -e "input" dir "source" "$DAGGER_WORKSPACE"/testdata
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input"
assert_success
@ -276,7 +263,9 @@ setup() {
}
@test "dagger input git" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
"$DAGGER" init
dagger_new_with_plan input "$TESTDIR"/cli/input/artifact
# input git
"$DAGGER" input -e "input" git "source" https://github.com/samalba/dagger-test-simple.git
@ -296,11 +285,3 @@ setup() {
"foo": "bar"
}'
}
@test "dagger input scan" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/scan "scan"
# TODO "scan" option isn't implemented
run "$DAGGER" input scan -e "input"
assert_success
}

View File

@ -7,13 +7,13 @@ setup() {
@test "example: react" {
skip_unless_secrets_available "$TESTDIR"/examples/react/inputs.yaml
"$DAGGER" new --plan-dir "$TESTDIR"/../examples/react react
"$DAGGER" init
dagger_new_with_plan react "$TESTDIR"/../examples/react
sops -d "$TESTDIR"/examples/react/inputs.yaml | "$DAGGER" -e "react" input yaml "" -f -
"$DAGGER" up -e "react"
# curl the URL we just deployed to check if it worked
deployUrl=$("$DAGGER" query -l error -f text -e "react" www.deployUrl)
echo "=>$deployUrl<="
run curl -sS "$deployUrl"
assert_success
assert_output --partial "Todo App"

View File

@ -10,8 +10,18 @@ common_setup() {
DAGGER_LOG_FORMAT="pretty"
export DAGGER_LOG_FORMAT
DAGGER_STORE="$(mktemp -d -t dagger-store-XXXXXX)"
export DAGGER_STORE
DAGGER_WORKSPACE="$(mktemp -d -t dagger-workspace-XXXXXX)"
export DAGGER_WORKSPACE
}
dagger_new_with_plan() {
local name="$1"
local sourcePlan="$2"
local targetPlan="$DAGGER_WORKSPACE"/.dagger/env/"$name"/plan
"$DAGGER" new "$name"
rmdir "$targetPlan"
ln -s "$sourcePlan" "$targetPlan"
}
skip_unless_secrets_available() {

View File

@ -91,8 +91,11 @@ setup() {
@test "stdlib: terraform" {
skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml
"$DAGGER" new --plan-dir "$TESTDIR"/stdlib/terraform/s3 terraform
"$DAGGER" -e terraform input dir TestData "$TESTDIR"/stdlib/terraform/s3/testdata
"$DAGGER" init
dagger_new_with_plan terraform "$TESTDIR"/stdlib/terraform/s3
cp -R "$TESTDIR"/stdlib/terraform/s3/testdata "$DAGGER_WORKSPACE"/testdata
"$DAGGER" -e terraform input dir TestData "$DAGGER_WORKSPACE"/testdata
sops -d "$TESTDIR"/stdlib/aws/inputs.yaml | "$DAGGER" -e "terraform" input yaml "" -f -
# it must fail because of a missing var