-
Notifications
You must be signed in to change notification settings - Fork 42
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
Benjamin AIMONE
authored and
Benjamin AIMONE
committed
Sep 28, 2022
1 parent
4023839
commit 85ea7dc
Showing
8 changed files
with
131 additions
and
15 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
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,108 @@ | ||
import com.klaxit.hiddensecrets.HiddenSecretsPlugin | ||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.data.Row4 | ||
import io.kotest.datatest.withData | ||
import io.kotest.matchers.shouldBe | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.rules.TemporaryFolder | ||
import java.io.File | ||
|
||
/** | ||
* Test that correct names of keys are present in java and cpp files. | ||
* | ||
* From @pratclot | ||
* https://github.com/klaxit/hidden-secrets-gradle-plugin/pull/64 | ||
*/ | ||
class IntegrationTest : WordSpec({ | ||
|
||
"Apply the plugin" should { | ||
val testProjectDir = TemporaryFolder() | ||
testProjectDir.create() | ||
val buildFile = testProjectDir.newFile("build.gradle") | ||
buildFile.appendText( | ||
""" | ||
plugins { | ||
id 'com.klaxit.hiddensecrets' | ||
id 'com.android.application' | ||
} | ||
android { | ||
compileSdkVersion 29 | ||
} | ||
""".trimIndent() | ||
) | ||
|
||
val gradleRunner = GradleRunner.create() | ||
.withPluginClasspath() | ||
.withProjectDir(testProjectDir.root) | ||
.withTestKitDir(testProjectDir.newFolder()) | ||
|
||
val test = this | ||
"Make command ${HiddenSecretsPlugin.TASK_HIDE_SECRET} succeed" { | ||
test.withData( | ||
Row4("thisIsATestKey", "thisIsATestKeyName", "thisIsATestKeyName", "com.package.test"), | ||
Row4( | ||
"this_is_a_test_key", | ||
"this_is_a_test_key_name", | ||
"this_1is_1a_1test_1key_1name", | ||
"com.package.test" | ||
), | ||
) { (key, keyName, cppKeyName, packageName) -> | ||
testProjectDir.run { | ||
val packagePath = packageName.replace('.', '/') | ||
val packageDirJava = newFolder("src/main/java/$packagePath") | ||
val packageDirCpp = newFolder("src/main/cpp/") | ||
|
||
val fileJava = File(packageDirJava, "Secrets.kt") | ||
val fileCpp = File(packageDirCpp, "secrets.cpp") | ||
|
||
var inputStream = javaClass.classLoader.getResourceAsStream("kotlin/Secrets.kt") | ||
inputStream?.bufferedReader()?.lines()?.forEach { | ||
fileJava.appendText(it + "\n") | ||
} | ||
inputStream?.close() | ||
|
||
inputStream = javaClass.classLoader.getResourceAsStream("cpp/secrets.cpp") | ||
inputStream?.bufferedReader()?.forEachLine { | ||
fileCpp.appendText(it + "\n") | ||
} | ||
inputStream?.close() | ||
|
||
gradleRunner.withArguments() | ||
val result = gradleRunner | ||
.withArguments( | ||
HiddenSecretsPlugin.TASK_HIDE_SECRET, | ||
"-Pkey=$key", | ||
"-PkeyName=$keyName", | ||
"-Ppackage=$packageName" | ||
) | ||
.build() | ||
println(result.output) | ||
|
||
// Search key name in java | ||
var javaCorrectNameFound = false | ||
fileJava.bufferedReader().forEachLine { | ||
if (it.contains(keyName)) { | ||
javaCorrectNameFound = true | ||
} | ||
} | ||
javaCorrectNameFound shouldBe true | ||
// Search function name in ccp | ||
val expectedCppFunctionName = "Java_${packageName.replace('.', '_')}_Secrets_get$cppKeyName(" | ||
println("expectedFunctionName: $expectedCppFunctionName") | ||
var cppCorrectNameFound = false | ||
fileCpp.bufferedReader().forEachLine { | ||
if (it.contains(expectedCppFunctionName)) { | ||
cppCorrectNameFound = true | ||
} | ||
} | ||
cppCorrectNameFound shouldBe true | ||
|
||
fileJava.delete() | ||
fileCpp.delete() | ||
packageDirJava.delete() | ||
packageDirCpp.delete() | ||
} | ||
} | ||
} | ||
} | ||
}) |
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