Skip to content

Commit

Permalink
add non interactive e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Jan 23, 2024
1 parent a092fa4 commit 32d5ca7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test: ## Run tests
.PHONY: test-e2e
test-e2e: build ## Run e2e tests
(cd e2e && ./interactive.tcl)
(cd e2e && ./non-interactive.tcl)

.PHONY: build
build: generate fmt vet $(BIN_FILENAME) ## Build manager binary
Expand Down
6 changes: 5 additions & 1 deletion e2e/interactive.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ proc expect_prompt {prompt} {
# The script assumes vi is used to enter the provate key
set ::env(EDITOR) "vi"
file delete -force config.yaml
file delete -force "em-$cluster_id"
set ::env(EMR_CONFIG_DIR) [pwd]

log "Starting tool"
Expand All @@ -44,7 +45,7 @@ expect_prompt "Enter your cluster ID"
send -- "$cluster_id"
send -- "\r"

log "Expecting to valid credentials"
log "Expecting to have valid credentials"
expect -exact "2 buckets with credentials found"
expect -exact "Emergency credentials found"

Expand All @@ -57,3 +58,6 @@ expect eof
test_kubeconfig "em-$cluster_id"

log "Test successful"

file delete -force config.yaml
file delete -force "em-$cluster_id"
2 changes: 1 addition & 1 deletion e2e/lib/common.tcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

proc log {msg} {
send_user "\n\[TEST\]\t$msg...\n"
send_user "\n\[TEST\]\t$msg\n"
}

proc test_kubeconfig {kubeconfig} {
Expand Down
42 changes: 42 additions & 0 deletions e2e/non-interactive.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env expect

source ./lib/common.tcl

set timeout 60

set cluster_id "c-appuio-lab-cloudscale-rma-0"
set api_endpoint "https://api.lab-cloudscale-rma-0.appuio.cloud:6443"

set passphrase [getenv_or_die "E2E_PASSBOLT_PASSPHRASE"]
set private_key [getenv_or_die "E2E_PASSBOLT_PRIVATE_KEY"]

proc expect_prompt {prompt} {
expect -exact "$prompt"
expect -exact "> "
sleep .5
}

# The script assumes vi is used to enter the provate key
set ::env(EDITOR) "vi"
file delete -force config.yaml
file delete -force "em-$cluster_id"
set ::env(EMR_CONFIG_DIR) [pwd]

log "Starting tool"
set ::env(EMR_PASSPHRASE) "$passphrase"
set ::env(EMR_KUBERNETES_ENDPOINT) "$api_endpoint"
exec -- jq --null-input --arg key "$private_key" {{passbolt_key: $key}} > config.yaml
spawn ../emergency-credentials-receive "$cluster_id"
expect -exact "Welcome"

log "Expecting to have valid credentials"
expect -exact "2 buckets with credentials found"
expect -exact "Emergency credentials found"
expect eof

test_kubeconfig "em-$cluster_id"

log "Test successful"

file delete -force config.yaml
file delete -force "em-$cluster_id"

0 comments on commit 32d5ca7

Please sign in to comment.