-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3f2455
commit 4f37042
Showing
8 changed files
with
164 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
test_runner/src/test/kotlin/ftl/args/FetchProjectIdTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package ftl.args | ||
|
||
import com.google.cloud.ServiceOptions | ||
import com.google.common.truth.Truth.assertThat | ||
import ftl.config.FtlConstants | ||
import ftl.config.defaultCredentialPath | ||
import ftl.util.getGACPathOrEmpty | ||
import io.mockk.every | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkAll | ||
import org.junit.After | ||
import org.junit.AfterClass | ||
import org.junit.Before | ||
import org.junit.BeforeClass | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
import java.io.File | ||
|
||
class FetchProjectIdTest { | ||
|
||
// mock server is not torn down between test classes | ||
// this is workaround until better solution is implemented | ||
companion object { | ||
@JvmStatic | ||
@BeforeClass | ||
fun noUseMock() { | ||
FtlConstants.useMock = false | ||
} | ||
|
||
@JvmStatic | ||
@AfterClass | ||
fun useMock() { | ||
FtlConstants.useMock = true | ||
} | ||
} | ||
|
||
@get:Rule | ||
val folder = TemporaryFolder() | ||
|
||
private lateinit var gac: File | ||
|
||
private lateinit var def: File | ||
|
||
@Before | ||
fun setup() { | ||
gac = folder.newFile("gap.json").also { it.writeText("""{"project_id": "id_from_gac"}""") } | ||
def = folder.newFile("def.json").also { it.writeText("""{"project_id": "id_from_def"}""") } | ||
} | ||
|
||
@After | ||
fun teardown() = unmockkAll() | ||
|
||
@Test | ||
fun `should fetch project id from GCLOUD_APLICATION_CREDENTIALS`() { | ||
mockkStatic("ftl.util.Utils") { | ||
every { getGACPathOrEmpty() } returns gac.absolutePath.toString() | ||
assertThat(ArgsHelper.getDefaultProjectIdOrNull()).isEqualTo("id_from_gac") | ||
} | ||
} | ||
|
||
@Test | ||
fun `should fetch project id from default credentials`() { | ||
mockkStatic( | ||
"ftl.util.Utils", | ||
"ftl.config.CredentialsKt", | ||
ServiceOptions::class.qualifiedName ?: "" | ||
) { | ||
every { defaultCredentialPath } returns def.toPath() | ||
every { getGACPathOrEmpty() } returns "" | ||
every { ServiceOptions.getDefaultProjectId() } returns null | ||
assertThat(ArgsHelper.getDefaultProjectIdOrNull()).isEqualTo("id_from_def") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters