Skip to content

Commit

Permalink
test: Improve code coverage for Acl (#490)
Browse files Browse the repository at this point in the history
* test: Improve code coverage for Acl
In Acl there's still untested class particularly the IamMember.
Also we can still improve the coverage by improving test for Group.

* docs(sample: Fix flaky test for AddEmptyColumnIT
Since nearly every table is using env var,
there's a possibility of concurrency problem in the test.
  • Loading branch information
irvifa committed Jun 29, 2020
1 parent 239aaa6 commit 84237c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.bigquery.Acl.Entity;
import com.google.cloud.bigquery.Acl.Entity.Type;
import com.google.cloud.bigquery.Acl.Group;
import com.google.cloud.bigquery.Acl.IamMember;
import com.google.cloud.bigquery.Acl.Role;
import com.google.cloud.bigquery.Acl.User;
import com.google.cloud.bigquery.Acl.View;
Expand Down Expand Up @@ -52,12 +53,20 @@ public void testGroupEntity() {
public void testSpecialGroupEntity() {
Group entity = Group.ofAllAuthenticatedUsers();
assertEquals("allAuthenticatedUsers", entity.getIdentifier());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
entity = Group.ofProjectWriters();
assertEquals("projectWriters", entity.getIdentifier());
pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
entity = Group.ofProjectReaders();
assertEquals("projectReaders", entity.getIdentifier());
pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
entity = Group.ofProjectOwners();
assertEquals("projectOwners", entity.getIdentifier());
pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}

@Test
Expand All @@ -79,6 +88,14 @@ public void testViewEntity() {
assertEquals(entity, Entity.fromPb(pb));
}

@Test
public void testIamMemberEntity() {
IamMember entity = new IamMember("member1");
assertEquals("member1", entity.getIamMember());
Dataset.Access pb = entity.toPb();
assertEquals(entity, Entity.fromPb(pb));
}

@Test
public void testOf() {
Acl acl = Acl.of(Group.ofAllAuthenticatedUsers(), Role.READER);
Expand Down
Expand Up @@ -22,6 +22,10 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.UUID;

import com.google.cloud.bigquery.Field;
import com.google.cloud.bigquery.LegacySQLTypeName;
import com.google.cloud.bigquery.Schema;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -32,18 +36,16 @@ public class AddEmptyColumnIT {
private PrintStream out;

private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME");
private static final String BIGQUERY_TEST_TABLE = System.getenv("BIGQUERY_TEST_TABLE");

private static void requireEnvVar(String varName) {
assertNotNull(
assertNotNull (
"Environment variable " + varName + " is required to perform these tests.",
System.getenv(varName));
}

@BeforeClass
public static void checkRequirements() {
requireEnvVar("BIGQUERY_DATASET_NAME");
requireEnvVar("BIGQUERY_TEST_TABLE");
}

@Before
Expand All @@ -60,8 +62,17 @@ public void tearDown() {

@Test
public void addEmptyColumn() {
String tableName = "AddEmptyColumnTestTable_" + UUID.randomUUID().toString().replace('-', '_');
Schema schema =
Schema.of(
Field.of("booleanField", LegacySQLTypeName.BOOLEAN),
Field.of("numericField", LegacySQLTypeName.NUMERIC));

// Create table in dataset for testing
CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, schema);

String randomColumnName = "new_" + UUID.randomUUID().toString().replace('-', '_');
AddEmptyColumn.addEmptyColumn(randomColumnName, BIGQUERY_DATASET_NAME, BIGQUERY_TEST_TABLE);
AddEmptyColumn.addEmptyColumn(randomColumnName, BIGQUERY_DATASET_NAME, tableName);
assertThat(bout.toString()).contains("Empty column successfully added to table");
}
}

0 comments on commit 84237c5

Please sign in to comment.