Skip to content

Commit

Permalink
Use the same configuration library for tests as Java SDK (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleewho authored Jan 26, 2022
1 parent e359340 commit de0b421
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build/
bin/
gen/
out/
/src/test/resources/config.properties
test.properties
*.DS_STORE

# GitHub Actions #
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies {
allTest "ch.qos.logback:logback-classic:1.2.3"
allTest "ch.qos.logback:logback-core:1.2.3"
allTest "org.json:json:20210307"
allTest "dev.nohus:AutoKonfig:1.0.0"
allTest 'org.aeonbits.owner:owner:1.0.12'

testImplementation "io.mockk:mockk:1.11.0"
testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '6.10.4'
Expand Down
37 changes: 18 additions & 19 deletions src/test/kotlin/com/pubnub/api/Keys.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package com.pubnub.api

import dev.nohus.autokonfig.AutoKonfig
import dev.nohus.autokonfig.types.StringSetting
import dev.nohus.autokonfig.withEnvironmentVariables
import dev.nohus.autokonfig.withResourceConfig
import org.aeonbits.owner.Config
import org.aeonbits.owner.ConfigFactory

object Keys {
private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply {
try {
withResourceConfig(resource)
} catch (e: Exception) {
}
}
@Config.Sources("file:test.properties")
interface KeysConfig : Config {
@get:Config.Key("subKey")
val subscribeKey: String

private val config = AutoKonfig()
.withSafeResourceConfig("config.properties")
.withEnvironmentVariables()
@get:Config.Key("pubKey")
val publishKey: String

val pubKey by config.StringSetting()
val subKey by config.StringSetting()
val pamPubKey by config.StringSetting()
val pamSubKey by config.StringSetting()
val pamSecKey by config.StringSetting()
@get:Config.Key("pamSubKey")
val pamSubKey: String

@get:Config.Key("pamPubKey")
val pamPubKey: String

@get:Config.Key("pamSecKey")
val pamSecKey: String
}

val Keys: KeysConfig = ConfigFactory.create(KeysConfig::class.java, System.getenv())
53 changes: 28 additions & 25 deletions src/test/kotlin/com/pubnub/contract/ContractTestConfig.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
package com.pubnub.contract

import dev.nohus.autokonfig.AutoKonfig
import dev.nohus.autokonfig.types.BooleanSetting
import dev.nohus.autokonfig.types.StringSetting
import dev.nohus.autokonfig.withEnvironmentVariables
import dev.nohus.autokonfig.withResourceConfig

object ContractTestConfig {
private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply {
try {
withResourceConfig(resource)
} catch (e: Exception) {
}
}

private val config = AutoKonfig()
.withSafeResourceConfig("config.properties")
.withEnvironmentVariables()

val pamSubKey by config.StringSetting()
val pamPubKey by config.StringSetting()
val pamSecKey by config.StringSetting()
val pubKey by config.StringSetting()
val subKey by config.StringSetting()
val serverHostPort by config.StringSetting()
val serverMock by config.BooleanSetting(true)
import org.aeonbits.owner.Config
import org.aeonbits.owner.ConfigFactory

@Config.Sources("file:test.properties")
interface ContractTestKeysConfig : Config {
@get:Config.Key("subKey")
val subKey: String

@get:Config.Key("pubKey")
val pubKey: String

@get:Config.Key("pamSubKey")
val pamSubKey: String

@get:Config.Key("pamPubKey")
val pamPubKey: String

@get:Config.Key("pamSecKey")
val pamSecKey: String

@get:Config.Key("serverHostPort")
val serverHostPort: String

@get:Config.Key("serverMock")
@get:Config.DefaultValue("true")
val serverMock: Boolean
}

val ContractTestConfig: ContractTestKeysConfig = ConfigFactory.create(ContractTestKeysConfig::class.java, System.getenv())
37 changes: 18 additions & 19 deletions src/testFixtures/kotlin/com/pubnub/api/Keys.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package com.pubnub.api

import dev.nohus.autokonfig.AutoKonfig
import dev.nohus.autokonfig.types.StringSetting
import dev.nohus.autokonfig.withEnvironmentVariables
import dev.nohus.autokonfig.withResourceConfig
import org.aeonbits.owner.Config
import org.aeonbits.owner.ConfigFactory

object Keys {
private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply {
try {
withResourceConfig(resource)
} catch (e: Exception) {
}
}
@Config.Sources("file:test.properties")
interface KeysConfig : Config {
@get:Config.Key("subKey")
val subKey: String

private val config = AutoKonfig()
.withSafeResourceConfig("config.properties")
.withEnvironmentVariables()
@get:Config.Key("pubKey")
val pubKey: String

val pubKey by config.StringSetting()
val subKey by config.StringSetting()
val pamPubKey by config.StringSetting()
val pamSubKey by config.StringSetting()
val pamSecKey by config.StringSetting()
@get:Config.Key("pamSubKey")
val pamSubKey: String

@get:Config.Key("pamPubKey")
val pamPubKey: String

@get:Config.Key("pamSecKey")
val pamSecKey: String
}

val Keys: KeysConfig = ConfigFactory.create(KeysConfig::class.java, System.getenv())
8 changes: 0 additions & 8 deletions src/testFixtures/resources/config-example.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#copy this file to `config.properties` and put real pubnub keys to run integration tests.
#copy this file to `test.properties` and put real pubnub keys to run integration tests.
#other way is to provide an environmental variables: PUB_KEY, SUB_KEY, etc.

pubKey=somePubKey
Expand Down

0 comments on commit de0b421

Please sign in to comment.