Skip to content

Commit

Permalink
Use expect to test interactive setup
Browse files Browse the repository at this point in the history
  • Loading branch information
watsonian committed May 10, 2023
1 parent 80683f9 commit eea604b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
with:
go-version: '1.19'
check-latest: true
- name: Install expect
run: sudo DEBIAN_FRONTEND=noninteractive apt-get install -yq expect
- name: Checkout
uses: actions/checkout@v1
with:
Expand Down
66 changes: 59 additions & 7 deletions tests/e2e/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ beforeEach() {
cat << EOF > doppler.yaml
setup:
- project: cli
config: dev
config: e2e
path: .
- project: example
config: stg
Expand Down Expand Up @@ -71,6 +71,58 @@ beforeAll
######################################################################
#

name="interactive setup"

beforeEach

# remove doppler.yaml file dropped by beforeEach
rm -f doppler.yaml

# confirm that no projects or configs are set before loading the setup file
actual="$("$DOPPLER_BINARY" configure get project --plain --config-dir=$TEST_CONFIG_DIR)"
expected=""
[[ "$actual" == "$expected" ]] || error "ERROR: unexpected project at scope. expected '$expected', actual '$actual'"

actual="$("$DOPPLER_BINARY" configure get config --plain --config-dir=$TEST_CONFIG_DIR)"
expected=""
[[ "$actual" == "$expected" ]] || error "ERROR: unexpected config at scope. expected '$expected', actual '$actual'"

cat << EOF > setup-test.exp
#!/usr/bin/env expect --
set timeout 2
set has_failed "1"
spawn $DOPPLER_BINARY setup --config-dir=$TEST_CONFIG_DIR
expect "Selected only available project: cli"
expect "Selected only available config: e2e"
expect {
"NAME" { set has_failed "0" }
}
if { \$has_failed == "1" } {
puts "failed"
} else {
puts "Setup completed successfully"
}
EOF

actual="$(expect -f setup-test.exp)"
expected="Setup completed successfully"
[[ "$actual" == *"$expected"* ]] || {
echo "$actual"
error "ERROR: interactive setup failed"
}

afterEach

######################################################################
#

name="test legacy doppler.yaml setup file"

beforeEach
Expand All @@ -88,7 +140,7 @@ expected=""
cat << EOF > doppler.yaml
setup:
project: cli
config: dev
config: e2e
EOF
actual="$("$DOPPLER_BINARY" setup --config-dir=$TEST_CONFIG_DIR --no-interactive)"
[[ "$actual" != "Unable to parse doppler repo config file" ]] || error "ERROR: setup file not parseable"
Expand All @@ -99,15 +151,15 @@ expected="cli"
[[ "$actual" == "$expected" ]] || error "ERROR: unexpected project at scope. expected '$expected', actual '$actual'"

actual="$("$DOPPLER_BINARY" configure get config --plain --config-dir=$TEST_CONFIG_DIR)"
expected="dev"
expected="e2e"
[[ "$actual" == "$expected" ]] || error "ERROR: unexpected config at scope. expected '$expected', actual '$actual'"

actual="$("$DOPPLER_BINARY" configure get project --plain --scope=./example --config-dir=$TEST_CONFIG_DIR)"
expected="cli"
[[ "$actual" == "$expected" ]] || error "ERROR: unexpected project at scope. expected '$expected', actual '$actual'"

actual="$("$DOPPLER_BINARY" configure get config --plain --scope=./example --config-dir=$TEST_CONFIG_DIR)"
expected="dev"
expected="e2e"
[[ "$actual" == "$expected" ]] || error "ERROR: unexpected config at scope. expected '$expected', actual '$actual'"

afterEach
Expand Down Expand Up @@ -148,7 +200,7 @@ expected="cli"
[[ "$actual" == "$expected" ]] || error "ERROR: unexpected project at scope. expected '$expected', actual '$actual'"

actual="$("$DOPPLER_BINARY" configure get config --plain --config-dir=$TEST_CONFIG_DIR)"
expected="dev"
expected="e2e"
[[ "$actual" == "$expected" ]] || error "ERROR: unexpected config at scope. expected '$expected', actual '$actual'"

actual="$("$DOPPLER_BINARY" configure get project --plain --scope=./example --config-dir=$TEST_CONFIG_DIR)"
Expand All @@ -171,7 +223,7 @@ beforeEach
cat << EOF > doppler.yaml
setup:
- project: cli
config: dev
config: e2e
- project: example
config: dev
EOF
Expand All @@ -192,7 +244,7 @@ beforeEach
cat << EOF > doppler.yaml
setup:
- project: cli
config: dev
config: e2e
path: .
- project: example
config: dev
Expand Down

0 comments on commit eea604b

Please sign in to comment.