add ConfigRepositoryKtTest.kt & improve error messages for missing config file resp. wrong config format
parent
f3f3121395
commit
cb23a563e8
@ -0,0 +1,47 @@
|
||||
package org.domaindrivenarchitecture.provs.workplace.infrastructure
|
||||
|
||||
import com.charleskorn.kaml.InvalidPropertyValueException
|
||||
import org.domaindrivenarchitecture.provs.ubuntu.secret.SecretSourceType
|
||||
import org.domaindrivenarchitecture.provs.workplace.domain.WorkplaceType
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
internal class ConfigRepositoryKtTest {
|
||||
|
||||
@Test
|
||||
fun getConfig_successful() {
|
||||
// when
|
||||
val config = getConfig("src/test/resources/TestWorkplaceConfig.yaml")
|
||||
|
||||
// then
|
||||
assertEquals(WorkplaceType.OFFICE, config.type)
|
||||
assertEquals("username", config.gitUserName)
|
||||
assertEquals("for@git.email", config.gitEmail)
|
||||
|
||||
assertEquals(SecretSourceType.FILE, config.ssh?.sourceType)
|
||||
assertEquals("~/.ssh/id_rsa.pub", config.ssh?.publicKey)
|
||||
assertEquals("~/.ssh/id_rsa", config.ssh?.privateKey)
|
||||
|
||||
assertEquals(SecretSourceType.GOPASS, config.gpg?.sourceType)
|
||||
assertEquals("path/to/pub.key", config.gpg?.publicKey)
|
||||
assertEquals("path/to/priv.key", config.gpg?.privateKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getConfig_fails_due_to_invalidProperty() {
|
||||
assertThrows<InvalidPropertyValueException> {
|
||||
getConfig("src/test/resources/InvalidWorkplaceConfig.yaml")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getConfig_fails_due_to_non_existing_file() {
|
||||
assertThrows<FileNotFoundException> {
|
||||
getConfig("src/test/resources/Idonotexist.yaml")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
type: WRONGTYPE # IDE, OFFICE or MINIMAL
|
||||
nonexistingkey: foo
|
@ -0,0 +1,14 @@
|
||||
# type is required
|
||||
type: OFFICE # IDE, OFFICE or MINIMAL
|
||||
|
||||
# fields below are optional, either remove them or update them with your data
|
||||
ssh:
|
||||
sourceType: FILE # FILE or GOPASS
|
||||
publicKey: ~/.ssh/id_rsa.pub # file path resp. gopass path to public key
|
||||
privateKey: ~/.ssh/id_rsa # file path resp. gopass path to private key
|
||||
gpg:
|
||||
sourceType: GOPASS # FILE or GOPASS
|
||||
publicKey: path/to/pub.key # file path resp. gopass path to public key
|
||||
privateKey: path/to/priv.key # file path resp. gopass path to private key
|
||||
gitUserName: username # global git user name
|
||||
gitEmail: for@git.email # global git email
|
Loading…
Reference in New Issue