Skip to content

Commit 55cfb6a

Browse files
fix(test): Don't use dgraph binary in tests (GRAPHQL-1114) (#168)
Ref: dgraph-io/dgo#143
1 parent 1aeb49d commit 55cfb6a

File tree

4 files changed

+272
-146
lines changed

4 files changed

+272
-146
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ dependencies {
114114
testCompile "io.opencensus:opencensus-exporter-trace-jaeger:${openCensusVersion}"
115115
testRuntime "io.opencensus:opencensus-impl:${openCensusVersion}"
116116

117+
// Used for unmarshalling a JSON GraphQL response
118+
testCompile "com.google.code.gson:gson:2.8.6"
119+
117120
// Declare the dependency for your favourite test framework you want to use in your tests.
118121
testCompile 'org.testng:testng:6.8.8'
119122
// javax.annotation is removed from the oracle java se 11, and requires explicit dependency

src/test/java/io/dgraph/AclTest.java

Lines changed: 11 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import io.grpc.StatusRuntimeException;
88
import java.io.BufferedReader;
99
import java.io.IOException;
10-
import java.io.InputStream;
1110
import java.io.InputStreamReader;
1211
import java.util.stream.Collectors;
1312
import org.testng.annotations.BeforeClass;
@@ -16,16 +15,13 @@
1615
public class AclTest extends DgraphIntegrationTest {
1716
private static final String USER_ID = "alice";
1817
private static final String USER_PASSWORD = "simplepassword";
19-
private static final String GUARDIAN_CREDS = "user=groot;password=password;namespace=0";
2018
private static final String PREDICATE_TO_READ = "predicate_to_read";
2119
private static final String PREDICATE_TO_WRITE = "predicate_to_write";
2220
private static final String PREDICATE_TO_ALTER = "predicate_to_alter";
2321
private static final String QUERY_ATTR = "name";
2422
private static final String UNUSED_GROUP = "unusedGroup";
2523
private static final String DEV_GROUP = "dev";
2624

27-
private static final String DGRAPH_ENDPOINT = TEST_HOSTNAME + ":" + TEST_PORT;
28-
2925
@BeforeClass
3026
public void setSchema() {
3127
dgraphClient.alter(
@@ -88,119 +84,28 @@ private void createAccountAndData() throws Exception {
8884
.build());
8985
}
9086

91-
private void createGroupAndACLs(String group, boolean addUserToGroup)
92-
throws IOException, InterruptedException {
87+
private void createGroupAndACLs(String group, boolean addUserToGroup) throws Exception {
9388

9489
// create a new group
95-
checkCmd(
96-
"unable to create the group " + group,
97-
"dgraph",
98-
"acl",
99-
"add",
100-
"-a",
101-
DGRAPH_ENDPOINT,
102-
"-g",
103-
group,
104-
"--guardian-creds",
105-
GUARDIAN_CREDS);
90+
TestUtil.addGroup(group);
10691

10792
if (addUserToGroup) {
108-
checkCmd(
109-
"unable to add user " + USER_ID + " to the group " + group,
110-
"dgraph",
111-
"acl",
112-
"mod",
113-
"-a",
114-
DGRAPH_ENDPOINT,
115-
"-u",
116-
USER_ID,
117-
"--group_list",
118-
group,
119-
"--guardian-creds",
120-
GUARDIAN_CREDS);
93+
TestUtil.updateUser(USER_ID, group, true);
12194
}
12295

12396
// add READ permission on the predicate_to_read to the group
124-
checkCmd(
125-
"unable to add READ permission on " + PREDICATE_TO_READ + " to the group " + group,
126-
"dgraph",
127-
"acl",
128-
"mod",
129-
"-a",
130-
DGRAPH_ENDPOINT,
131-
"-g",
132-
group,
133-
"-p",
134-
PREDICATE_TO_READ,
135-
"-m",
136-
"4",
137-
"--guardian-creds",
138-
GUARDIAN_CREDS);
97+
TestUtil.updateGroup(group, PREDICATE_TO_READ, 4);
13998

14099
// also add READ permission on the attribute queryAttr, which is used inside the query block
141-
checkCmd(
142-
"unable to add READ permission on " + QUERY_ATTR + " to the group " + group,
143-
"dgraph",
144-
"acl",
145-
"mod",
146-
"-a",
147-
DGRAPH_ENDPOINT,
148-
"-g",
149-
group,
150-
"-p",
151-
QUERY_ATTR,
152-
"-m",
153-
"4",
154-
"--guardian-creds",
155-
GUARDIAN_CREDS);
100+
TestUtil.updateGroup(group, QUERY_ATTR, 4);
156101

157-
checkCmd(
158-
"unable to add WRITE permission on " + PREDICATE_TO_WRITE + " to the group " + group,
159-
"dgraph",
160-
"acl",
161-
"mod",
162-
"-a",
163-
DGRAPH_ENDPOINT,
164-
"-g",
165-
group,
166-
"-p",
167-
PREDICATE_TO_WRITE,
168-
"-m",
169-
"2",
170-
"--guardian-creds",
171-
GUARDIAN_CREDS);
102+
TestUtil.updateGroup(group, PREDICATE_TO_WRITE, 2);
172103

173-
checkCmd(
174-
"unable to add ALTER permission on " + PREDICATE_TO_ALTER + " to the group " + group,
175-
"dgraph",
176-
"acl",
177-
"mod",
178-
"-a",
179-
DGRAPH_ENDPOINT,
180-
"-g",
181-
group,
182-
"-p",
183-
PREDICATE_TO_ALTER,
184-
"-m",
185-
"1",
186-
"--guardian-creds",
187-
GUARDIAN_CREDS);
104+
TestUtil.updateGroup(group, PREDICATE_TO_ALTER, 1);
188105
}
189106

190-
private void removeUserFromAllGroups() throws IOException, InterruptedException {
191-
checkCmd(
192-
"unable to remove user " + USER_ID + " from all the groups",
193-
"dgraph",
194-
"acl",
195-
"mod",
196-
"-a",
197-
DGRAPH_ENDPOINT,
198-
"-u",
199-
USER_ID,
200-
"--group_list",
201-
"",
202-
"--guardian-creds",
203-
GUARDIAN_CREDS);
107+
private void removeUserFromAllGroups() throws Exception {
108+
TestUtil.updateUser(USER_ID, DEV_GROUP, false);
204109
}
205110

206111
private void queryPredicateWithUserAccount(boolean shouldFail) {
@@ -278,47 +183,8 @@ private void verifyOperation(boolean shouldFail, String operation, Runnable runn
278183
}
279184

280185
private void resetUser() throws Exception {
281-
Process deleteUserCmd =
282-
new ProcessBuilder(
283-
"dgraph",
284-
"acl",
285-
"del",
286-
"-a",
287-
DGRAPH_ENDPOINT,
288-
"-u",
289-
USER_ID,
290-
"--guardian-creds",
291-
GUARDIAN_CREDS)
292-
.start();
293-
deleteUserCmd.waitFor();
294-
295-
Process createUserCmd =
296-
new ProcessBuilder(
297-
"dgraph",
298-
"acl",
299-
"add",
300-
"-a",
301-
DGRAPH_ENDPOINT,
302-
"-u",
303-
USER_ID,
304-
"-p",
305-
USER_PASSWORD,
306-
"--guardian-creds",
307-
GUARDIAN_CREDS)
308-
.redirectErrorStream(true)
309-
.start();
310-
createUserCmd.waitFor();
311-
if (createUserCmd.exitValue() != 0) {
312-
// print out the output from the command
313-
InputStream inputStream = createUserCmd.getInputStream();
314-
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
315-
String line;
316-
while ((line = br.readLine()) != null) {
317-
System.out.println(line);
318-
}
319-
320-
throw new Exception("unable to create user");
321-
}
186+
TestUtil.deleteUser(USER_ID);
187+
TestUtil.addUser(USER_ID, USER_PASSWORD);
322188
}
323189

324190
private void checkCmd(String failureMsg, String... args)

src/test/java/io/dgraph/DgraphIntegrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
public abstract class DgraphIntegrationTest {
3030
static final Logger logger = LoggerFactory.getLogger(DgraphIntegrationTest.class);
3131
static final String TEST_HOSTNAME = "localhost";
32-
static final int TEST_PORT = 9180;
32+
static final int TEST_gRPC_PORT = 9180;
33+
static final int TEST_HTTP_PORT = 8180;
3334
protected static DgraphClient dgraphClient;
3435
private static ManagedChannel channel1, channel2, channel3;
3536

0 commit comments

Comments
 (0)