Skip to content

Commit 6f57fee

Browse files
rishabhpoddarRishabh
andauthored
ci: adds new workflow for checking tests passing (#37)
* ci: adds new workflow * fixes tests Co-authored-by: Rishabh <rishabh@supertokens.io>
1 parent 41e19e4 commit 6f57fee

File tree

5 files changed

+73
-12
lines changed

5 files changed

+73
-12
lines changed

.github/helpers/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
package-lock.json

.github/helpers/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "helpers",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "test-pass-check-pr.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"github-workflow-helpers": "github:supertokens/github-workflow-helpers"
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Check if \"Run tests\" action succeeded"
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- edited
9+
- synchronize
10+
11+
jobs:
12+
pr-run-test-action:
13+
name: Check if "Run tests" action succeeded
14+
timeout-minutes: 60
15+
concurrency:
16+
group: ${{ github.head_ref }}
17+
cancel-in-progress: true
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: node install
22+
run: cd ./.github/helpers && npm i
23+
- name: Calling github API
24+
run: cd ./.github/helpers && GITHUB_TOKEN=${{ github.token }} REPO=${{ github.repository }} RUN_ID=${{ github.run_id }} BRANCH=${{ github.head_ref }} JOB_ID=${{ github.job }} SOURCE_OWNER=${{ github.event.pull_request.head.repo.owner.login }} CURRENT_SHA=${{ github.event.pull_request.head.sha }} node node_modules/github-workflow-helpers/test-pass-check-pr.js

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ dependencies {
5252
testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.3.1'
5353

5454
testImplementation 'com.tngtech.archunit:archunit-junit4:0.22.0'
55+
56+
// https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml
57+
testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.10.0'
58+
59+
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
60+
testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.0'
5561
}
5662

5763
jar {

src/test/java/io/supertokens/storage/postgresql/test/ConfigTest.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package io.supertokens.storage.postgresql.test;
1919

20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
2022
import com.google.gson.JsonObject;
2123
import io.supertokens.ProcessState;
2224
import io.supertokens.session.Session;
@@ -34,6 +36,7 @@
3436
import org.junit.rules.TestRule;
3537

3638
import java.io.File;
39+
import java.io.IOException;
3740

3841
import static org.junit.Assert.assertEquals;
3942
import static org.junit.Assert.assertNotNull;
@@ -318,10 +321,14 @@ public void testAddingSchemaWorks() throws Exception {
318321

319322
@Test
320323
public void testValidConnectionURI() throws Exception {
324+
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
325+
PostgreSQLConfig userConfig = mapper.readValue(new File("../config.yaml"), PostgreSQLConfig.class);
326+
String hostname = userConfig.getHostName();
321327
{
322328
String[] args = { "../" };
323329

324-
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://root:root@localhost:5432/supertokens");
330+
Utils.setValueInConfig("postgresql_connection_uri",
331+
"postgresql://root:root@" + hostname + ":5432/supertokens");
325332
Utils.commentConfigValue("postgresql_password");
326333
Utils.commentConfigValue("postgresql_user");
327334
Utils.commentConfigValue("postgresql_port");
@@ -341,7 +348,7 @@ public void testValidConnectionURI() throws Exception {
341348
Utils.reset();
342349
String[] args = { "../" };
343350

344-
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://root:root@localhost/supertokens");
351+
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://root:root@" + hostname + "/supertokens");
345352
Utils.commentConfigValue("postgresql_password");
346353
Utils.commentConfigValue("postgresql_user");
347354
Utils.commentConfigValue("postgresql_port");
@@ -361,7 +368,7 @@ public void testValidConnectionURI() throws Exception {
361368
Utils.reset();
362369
String[] args = { "../" };
363370

364-
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://localhost:5432/supertokens");
371+
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://" + hostname + ":5432/supertokens");
365372
Utils.commentConfigValue("postgresql_port");
366373
Utils.commentConfigValue("postgresql_host");
367374
Utils.commentConfigValue("postgresql_database_name");
@@ -379,7 +386,7 @@ public void testValidConnectionURI() throws Exception {
379386
Utils.reset();
380387
String[] args = { "../" };
381388

382-
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://root@localhost:5432/supertokens");
389+
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://root@" + hostname + ":5432/supertokens");
383390
Utils.commentConfigValue("postgresql_user");
384391
Utils.commentConfigValue("postgresql_port");
385392
Utils.commentConfigValue("postgresql_host");
@@ -398,7 +405,7 @@ public void testValidConnectionURI() throws Exception {
398405
Utils.reset();
399406
String[] args = { "../" };
400407

401-
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://root:root@localhost:5432");
408+
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://root:root@" + hostname + ":5432");
402409
Utils.commentConfigValue("postgresql_password");
403410
Utils.commentConfigValue("postgresql_user");
404411
Utils.commentConfigValue("postgresql_port");
@@ -417,6 +424,9 @@ public void testValidConnectionURI() throws Exception {
417424

418425
@Test
419426
public void testInvalidConnectionURI() throws Exception {
427+
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
428+
PostgreSQLConfig userConfig = mapper.readValue(new File("../config.yaml"), PostgreSQLConfig.class);
429+
String hostname = userConfig.getHostName();
420430
{
421431
String[] args = { "../" };
422432

@@ -439,7 +449,7 @@ public void testInvalidConnectionURI() throws Exception {
439449
String[] args = { "../" };
440450

441451
Utils.setValueInConfig("postgresql_connection_uri",
442-
"postgresql://root:wrongPassword@localhost:5432/supertokens");
452+
"postgresql://root:wrongPassword@" + hostname + ":5432/supertokens");
443453
Utils.commentConfigValue("postgresql_password");
444454
Utils.commentConfigValue("postgresql_user");
445455
Utils.commentConfigValue("postgresql_port");
@@ -459,11 +469,14 @@ public void testInvalidConnectionURI() throws Exception {
459469

460470
@Test
461471
public void testValidConnectionURIAttributes() throws Exception {
472+
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
473+
PostgreSQLConfig userConfig = mapper.readValue(new File("../config.yaml"), PostgreSQLConfig.class);
474+
String hostname = userConfig.getHostName();
462475
{
463476
String[] args = { "../" };
464477

465478
Utils.setValueInConfig("postgresql_connection_uri",
466-
"postgresql://root:root@localhost:5432/supertokens?key1=value1");
479+
"postgresql://root:root@" + hostname + ":5432/supertokens?key1=value1");
467480

468481
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
469482
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
@@ -478,9 +491,8 @@ public void testValidConnectionURIAttributes() throws Exception {
478491
Utils.reset();
479492
String[] args = { "../" };
480493

481-
Utils.setValueInConfig("postgresql_connection_uri",
482-
"postgresql://root:root@localhost:5432/supertokens?key1=value1&allowPublicKeyRetrieval=false&key2"
483-
+ "=value2");
494+
Utils.setValueInConfig("postgresql_connection_uri", "postgresql://root:root@" + hostname
495+
+ ":5432/supertokens?key1=value1&allowPublicKeyRetrieval=false&key2" + "=value2");
484496

485497
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
486498
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
@@ -492,14 +504,17 @@ public void testValidConnectionURIAttributes() throws Exception {
492504
}
493505
}
494506

495-
public static void checkConfig(PostgreSQLConfig config) {
507+
public static void checkConfig(PostgreSQLConfig config) throws IOException {
508+
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
509+
PostgreSQLConfig userConfig = mapper.readValue(new File("../config.yaml"), PostgreSQLConfig.class);
510+
String hostname = userConfig.getHostName();
496511
assertEquals("Config getAttributes did not match default", config.getConnectionAttributes(),
497512
"allowPublicKeyRetrieval=true");
498513
assertEquals("Config getSchema did not match default", config.getConnectionScheme(), "postgresql");
499514
assertEquals("Config connectionPoolSize did not match default", config.getConnectionPoolSize(), 10);
500515
assertEquals("Config databaseName does not match default", config.getDatabaseName(), "supertokens");
501516
assertEquals("Config keyValue table does not match default", config.getKeyValueTable(), "key_value");
502-
assertEquals("Config hostName does not match default ", config.getHostName(), "localhost");
517+
assertEquals("Config hostName does not match default ", config.getHostName(), hostname);
503518
assertEquals("Config port does not match default", config.getPort(), 5432);
504519
assertEquals("Config sessionInfoTable does not match default", config.getSessionInfoTable(), "session_info");
505520
assertEquals("Config user does not match default", config.getUser(), "root");

0 commit comments

Comments
 (0)