use of harness.TestUser in project terra-cli by DataBiosphere.
the class BqDatasetNumTables method numTablesForReferencedWithNoAccess.
@Test
@DisplayName("referenced dataset with no access does not fail the describe command")
void numTablesForReferencedWithNoAccess() throws IOException {
workspaceCreator.login();
// `terra workspace set --id=$id`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getUserFacingId());
// `terra resource add-ref bq-dataset --name=$name --project-id=$projectId
// --dataset-id=$datasetId`
String name = "numTablesForReferencedWithNoAccess";
TestCommand.runCommandExpectSuccess("resource", "add-ref", "bq-dataset", "--name=" + name, "--project-id=" + externalDataset.getProjectId(), "--dataset-id=" + externalDataset.getDatasetId());
// `terra workspace add-user --email=$email --role=READER`
TestUser shareeUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + shareeUser.email, "--role=READER");
shareeUser.login();
// `terra resource describe --name=$name`
UFBqDataset describeDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "describe", "--name=" + name);
// the external dataset created in the beforeall method should have 1 table in it, but the
// sharee user doesn't have read access to the dataset so they can't know that
assertNull(describeDataset.numTables, "referenced dataset with no access contains NULL tables");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class Workspace method describeReflectsNumResources.
@Test
@DisplayName("workspace describe reflects the number of resources")
void describeReflectsNumResources() throws IOException {
// select a test user and login
TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
testUser.login();
UFWorkspace createdWorkspace = WorkspaceUtils.createWorkspace(testUser);
assertEquals(0, createdWorkspace.numResources, "new workspace has 0 resources");
// `terra resource create gcs-bucket --name=$name --bucket-name=$bucketName`
String bucketResourceName = "describeReflectsNumResourcesGCS";
String bucketName = UUID.randomUUID().toString();
TestCommand.runCommandExpectSuccess("resource", "create", "gcs-bucket", "--name=" + bucketResourceName, "--bucket-name=" + bucketName);
// `terra workspace describe`
UFWorkspace describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
assertEquals(1, describeWorkspace.numResources, "worksapce has 1 resource after creating bucket");
// `terra resource create bq-dataset --name=$name --dataset-id=$datasetId`
String datasetResourceName = "describeReflectsNumResourcesBQ";
String datasetId = "bq1";
TestCommand.runCommandExpectSuccess("resource", "create", "bq-dataset", "--name=" + datasetResourceName, "--dataset-id=" + datasetId);
// `terra workspace describe`
Result describeResult2 = TestCommand.runCommand("workspace", "describe");
assertEquals(0, describeResult2.exitCode, "Describe was successful.");
assertThat("workspace has 2 resources after creating dataset", describeResult2.stdOut, containsString("# Resources: 2"));
assertThat("No error message is displayed on second describe.", describeResult2.stdErr, is(emptyString()));
UFWorkspace describeWorkspace3 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
assertEquals(2, describeWorkspace3.numResources, "worksapce has 2 resources after creating dataset");
// `terra workspace delete`
TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class Workspace method createFailsWithoutSpendAccess.
@Test
@DisplayName("workspace create fails without spend profile access")
void createFailsWithoutSpendAccess() throws IOException {
// select a test user and login
TestUser testUser = TestUser.chooseTestUserWithoutSpendAccess();
testUser.login();
final String workspaceName = "bad-profile-6789";
// `terra workspace create --id=<user-facing-id>`
String stdErr = TestCommand.runCommandExpectExitCode(1, "workspace", "create", "--id=" + WorkspaceUtils.createUserFacingId());
assertThat("error message includes spend profile unauthorized", stdErr, CoreMatchers.containsString("Accessing the spend profile failed. Ask an administrator to grant you access."));
// workspace was deleted
List<UFWorkspace> listWorkspaces = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "workspace", "list", "--limit=100");
assertFalse(listWorkspaces.stream().anyMatch(w -> workspaceName.equals(w.name)));
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class Workspace method statusDescribeListReflectCreate.
@Test
@DisplayName("status, describe, workspace list reflect workspace create")
void statusDescribeListReflectCreate() throws IOException {
// select a test user and login
TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
testUser.login();
UFWorkspace createdWorkspace = WorkspaceUtils.createWorkspace(testUser);
// check the created workspace has an id and a google project
assertNotNull(createdWorkspace.id, "create workspace returned a workspace id");
assertNotNull(createdWorkspace.googleProjectId, "create workspace created a gcp project");
assertThat("workspace email matches test user", createdWorkspace.userEmail, equalToIgnoringCase(testUser.email));
// `terra status --format=json`
UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
// check the current status reflects the new workspace
assertThat("workspace server matches current server", createdWorkspace.serverName, equalToIgnoringCase(status.server.name));
assertEquals(createdWorkspace.id, status.workspace.id, "workspace id matches current status");
assertEquals(createdWorkspace.googleProjectId, status.workspace.googleProjectId, "workspace gcp project matches current status");
// `terra workspace describe --format=json`
UFWorkspace describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
// check the new workspace is returned by describe
assertEquals(createdWorkspace.id, describeWorkspace.id, "workspace id matches that in describe");
assertEquals(createdWorkspace.googleProjectId, describeWorkspace.googleProjectId, "workspace gcp project matches that in describe");
// check the new workspace is included in the list
List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(createdWorkspace.id);
assertEquals(1, matchingWorkspaces.size(), "new workspace is included exactly once in list");
assertEquals(createdWorkspace.id, matchingWorkspaces.get(0).id, "workspace id matches that in list");
assertEquals(createdWorkspace.googleProjectId, matchingWorkspaces.get(0).googleProjectId, "workspace gcp project matches that in list");
// `terra workspace delete`
TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class Workspace method statusDescribeListReflectDelete.
@Test
@DisplayName("status, describe, workspace list reflect workspace delete")
void statusDescribeListReflectDelete() throws IOException {
// select a test user and login
TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
testUser.login();
UFWorkspace createdWorkspace = WorkspaceUtils.createWorkspace(testUser);
// `terra workspace delete --format=json`
TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
// `terra status --format=json`
UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
// check the current status reflects the deleted workspace
assertNull(status.workspace, "status has no workspace after delete");
// `terra workspace describe --format=json`
TestCommand.runCommandExpectExitCode(1, "workspace", "describe");
// check the deleted workspace is not included in the list
List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(createdWorkspace.id);
assertEquals(0, matchingWorkspaces.size(), "deleted workspace is not included in list");
}
Aggregations