-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sets up initial test module structure, container test rule and initia…
…l Skaffold file tests. (GoogleContainerTools#40) * Set up initial test module structure, container test rule, dependencies and Skaffold tests. * Implemented junit4 rule.
- Loading branch information
Showing
7 changed files
with
160 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
59 changes: 59 additions & 0 deletions
59
common-test-lib/src/main/kotlin/com/google/container/tools/test/ContainerToolsRule.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,59 @@ | ||
/* | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.container.tools.test | ||
|
||
import com.intellij.testFramework.EdtTestUtil | ||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture | ||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory | ||
import com.intellij.util.ThrowableRunnable | ||
import org.junit.rules.TestRule | ||
import org.junit.runner.Description | ||
import org.junit.runners.model.Statement | ||
|
||
/** | ||
* A custom [TestRule] for Container Tools unit tests. | ||
* | ||
* This rule adds the following functionality: | ||
* | ||
* * Creates an [IdeaProjectTestFixture] and makes it available for tests via property. By default | ||
* this text fixture is "light", i.e. instance of [LightIdeaTestFixture]. | ||
*/ | ||
class ContainerToolsRule : TestRule { | ||
lateinit var ideaProjectTestFixture: IdeaProjectTestFixture | ||
|
||
override fun apply(baseStatement: Statement, description: Description): Statement = | ||
object : Statement() { | ||
override fun evaluate() { | ||
try { | ||
setUpRule() | ||
baseStatement.evaluate() | ||
} finally { | ||
tearDownRule() | ||
} | ||
} | ||
} | ||
|
||
private fun setUpRule() { | ||
ideaProjectTestFixture = | ||
IdeaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder().fixture | ||
EdtTestUtil.runInEdtAndWait(ThrowableRunnable { ideaProjectTestFixture.setUp() }) | ||
} | ||
|
||
private fun tearDownRule() { | ||
EdtTestUtil.runInEdtAndWait(ThrowableRunnable { ideaProjectTestFixture.tearDown() }) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
*/ | ||
|
||
include 'skaffold' | ||
include 'common-test-lib' |
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,19 @@ | ||
/* | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
dependencies { | ||
compile(project(":common-test-lib")) | ||
} |
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
59 changes: 59 additions & 0 deletions
59
skaffold/src/test/kotlin/com/google/container/tools/skaffold/SkaffoldFilesTest.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,59 @@ | ||
/* | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.container.tools.skaffold | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import com.google.container.tools.test.ContainerToolsRule | ||
import com.intellij.mock.MockVirtualFile | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
/** Unit tests for Skaffold files functionality in [SkaffoldFiles.kt] */ | ||
class SkaffoldFilesTest { | ||
@get:Rule | ||
val containerToolsRule = ContainerToolsRule() | ||
|
||
@Test | ||
fun `valid skaffold file is accepted`() { | ||
val skaffoldFile = MockVirtualFile.file("skaffold.yaml") | ||
skaffoldFile.setText("apiVersion: skaffold/v1alpha2") | ||
|
||
assertThat(isSkaffoldFile(skaffoldFile)).isTrue() | ||
} | ||
|
||
@Test | ||
fun `extra spaces and tabs in header skaffold file is accepted`() { | ||
val skaffoldFile = MockVirtualFile.file("skaffold.yaml") | ||
skaffoldFile.setText( | ||
""" apiVersion: skaffold/v1alpha3 | ||
kind: Config | ||
build: | ||
""" | ||
) | ||
|
||
assertThat(isSkaffoldFile(skaffoldFile)).isTrue() | ||
} | ||
|
||
@Test | ||
fun `kubernetes file is not valid skaffold file`() { | ||
val k8sFile = MockVirtualFile.file("deploy.yaml") | ||
k8sFile.setText("apiVersion: apps/v1") | ||
|
||
assertThat(isSkaffoldFile(k8sFile)).isFalse() | ||
} | ||
} |