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

Commit

Permalink
Add itegration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johndevs committed Mar 30, 2019
1 parent dea4639 commit d33af23
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 19 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
language: groovy
jdk:
- oraclejdk8
script: "./gradlew --stacktrace --info --parallel check"
script:
- "./gradlew --stacktrace --info --parallel check"
after_script:
- docker ps -a
branches:
only:
- "master"
services:
- docker
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand Down
14 changes: 6 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ targetCompatibility = 1.8
* Sources
*
**********************************************************************************************************************/
/*

sourceSets {
functionalTest {
groovy {
Expand All @@ -60,7 +60,6 @@ sourceSets {
runtimeClasspath += output + compileClasspath
}
}
*/

processResources {
from(sourceSets.main.resources.srcDirs){
Expand Down Expand Up @@ -138,7 +137,7 @@ groovydoc {
* Testing & Quality
*
***********************************************************************************************************************/
/*

task functionalTest(type: Test) {
dependsOn test
group = 'Verification'
Expand All @@ -161,17 +160,16 @@ task functionalTest(type: Test) {
}
}
check.dependsOn functionalTest
*/

codenarc{
toolVersion = '1.1'
configFile = rootProject.file('config/codenarc/ruleset.groovy')
maxPriority1Violations = 0
maxPriority2Violations = 0
maxPriority3Violations = 0
// codenarcFunctionalTest {
// configFile = rootProject.file('config/codenarc/ruleset-test.groovy')
// }
codenarcFunctionalTest {
configFile = rootProject.file('config/codenarc/ruleset-test.groovy')
}
codenarcTest {
configFile = rootProject.file('config/codenarc/ruleset-test.groovy')
}
Expand All @@ -198,7 +196,7 @@ plugins.withType(GroovyBasePlugin) {
*
***********************************************************************************************************************/
gradlePlugin {
//testSourceSets sourceSets.functionalTest
testSourceSets sourceSets.functionalTest
plugins {
fnPlugin {
id = 'com.devsoap.fn'
Expand Down
85 changes: 85 additions & 0 deletions src/functionalTest/groovy/com/devsoap/fn/CreateFunctionTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2018-2019 Devsoap Inc.
*
* 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.devsoap.fn

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

import org.gradle.testkit.runner.BuildResult
import java.nio.file.Paths

/**
* Tests creation of FN projects
*
* @author John Ahlroos
* @since 1.0
*/
class CreateFunctionTest extends FunctionalTest {

void 'default project is created and compiles'() {
setup:
File rootDir = testProjectDir.root
File javaSourceDir = Paths.get(rootDir.canonicalPath, 'src', 'main', 'java').toFile()
File functionFile = Paths.get(javaSourceDir.canonicalPath, 'MyFunction.java').toFile()
when:
BuildResult result = run'fnCreateFunction', 'jar'
then:
result.task(':fnCreateFunction').outcome == SUCCESS
result.task(':jar').outcome == SUCCESS
functionFile.exists()
}

void 'default Groovy project is created and compiles'() {
setup:
extraPlugins = ['groovy':null]

buildFile << '''
dependencies {
compile fn.groovy()
}
'''.stripIndent()

File rootDir = testProjectDir.root
File javaSourceDir = Paths.get(rootDir.canonicalPath, 'src', 'main', 'groovy').toFile()
File functionFile = Paths.get(javaSourceDir.canonicalPath, 'MyFunction.groovy').toFile()
when:
BuildResult result = run'fnCreateFunction', 'jar'
then:
result.task(':fnCreateFunction').outcome == SUCCESS
result.task(':jar').outcome == SUCCESS
functionFile.exists()
}

void 'default Kotlin project is created and compiles'() {
setup:
extraPlugins = ['org.jetbrains.kotlin.jvm':'1.3.21']

buildFile << '''
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
}
'''.stripIndent()

File rootDir = testProjectDir.root
File javaSourceDir = Paths.get(rootDir.canonicalPath, 'src', 'main', 'kotlin').toFile()
File functionFile = Paths.get(javaSourceDir.canonicalPath, 'MyFunction.kt').toFile()
when:
BuildResult result = run'fnCreateFunction', 'jar'
then:
result.task(':fnCreateFunction').outcome == SUCCESS
result.task(':jar').outcome == SUCCESS
functionFile.exists()
}
}
50 changes: 50 additions & 0 deletions src/functionalTest/groovy/com/devsoap/fn/DeployTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2018-2019 Devsoap Inc.
*
* 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.devsoap.fn

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

import spock.lang.Ignore
import org.gradle.testkit.runner.BuildResult

/**
* Tests function deployment
*
* @author John Ahlroos
* @since 1.0
*/
class DeployTest extends FunctionalServerTest {

/**
* FIXME For some reason Travis cannot connect to the server after it has started
*/
@Ignore
void 'deploy default function'() {
setup:
run'fnCreateFunction'
when:
BuildResult deployResult = run'fnDeploy'
BuildResult invokeResult = run 'fnInvoke'
then:
deployResult.task(':fnDeploy').outcome == SUCCESS
deployResult.output.contains('Successfully created function')
deployResult.output.contains('Successfully created trigger')

invokeResult.task(':fnInvoke').outcome == SUCCESS
invokeResult.output.contains('Hello, world!')
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2018-2019 Devsoap Inc.
*
* 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.devsoap.fn

import static junit.framework.TestCase.fail
import static org.gradle.testkit.runner.TaskOutcome.FAILED

import org.gradle.testkit.runner.BuildResult

/**
* Base class for functional tests that requires a running FN server
*
* @author John Ahlroos
* @since 1.0
*/
class FunctionalServerTest extends FunctionalTest {

protected void setup() {
BuildResult result = run('fnStart')
if (result.task(':fnStart').outcome == FAILED) {
fail('Failed to start FN server')
} else {
println 'Successfully started FN server!'
}
}

protected void cleanup() {
BuildResult result = run('fnStop')
if (result.task(':fnStop').outcome == FAILED) {
fail('Failed to stio FN server')
} else {
println 'Successfully stopped FN server!'
}
}
}
Loading

0 comments on commit d33af23

Please sign in to comment.