Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/test/java/integration/Notebook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package integration;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import harness.TestBashScript;
import harness.TestUser;
import harness.baseclasses.ClearContextIntegration;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("integration")
public class Notebook extends ClearContextIntegration {
@Test
@DisplayName("post startup script sets correct env vars")
void notebookPostStartupScript() throws IOException {
// Select a test user and login
TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
testUser.login(/*writeGcloudAuthFiles=*/ true);

// Create a workspace
int exitCode = TestBashScript.runScript("CreateWorkspace.sh");
assertEquals(0, exitCode, "workspace created without errors");

// Create a notebook and get the environment variables
exitCode = TestBashScript.runScript("NotebookPostStartup.sh");
assertEquals(0, exitCode, "notebook created without errors");

String scriptOutput =
Files.readString(
TestBashScript.getOutputFilePath("notebookPostStartupScript_stdout.txt"),
StandardCharsets.UTF_8);

String[] envVars = {
"GOOGLE_CLOUD_PROJECT",
"OWNER_EMAIL",
"TERRA_USER_EMAIL",
"GGOGLE_PROJECT",
"CROMWELL_JAR",
"GOOGLE_SERVICE_ACCOUNT_EMAIL",
"PET_SA_EMAIL"
};

// Check that all expected env variables are present
for (String var : envVars) {
assertThat(
"output includes the env variable " + var,
scriptOutput,
CoreMatchers.containsString(var));
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/unit/PassthroughApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void appExecuteSpace() throws IOException {

// `terra app execute sh -c "echo Hello World"`
TestCommand.Result cmd =
TestCommand.runCommand("app", "execute", "sh", "-c", "\"echo Hello World\"");
TestCommand.runCommand("app", "execute", "sh", "-c", "echo Hello World");

// Check that the output was printed
assertThat("Output is correct", cmd.stdOut, CoreMatchers.containsString("Hello World"));
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/testscripts/NotebookPostStartup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e
## This script creates a new notebook and echoes the set environment variables

terra status

name=notebook-$RANDOM
terra resource create gcp-notebook --name=$name

# hack to wait for permissions to propagate
until terra notebook start --name=$name
do
sleep 30
done

terra gcloud compute ssh --quiet --zone us-central1-a --command "source .bash_profile; env" jupyter@$name > notebookPostStartupScript_stdout.txt
cat notebookPostStartupScript_stdout.txt