tests: fix integration tests
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
12b771a43b
commit
c7c8c5fa8d
@ -38,6 +38,7 @@ var computeCmd = &cobra.Command{
|
|||||||
st := &state.State{
|
st := &state.State{
|
||||||
Name: "FIXME",
|
Name: "FIXME",
|
||||||
Path: args[0],
|
Path: args[0],
|
||||||
|
Plan: args[0],
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, input := range viper.GetStringSlice("input-string") {
|
for _, input := range viper.GetStringSlice("input-string") {
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
func TestLocalDirs(t *testing.T) {
|
func TestLocalDirs(t *testing.T) {
|
||||||
st := &state.State{
|
st := &state.State{
|
||||||
Path: "/tmp/source",
|
Path: "/tmp/source",
|
||||||
|
Plan: "/tmp/source/plan",
|
||||||
}
|
}
|
||||||
require.NoError(t, st.SetInput("www.source", state.DirInput("/", []string{})))
|
require.NoError(t, st.SetInput("www.source", state.DirInput("/", []string{})))
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import "path"
|
|
||||||
|
|
||||||
// Contents of an environment serialized to a file
|
// Contents of an environment serialized to a file
|
||||||
type State struct {
|
type State struct {
|
||||||
// State path
|
// State path
|
||||||
@ -10,6 +8,9 @@ type State struct {
|
|||||||
// Workspace path
|
// Workspace path
|
||||||
Workspace string `yaml:"-"`
|
Workspace string `yaml:"-"`
|
||||||
|
|
||||||
|
// Plan path
|
||||||
|
Plan string `yaml:"-"`
|
||||||
|
|
||||||
// Human-friendly environment name.
|
// Human-friendly environment name.
|
||||||
// A environment may have more than one name.
|
// A environment may have more than one name.
|
||||||
// FIXME: store multiple names?
|
// FIXME: store multiple names?
|
||||||
@ -25,7 +26,7 @@ type State struct {
|
|||||||
// Cue module containing the environment plan
|
// Cue module containing the environment plan
|
||||||
// The input's top-level artifact is used as a module directory.
|
// The input's top-level artifact is used as a module directory.
|
||||||
func (s *State) PlanSource() Input {
|
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 {
|
func (s *State) SetInput(key string, value Input) error {
|
||||||
|
@ -155,6 +155,7 @@ func (w *Workspace) Get(ctx context.Context, name string) (*State, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
st.Path = envPath
|
st.Path = envPath
|
||||||
|
st.Plan = path.Join(envPath, planDir)
|
||||||
st.Workspace = w.Path
|
st.Workspace = w.Path
|
||||||
|
|
||||||
computed, err := os.ReadFile(path.Join(envPath, stateDir, computedFile))
|
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{
|
st := &State{
|
||||||
Path: envPath,
|
Path: envPath,
|
||||||
Workspace: w.Path,
|
Workspace: w.Path,
|
||||||
|
Plan: path.Join(envPath, planDir),
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
data, err := yaml.Marshal(st)
|
data, err := yaml.Marshal(st)
|
||||||
|
113
tests/cli.bats
113
tests/cli.bats
@ -4,55 +4,45 @@ setup() {
|
|||||||
common_setup
|
common_setup
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger list" {
|
@test "dagger init" {
|
||||||
run "$DAGGER" list
|
run "$DAGGER" init
|
||||||
assert_success
|
assert_success
|
||||||
assert_output ""
|
|
||||||
|
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
|
|
||||||
|
|
||||||
run "$DAGGER" list
|
run "$DAGGER" list
|
||||||
assert_success
|
assert_success
|
||||||
assert_output --partial "simple"
|
refute_output
|
||||||
|
|
||||||
|
run "$DAGGER" init
|
||||||
|
assert_failure
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger new --plan-dir" {
|
@test "dagger new" {
|
||||||
run "$DAGGER" list
|
run "$DAGGER" new "test"
|
||||||
assert_success
|
|
||||||
assert_output ""
|
|
||||||
|
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
|
|
||||||
|
|
||||||
# duplicate name
|
|
||||||
run "$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
|
|
||||||
assert_failure
|
assert_failure
|
||||||
|
|
||||||
# verify the plan works
|
run "$DAGGER" init
|
||||||
"$DAGGER" up -e "simple"
|
|
||||||
|
|
||||||
# verify we have the right plan
|
|
||||||
run "$DAGGER" query -f cue -e "simple" -c -f json
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output --partial '{
|
|
||||||
"bar": "another value",
|
|
||||||
"computed": "test",
|
|
||||||
"foo": "value"
|
|
||||||
}'
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "dagger new --plan-git" {
|
run "$DAGGER" list
|
||||||
"$DAGGER" new --plan-git https://github.com/samalba/dagger-test.git simple
|
|
||||||
"$DAGGER" up -e "simple"
|
|
||||||
run "$DAGGER" query -f cue -e "simple" -c
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output --partial '{
|
refute_output
|
||||||
foo: "value"
|
|
||||||
bar: "another value"
|
run "$DAGGER" new "test"
|
||||||
}'
|
assert_success
|
||||||
|
|
||||||
|
run "$DAGGER" list
|
||||||
|
assert_success
|
||||||
|
assert_output --partial "test"
|
||||||
|
|
||||||
|
run "$DAGGER" new "test"
|
||||||
|
assert_failure
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger query" {
|
@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"
|
run "$DAGGER" query -l error -e "simple"
|
||||||
assert_success
|
assert_success
|
||||||
assert_output '{
|
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" {
|
@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
|
# simple input
|
||||||
"$DAGGER" input -e "input" text "input" "my input"
|
"$DAGGER" input -e "input" text "input" "my input"
|
||||||
@ -176,7 +152,9 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input json" {
|
@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
|
# simple json
|
||||||
"$DAGGER" input -e "input" json "structured" '{"a": "foo", "b": 42}'
|
"$DAGGER" input -e "input" json "structured" '{"a": "foo", "b": 42}'
|
||||||
@ -214,7 +192,9 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input yaml" {
|
@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
|
# simple yaml
|
||||||
"$DAGGER" input -e "input" yaml "structured" '{"a": "foo", "b": 42}'
|
"$DAGGER" input -e "input" yaml "structured" '{"a": "foo", "b": 42}'
|
||||||
@ -252,10 +232,17 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input dir" {
|
@test "dagger input dir" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
"$DAGGER" init
|
||||||
|
|
||||||
# input dir
|
dagger_new_with_plan input "$TESTDIR"/cli/input/artifact
|
||||||
"$DAGGER" input -e "input" dir "source" "$TESTDIR"/cli/input/artifact/testdata
|
|
||||||
|
# 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"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input"
|
run "$DAGGER" -l error query -e "input"
|
||||||
assert_success
|
assert_success
|
||||||
@ -276,7 +263,9 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input git" {
|
@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
|
# 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
|
||||||
@ -296,11 +285,3 @@ setup() {
|
|||||||
"foo": "bar"
|
"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
|
|
||||||
}
|
|
||||||
|
@ -7,13 +7,13 @@ setup() {
|
|||||||
@test "example: react" {
|
@test "example: react" {
|
||||||
skip_unless_secrets_available "$TESTDIR"/examples/react/inputs.yaml
|
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 -
|
sops -d "$TESTDIR"/examples/react/inputs.yaml | "$DAGGER" -e "react" input yaml "" -f -
|
||||||
"$DAGGER" up -e "react"
|
"$DAGGER" up -e "react"
|
||||||
|
|
||||||
# curl the URL we just deployed to check if it worked
|
# curl the URL we just deployed to check if it worked
|
||||||
deployUrl=$("$DAGGER" query -l error -f text -e "react" www.deployUrl)
|
deployUrl=$("$DAGGER" query -l error -f text -e "react" www.deployUrl)
|
||||||
echo "=>$deployUrl<="
|
|
||||||
run curl -sS "$deployUrl"
|
run curl -sS "$deployUrl"
|
||||||
assert_success
|
assert_success
|
||||||
assert_output --partial "Todo App"
|
assert_output --partial "Todo App"
|
||||||
|
@ -10,8 +10,18 @@ common_setup() {
|
|||||||
DAGGER_LOG_FORMAT="pretty"
|
DAGGER_LOG_FORMAT="pretty"
|
||||||
export DAGGER_LOG_FORMAT
|
export DAGGER_LOG_FORMAT
|
||||||
|
|
||||||
DAGGER_STORE="$(mktemp -d -t dagger-store-XXXXXX)"
|
DAGGER_WORKSPACE="$(mktemp -d -t dagger-workspace-XXXXXX)"
|
||||||
export DAGGER_STORE
|
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() {
|
skip_unless_secrets_available() {
|
||||||
|
@ -91,8 +91,11 @@ setup() {
|
|||||||
@test "stdlib: terraform" {
|
@test "stdlib: terraform" {
|
||||||
skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml
|
skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml
|
||||||
|
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/stdlib/terraform/s3 terraform
|
"$DAGGER" init
|
||||||
"$DAGGER" -e terraform input dir TestData "$TESTDIR"/stdlib/terraform/s3/testdata
|
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 -
|
sops -d "$TESTDIR"/stdlib/aws/inputs.yaml | "$DAGGER" -e "terraform" input yaml "" -f -
|
||||||
|
|
||||||
# it must fail because of a missing var
|
# it must fail because of a missing var
|
||||||
|
Reference in New Issue
Block a user