Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
Update tests, add gcloud tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loosebazooka committed Jun 16, 2015
1 parent 2d76ad4 commit 2d06944
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 131 deletions.
49 changes: 0 additions & 49 deletions src/test/groovy/com/google/appengine/AppProjectTest.groovy

This file was deleted.

25 changes: 14 additions & 11 deletions src/test/groovy/com/google/appengine/ide/EclipseTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@
* limitations under the License.
*/
package com.google.appengine.ide

import com.google.appengine.AppEnginePlugin
import com.google.appengine.AppProjectTest
import com.google.appengine.util.VersionComparator
import com.google.gradle.test.fixture.AppProjectBuilder
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.plugins.ide.eclipse.EclipsePlugin
import org.gradle.plugins.ide.eclipse.model.EclipseModel
import org.junit.Before
import org.junit.Test

/**
* Simple test to ensure the plugin is interacting nicely with the eclipse plugin
*
* @author Appu Goundan
*/
class EclipseTest extends AppProjectTest {
class EclipseTest {

Project project;

@Before
void setUp() {
project = AppProjectBuilder.builder().withAppEngine().build();
}

@Test
void functionalConfigTest() {
Expand All @@ -42,13 +49,9 @@ class EclipseTest extends AppProjectTest {
}
}
else {
// TODO this doesn't actually do anything unless the builder uses gradle 2.3 or higher
// but it can be tested manually by using gradle 2.3, I can't to find a way using projectbuilder
// to set the gradle version. (The Gradle Connector can)
project.afterEvaluate {
assert(project.plugins.hasPlugin(EclipsePlugin))
assert(project.extensions.getByType(EclipseModel).classpath.plusConfigurations.contains(testConfig))
}
project.evaluate()
assert(project.plugins.hasPlugin(EclipsePlugin))
assert(project.extensions.getByType(EclipseModel).classpath.plusConfigurations.contains(testConfig))
}
}
}
26 changes: 18 additions & 8 deletions src/test/groovy/com/google/appengine/ide/IdeaTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@
* limitations under the License.
*/
package com.google.appengine.ide

import com.google.appengine.AppEnginePlugin
import com.google.appengine.AppProjectTest
import com.google.gradle.test.fixture.AppProjectBuilder
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.SourceSet
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.junit.Before
import org.junit.Test

class IdeaTest extends AppProjectTest {
class IdeaTest {

Project project;

@Before
void setUp() {
project = AppProjectBuilder.builder().withAppEngine().build();
}

@Test
void functionalConfigTest() {
Expand All @@ -33,12 +41,14 @@ class IdeaTest extends AppProjectTest {
SourceSet testSourceSet = project.convention.getPlugin(JavaPluginConvention).sourceSets.getByName(AppEnginePlugin.FUNCTIONAL_TEST_SOURCE_SET)

assert(project.plugins.hasPlugin(IdeaPlugin))
project.afterEvaluate {
project.plugins.withType(IdeaPlugin) { IdeaPlugin plugin ->
assert (plugin.model.module.testSourceDirs.contains(testSourceSet))
assert (plugin.model.module.scopes.TEST.plus.contains(testRuntimeConfig))
assert (plugin.model.module.scopes.TEST.plus.contains(testCompileConfig))
project.evaluate()

project.plugins.withType(IdeaPlugin) { IdeaPlugin plugin ->
testSourceSet.allSource.srcDirs.each { File dir ->
assert (plugin.model.module.testSourceDirs.contains(dir))
}
assert (plugin.model.module.scopes.TEST.plus.contains(testRuntimeConfig))
assert (plugin.model.module.scopes.TEST.plus.contains(testCompileConfig))
}
}
}
3 changes: 1 addition & 2 deletions src/test/groovy/com/google/appengine/model/ModelTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package com.google.appengine.model

import com.google.appengine.AppIntegrationTest
import com.google.gradle.test.integration.AppIntegrationTest
import com.google.appengine.gradle.model.AppEngineModel
import org.gradle.tooling.GradleConnector
import org.gradle.tooling.ProjectConnection
import org.junit.Assert
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package com.google.appengine.task.endpoints

import com.google.appengine.AppIntegrationTest
import org.gradle.tooling.GradleConnector
import com.google.gradle.test.integration.AppIntegrationTest
import org.gradle.tooling.ProjectConnection
import org.junit.Assert
import org.junit.Test
Expand Down
110 changes: 110 additions & 0 deletions src/test/groovy/com/google/gcloud/dsl/GCloudDslTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.google.gcloud.dsl

import com.google.gradle.test.fixture.AppProjectBuilder
import org.gradle.api.Project
import org.junit.BeforeClass
import org.junit.Test

import static org.junit.Assert.*

/**
* Test the parsing/execution of a build file with a gcloud configuration
*/
class GCloudDslTest {

static Project root
static Project child1
static Project child2

@BeforeClass
static void makeProject() {
root = AppProjectBuilder.builder().withAppEngine().withGCloud().build()
child1 = AppProjectBuilder.builder().withAppEngine().withParent(root).withName("child1").build()
child2 = AppProjectBuilder.builder().withAppEngine().withParent(root).withName("child2").build()

root.gcloud {
configurations {
allChildren {
args project: "test-project"
runArgs host: ":8889", "jvm-flag": ["-X1", "-X2"]
deployArgs version: "tomato"
modules ":child1", ":child2", ":child2"
}
onlyRoot {
args project: "other-project"
}
indexes {
args project: "other-other-project"
descriptors "index.yaml", "index.yaml"
}
}
}

// make sure to evaluate the project, so we can see everything
root.evaluate()
}

@Test
void testTasks() {
// why no assertEquals for ints? some autoboxing issue here
assertEquals(3L, root.tasks.findAll { it.name.startsWith("gcloudAppDeploy") }.size())

assertNotNull(root.tasks.findByName("gcloudAppDeployAllChildren"))
assertNotNull(root.tasks.findByName("gcloudAppDeployOnlyRoot"))
assertNotNull(root.tasks.findByName("gcloudAppDeployIndexes"))

assertTrue(root.tasks.findAll { it.name.startsWith("gcloudAppRun") }.size() == 2)
assertNotNull(root.tasks.findByName("gcloudAppRunAllChildren"))
assertNotNull(root.tasks.findByName("gcloudAppRunOnlyRoot"))

assertTrue(root.tasks.findAll { it.name.startsWith("gcloudAppStop") }.size() == 2)
assertNotNull(root.tasks.findByName("gcloudAppStopAllChildren"))
assertNotNull(root.tasks.findByName("gcloudAppStopOnlyRoot"))
}

@Test
void testExtension() {
GCloudPluginExtension extension = root.extensions.gcloud

assertEquals(3L, extension.configurations.size())

GCloudConfigurable allChildren = extension.configurations.findByName("allChildren")
GCloudConfigurable onlyRoot = extension.configurations.findByName("onlyRoot")
GCloudConfigurable indexes = extension.configurations.findByName("indexes")

assertNotNull(allChildren)
assertNotNull(onlyRoot)
assertNotNull(indexes)

assertEquals(1L, allChildren.args.size())
assertEquals(2L, allChildren.runArgs.size())
assertEquals(1L, allChildren.deployArgs.size())
assertEquals(1L, allChildren.descriptors.size())
assertEquals(2L, allChildren.modules.size())
assertEquals("test-project", allChildren.args.get("project"))
assertEquals(":8889", allChildren.runArgs.get("host"))
assertEquals("tomato", allChildren.deployArgs.get("version"))
assertTrue(allChildren.descriptors.contains("app.yaml"))
assertNotNull(allChildren.modules.find { Project p -> p.path.equals ":child1" })
assertNotNull(allChildren.modules.find { Project p -> p.path.equals ":child2" })

assertTrue(onlyRoot.args.size() == 1)
assertTrue(onlyRoot.runArgs.size() == 0)
assertTrue(onlyRoot.deployArgs.size() == 0)
assertTrue(onlyRoot.descriptors.size() == 1)
assertTrue(onlyRoot.modules.size() == 1)
assertEquals("other-project", onlyRoot.args.get("project"))
assertTrue(onlyRoot.descriptors.contains("app.yaml"))
assertNotNull(onlyRoot.modules.find { Project p -> p.path.equals ":" })

assertTrue(indexes.args.size() == 1)
assertTrue(indexes.runArgs.size() == 0)
assertTrue(indexes.deployArgs.size() == 0)
assertTrue(indexes.descriptors.size() == 1)
assertTrue(indexes.modules.size() == 1)
assertEquals("other-other-project", indexes.args.get("project"))
assertTrue(indexes.descriptors.contains("index.yaml"))
assertNotNull(indexes.modules.find { Project p -> p.path.equals ":" })
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.google.gcloud.wrapper

import aQute.libg.command.Command
import com.beust.jcommander.internal.Lists
import com.google.gcloud.exec.command.CommandBuilder
import spock.lang.Ignore
import spock.lang.Specification

/**
* Command Builder test
*/
class CommandBuilderTest extends Specification {
def "Test command builder"() {
given: "A builder"
CommandBuilder builder = new CommandBuilder()

when: "Create a command"
builder.addCommand("gcloud", "test1", "test2")
.addOption("bool1", true.toString())
.addOption("bool2", false.toString()) // false value
.addArgument("path1")
.addOption("opt1", "value")
.addOption("--opt2", "value")
.addOption("--multi", ["value1", "value2"])
.addArgument("path2");
String[] command = builder.buildCommand()

then: "Check command and order"
command.length == 10
command[0] == "gcloud"
command[1] == "test1"
command[2] == "test2"
command[3] == "--bool1"
command[4] == "--opt1=value"
command[5] == "--opt2=value"
command[6] == "--multi=value1"
command[7] == "--multi=value2"
command[8] == "path1"
command[9] == "path2"
}

def "Illegal option test"() {
given: "A builder"
CommandBuilder builder = new CommandBuilder()

when: "Illegal option added"
builder.addOption(a, b)

then:
thrown(IllegalArgumentException)

where:
a | b
null | "x"
"" | "x"
" "| "x"
}

def "Illegal argument test"() {
given: "A builder"
CommandBuilder builder = new CommandBuilder()

when: "Illegal argument added"
builder.addArgument(a)

then:
thrown(IllegalArgumentException)

where:
a | _
null | _
"" | _
" "| _
}
}
Loading

0 comments on commit 2d06944

Please sign in to comment.