Skip to content

Commit

Permalink
✅ : rewrite test in kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Jan 27, 2020
1 parent 47a28fa commit 3ca6f20
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 98 deletions.
98 changes: 0 additions & 98 deletions src/test/java/io/codeka/gaia/hcl/HCLParserTest.java

This file was deleted.

87 changes: 87 additions & 0 deletions src/test/java/io/codeka/gaia/hcl/HCLParserTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package io.codeka.gaia.hcl

import io.codeka.gaia.modules.bo.Output
import io.codeka.gaia.modules.bo.Variable
import org.apache.commons.io.IOUtils
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import org.springframework.core.io.ClassPathResource
import java.io.IOException
import java.nio.charset.Charset

class HCLParserTest {

private val hclParser = HclParserImpl()

@Test
@Throws(IOException::class)
fun parsing_variables_shouldWorkWithVisitor() {
// given
val fileContent = IOUtils.toString(ClassPathResource("hcl/variables.tf").url, Charset.defaultCharset())

// when
val variables = hclParser.parseVariables(fileContent)

// then
Assertions.assertThat(variables).hasSize(3)
val stringVar = Variable("string_var", "string", "a test string var", "foo")
val numberVar = Variable("number_var", "number", "a test number var", "42")
val boolVar = Variable("bool_var", defaultValue = "false")
Assertions.assertThat(variables).contains(stringVar, numberVar, boolVar)
}

@Test
@Throws(IOException::class)
fun parsing_variables_shouldWork_withComplexFile() {
// given
val fileContent = IOUtils.toString(ClassPathResource("hcl/variables_aws_eks.tf").url, Charset.defaultCharset())

// when
val variables = hclParser.parseVariables(fileContent)

// then
Assertions.assertThat(variables).hasSize(49)
}

@Test
@Throws(IOException::class)
fun parsing_variables_shouldWork_withAnotherComplexFile() {
// given
val fileContent = IOUtils.toString(ClassPathResource("hcl/variables_aws_vpc.tf").url, Charset.defaultCharset())

// when
val variables = hclParser.parseVariables(fileContent)

// then
Assertions.assertThat(variables).hasSize(282)
}

@Test
@Throws(IOException::class)
fun parsing_outputs_shouldWorkWithVisitor() {
// given
val fileContent = IOUtils.toString(ClassPathResource("hcl/outputs.tf").url, Charset.defaultCharset())

// when
val outputs = hclParser.parseOutputs(fileContent)

// then
Assertions.assertThat(outputs).hasSize(2)
val output1 = Output("instance_ip_addr", "\${aws_instance.server.private_ip}", "The private IP address of the main server instance.", "false")
val output2 = Output("db_password", "aws_db_instance.db[1].password", "The password for logging in to the database.", "true")
Assertions.assertThat(outputs).contains(output1, output2)
}

@Test
@Throws(IOException::class)
fun parsing_outputs_shouldWork_withComplexFile() {
// given
val fileContent = IOUtils.toString(ClassPathResource("hcl/outputs_aws_eks.tf").url, Charset.defaultCharset())

// when
val outputs = hclParser.parseOutputs(fileContent)

// then
Assertions.assertThat(outputs).hasSize(27)
}
}

0 comments on commit 3ca6f20

Please sign in to comment.