Skip to content

Commit

Permalink
ci: adds new workflow files to check tests (#34)
Browse files Browse the repository at this point in the history
* adds new workflow files

* fixes tests

Co-authored-by: Rishabh <[email protected]>
  • Loading branch information
rishabhpoddar and Rishabh authored Mar 27, 2022
1 parent 50392e1 commit 8b9754a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/helpers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
14 changes: 14 additions & 0 deletions .github/helpers/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
24 changes: 24 additions & 0 deletions .github/workflows/tests-pass-check-pr.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
43 changes: 29 additions & 14 deletions src/test/java/io/supertokens/storage/mysql/test/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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");
Expand Down

0 comments on commit 8b9754a

Please sign in to comment.