From 8b9754a02033b2c39f86510dd84d45cbee33b463 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Sun, 27 Mar 2022 23:53:23 +0530 Subject: [PATCH] ci: adds new workflow files to check tests (#34) * adds new workflow files * fixes tests Co-authored-by: Rishabh --- .github/helpers/.gitignore | 2 + .github/helpers/package.json | 14 ++++++ .github/workflows/tests-pass-check-pr.yml | 24 +++++++++++ build.gradle | 6 +++ .../storage/mysql/test/ConfigTest.java | 43 +++++++++++++------ 5 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 .github/helpers/.gitignore create mode 100644 .github/helpers/package.json create mode 100644 .github/workflows/tests-pass-check-pr.yml diff --git a/.github/helpers/.gitignore b/.github/helpers/.gitignore new file mode 100644 index 0000000..25c8fdb --- /dev/null +++ b/.github/helpers/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json \ No newline at end of file diff --git a/.github/helpers/package.json b/.github/helpers/package.json new file mode 100644 index 0000000..80ec546 --- /dev/null +++ b/.github/helpers/package.json @@ -0,0 +1,14 @@ +{ + "name": "helpers", + "version": "1.0.0", + "description": "", + "main": "test-pass-check-pr.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "github-workflow-helpers": "github:supertokens/github-workflow-helpers" + } +} \ No newline at end of file diff --git a/.github/workflows/tests-pass-check-pr.yml b/.github/workflows/tests-pass-check-pr.yml new file mode 100644 index 0000000..4f03705 --- /dev/null +++ b/.github/workflows/tests-pass-check-pr.yml @@ -0,0 +1,24 @@ +name: "Check if \"Run tests\" action succeeded" + +on: + pull_request: + types: + - opened + - reopened + - edited + - synchronize + +jobs: + pr-run-test-action: + name: Check if "Run tests" action succeeded + timeout-minutes: 60 + concurrency: + group: ${{ github.head_ref }} + cancel-in-progress: true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: node install + run: cd ./.github/helpers && npm i + - name: Calling github API + 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 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 277d09c..29f8185 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,12 @@ dependencies { testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.3.1' testImplementation 'com.tngtech.archunit:archunit-junit4:0.22.0' + + // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml + testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.10.0' + + // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core + testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.0' } jar { diff --git a/src/test/java/io/supertokens/storage/mysql/test/ConfigTest.java b/src/test/java/io/supertokens/storage/mysql/test/ConfigTest.java index 3d8b441..b094002 100644 --- a/src/test/java/io/supertokens/storage/mysql/test/ConfigTest.java +++ b/src/test/java/io/supertokens/storage/mysql/test/ConfigTest.java @@ -17,6 +17,8 @@ package io.supertokens.storage.mysql.test; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import io.supertokens.ProcessState; import io.supertokens.storage.mysql.ConnectionPoolTestContent; import io.supertokens.storage.mysql.Start; @@ -31,6 +33,7 @@ import org.junit.rules.TestRule; import java.io.File; +import java.io.IOException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -266,10 +269,13 @@ public void testAddingTableNamePrefixWorks() throws Exception { @Test public void testValidConnectionURI() throws Exception { + final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + MySQLConfig userConfig = mapper.readValue(new File("../config.yaml"), MySQLConfig.class); + String hostname = userConfig.getHostName(); { String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", "mysql://root:root@localhost:3306/supertokens"); + Utils.setValueInConfig("mysql_connection_uri", "mysql://root:root@" + hostname + ":3306/supertokens"); Utils.commentConfigValue("mysql_password"); Utils.commentConfigValue("mysql_user"); Utils.commentConfigValue("mysql_port"); @@ -289,7 +295,7 @@ public void testValidConnectionURI() throws Exception { Utils.reset(); String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", "mysql://root:root@localhost/supertokens"); + Utils.setValueInConfig("mysql_connection_uri", "mysql://root:root@" + hostname + "/supertokens"); Utils.commentConfigValue("mysql_password"); Utils.commentConfigValue("mysql_user"); Utils.commentConfigValue("mysql_port"); @@ -309,7 +315,7 @@ public void testValidConnectionURI() throws Exception { Utils.reset(); String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", "mysql://localhost:3306/supertokens"); + Utils.setValueInConfig("mysql_connection_uri", "mysql://" + hostname + ":3306/supertokens"); Utils.commentConfigValue("mysql_port"); Utils.commentConfigValue("mysql_host"); Utils.commentConfigValue("mysql_database_name"); @@ -327,7 +333,7 @@ public void testValidConnectionURI() throws Exception { Utils.reset(); String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", "mysql://root@localhost:3306/supertokens"); + Utils.setValueInConfig("mysql_connection_uri", "mysql://root@" + hostname + ":3306/supertokens"); Utils.commentConfigValue("mysql_user"); Utils.commentConfigValue("mysql_port"); Utils.commentConfigValue("mysql_host"); @@ -346,7 +352,7 @@ public void testValidConnectionURI() throws Exception { Utils.reset(); String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", "mysql://root:root@localhost:3306"); + Utils.setValueInConfig("mysql_connection_uri", "mysql://root:root@" + hostname + ":3306"); Utils.commentConfigValue("mysql_password"); Utils.commentConfigValue("mysql_user"); Utils.commentConfigValue("mysql_port"); @@ -365,10 +371,13 @@ public void testValidConnectionURI() throws Exception { @Test public void testInvalidConnectionURI() throws Exception { + final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + MySQLConfig userConfig = mapper.readValue(new File("../config.yaml"), MySQLConfig.class); + String hostname = userConfig.getHostName(); { String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", ":/localhost:3306/supertokens"); + Utils.setValueInConfig("mysql_connection_uri", ":/" + hostname + ":3306/supertokens"); TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); ProcessState.EventAndException e = process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.INIT_FAILURE); @@ -386,7 +395,8 @@ public void testInvalidConnectionURI() throws Exception { Utils.reset(); String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", "mysql://root:wrongPassword@localhost:3306/supertokens"); + Utils.setValueInConfig("mysql_connection_uri", + "mysql://root:wrongPassword@" + hostname + ":3306/supertokens"); Utils.commentConfigValue("mysql_password"); Utils.commentConfigValue("mysql_user"); Utils.commentConfigValue("mysql_port"); @@ -406,10 +416,14 @@ public void testInvalidConnectionURI() throws Exception { @Test public void testValidConnectionURIAttributes() throws Exception { + final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + MySQLConfig userConfig = mapper.readValue(new File("../config.yaml"), MySQLConfig.class); + String hostname = userConfig.getHostName(); { String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", "mysql://root:root@localhost:3306/supertokens?key1=value1"); + Utils.setValueInConfig("mysql_connection_uri", + "mysql://root:root@" + hostname + ":3306/supertokens?key1=value1"); TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); @@ -424,9 +438,8 @@ public void testValidConnectionURIAttributes() throws Exception { Utils.reset(); String[] args = { "../" }; - Utils.setValueInConfig("mysql_connection_uri", - "mysql://root:root@localhost:3306/supertokens?key1=value1&allowPublicKeyRetrieval=false&key2" - + "=value2"); + Utils.setValueInConfig("mysql_connection_uri", "mysql://root:root@" + hostname + + ":3306/supertokens?key1=value1&allowPublicKeyRetrieval=false&key2" + "=value2"); TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); @@ -438,15 +451,17 @@ public void testValidConnectionURIAttributes() throws Exception { } } - public static void checkConfig(MySQLConfig config) { - + public static void checkConfig(MySQLConfig config) throws IOException { + final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + MySQLConfig userConfig = mapper.readValue(new File("../config.yaml"), MySQLConfig.class); + String hostname = userConfig.getHostName(); assertEquals("Config getAttributes did not match default", config.getConnectionAttributes(), "allowPublicKeyRetrieval=true"); assertEquals("Config getSchema did not match default", config.getConnectionScheme(), "mysql"); assertEquals("Config connectionPoolSize did not match default", config.getConnectionPoolSize(), 10); assertEquals("Config databaseName does not match default", config.getDatabaseName(), "supertokens"); assertEquals("Config keyValue table does not match default", config.getKeyValueTable(), "key_value"); - assertEquals("Config hostName does not match default ", config.getHostName(), "localhost"); + assertEquals("Config hostName does not match default ", config.getHostName(), hostname); assertEquals("Config port does not match default", config.getPort(), 3306); assertEquals("Config sessionInfoTable does not match default", config.getSessionInfoTable(), "session_info"); assertEquals("Config user does not match default", config.getUser(), "root");