Skip to content

Commit

Permalink
CI: Add test for singleuser.extraEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Sep 4, 2020
1 parent 079fe5a commit e02be6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dev-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ singleuser:
cidr: 104.28.9.110/32 # jupyter.org 1
- ipBlock:
cidr: 104.28.8.110/32 # jupyter.org 2
extraEnv:
TEST_ENV_FIELDREF_TO_NAMESPACE:
valueFrom:
fieldRef:
fieldPath: metadata.namespace

prePuller:
hook:
Expand Down
11 changes: 10 additions & 1 deletion tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ def test_hub_can_talk_to_proxy(api_request, request_data):
def test_hub_api_request_user_spawn(api_request, jupyter_user, request_data, pebble_acme_ca_cert):
"""
Tests the hub api's /users/:user/server POST endpoint. A user pod should be
created.
created with environment variables defined in singleuser.extraEnv etc.
"""

print("asking kubespawner to spawn a server for a test user")
r = api_request.post("/users/" + jupyter_user + "/server")
assert r.status_code in (201, 202)
try:
# check successfull spawn
server_model = _wait_for_user_to_spawn(
api_request, jupyter_user, request_data["test_timeout"]
)
Expand All @@ -142,6 +143,14 @@ def test_hub_api_request_user_spawn(api_request, jupyter_user, request_data, peb
)
assert r.status_code == 200
assert "version" in r.json()

# check user pod's extra environment variable
pod_name = server_model["state"]["pod_name"]
c = subprocess.run([
"kubectl", "exec", pod_name, "--",
"sh", "-c", "if [ -z $TEST_ENV_FIELDREF_TO_NAMESPACE ]; then exit 1; fi",
])
assert c.returncode == 0, f"singleuser.extraEnv didn't lead to a mounted environment variable!"
finally:
_delete_server(api_request, jupyter_user, request_data["test_timeout"])

Expand Down

0 comments on commit e02be6f

Please sign in to comment.