@@ -12,6 +12,25 @@ if ! command -v jq &> /dev/null; then
1212 exit 1
1313fi
1414
15+ # Determine if we're testing against a remote k8s cluster
16+ # Set STACK_K8S_REMOTE=true to enable remote mode, which also requires:
17+ # STACK_KUBE_CONFIG - path to kubeconfig file
18+ # STACK_IMAGE_REGISTRY - container image registry URL
19+ # STACK_K8S_HOSTNAME - hostname of the remote cluster
20+ if [ " $STACK_K8S_REMOTE " = " true" ]; then
21+ if [ -z " $STACK_KUBE_CONFIG " ] || [ -z " $STACK_IMAGE_REGISTRY " ] || [ -z " $STACK_K8S_HOSTNAME " ]; then
22+ echo " Error: Remote k8s mode requires STACK_KUBE_CONFIG, STACK_IMAGE_REGISTRY, and STACK_K8S_HOSTNAME"
23+ exit 1
24+ fi
25+ DEPLOY_TO=" k8s"
26+ TEST_HOSTNAME=" $STACK_K8S_HOSTNAME "
27+ TEST_SCHEME=" https"
28+ else
29+ DEPLOY_TO=" k8s-kind"
30+ TEST_HOSTNAME=" localhost"
31+ TEST_SCHEME=" http"
32+ fi
33+
1534# Dump environment variables for debugging
1635echo " Environment variables:"
1736env
@@ -105,8 +124,8 @@ add_todo() {
105124 -H ' Accept-Language: en-US,en;q=0.9' \
106125 -H ' Connection: keep-alive' \
107126 -H ' Content-Type: application/json' \
108- -H ' Origin: http ://localhost ' \
109- -H ' Referer: http ://localhost/ ' \
127+ -H " Origin: ${TEST_SCHEME} ://${TEST_HOSTNAME} " \
128+ -H " Referer: ${TEST_SCHEME} ://${TEST_HOSTNAME} / " \
110129 -H ' Sec-Fetch-Dest: empty' \
111130 -H ' Sec-Fetch-Mode: cors' \
112131 -H ' Sec-Fetch-Site: same-site' \
@@ -155,11 +174,13 @@ $TEST_TARGET_SO prepare --stack $STACK_NAME
155174# Basic test of creating a deployment
156175test_deployment_dir=$STACK_TEST_DIR /test-deployment-dir
157176test_deployment_spec=$STACK_TEST_DIR /test-deployment-spec.yml
158- $TEST_TARGET_SO init --deploy-to k8s-kind \
159- --stack $STACK_NAME \
160- --output $test_deployment_spec \
161- --http-proxy-fqdn localhost \
162- --config REACT_APP_API_URL=http://localhost/api/todos
177+ init_args=" --deploy-to $DEPLOY_TO --stack $STACK_NAME --output $test_deployment_spec "
178+ init_args=" $init_args --http-proxy-fqdn $TEST_HOSTNAME "
179+ init_args=" $init_args --config REACT_APP_API_URL=${TEST_SCHEME} ://${TEST_HOSTNAME} /api/todos"
180+ if [ " $STACK_K8S_REMOTE " = " true" ]; then
181+ init_args=" $init_args --kube-config $STACK_KUBE_CONFIG --image-registry $STACK_IMAGE_REGISTRY "
182+ fi
183+ $TEST_TARGET_SO init $init_args
163184
164185# Check the file now exists
165186if [ ! -f " $test_deployment_spec " ]; then
@@ -177,22 +198,29 @@ if [ ! -d "$test_deployment_dir" ]; then
177198fi
178199echo " deploy create test: passed"
179200
201+ # Push images to remote registry if needed
202+ if [ " $STACK_K8S_REMOTE " = " true" ]; then
203+ $TEST_TARGET_SO manage --dir $test_deployment_dir push-images
204+ fi
205+
180206# Start
181207$TEST_TARGET_SO manage --dir $test_deployment_dir start
182208wait_for_running 3
183209
184210# Add a todo
185211todo_title=" 79b06705-b402-431a-83a3-a634392d2754"
186- add_todo http ://localhost /api/todos " $todo_title "
212+ add_todo ${TEST_SCHEME} ://${TEST_HOSTNAME} /api/todos " $todo_title "
187213
188214
189215# Check that it exists
190- if [ " $todo_title " != " $( curl -s http ://localhost /api/todos | jq -r ' .[] | select(.id == 1) | .title' ) " ]; then
216+ if [ " $todo_title " != " $( curl -s ${TEST_SCHEME} ://${TEST_HOSTNAME} /api/todos | jq -r ' .[] | select(.id == 1) | .title' ) " ]; then
191217 echo " deploy storage: failed - todo $todo_title not found"
192218 exit 1
193219fi
194220
195- wget -q -O - http ://localhost | grep ' bundle.js'
221+ wget -q -O - ${TEST_SCHEME} ://${TEST_HOSTNAME} | grep ' bundle.js'
196222echo " deploy http: passed"
197223
224+ delete_cluster_exit
225+
198226echo " Test passed"
0 commit comments