Skip to content

Commit

Permalink
feat(plugins): Add echo-plugins-test module (#848)
Browse files Browse the repository at this point in the history
* feat(plugins): Add echo-plugins-test module

* fix(build): Add kotlinVersion and add nebula.kotlin plugin
  • Loading branch information
jonsie authored Apr 19, 2020
1 parent 32e6a8c commit 6978a4b
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ data
.project
.settings/
bin/
plugins/
/plugins/
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

plugins {
id 'io.spinnaker.project' version "$spinnakerGradleVersion" apply false
id "nebula.kotlin" version "$kotlinVersion" apply false
}

subprojects {
Expand Down
21 changes: 21 additions & 0 deletions echo-plugins-test/echo-plugins-test.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apply from: "${project.rootDir}/gradle/kotlin.gradle"

dependencies {
implementation(project(":echo-api"))
implementation("com.netflix.spinnaker.kork:kork-exceptions")

testImplementation(project(":echo-web"))
testImplementation(project(":echo-core"))

testImplementation("com.netflix.spinnaker.kork:kork-plugins")
testImplementation("com.netflix.spinnaker.kork:kork-plugins-tck")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

test {
useJUnitPlatform {
includeEngines("junit-jupiter", "junit-vintage")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2020 Netflix, 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.netflix.spinnaker.echo.plugins

import org.pf4j.Plugin
import org.pf4j.PluginWrapper

class EchoPlugin(pluginWrapper: PluginWrapper) : Plugin(pluginWrapper)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2020 Netflix, 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.netflix.spinnaker.echo.plugins

import com.netflix.spinnaker.echo.api.events.Event
import com.netflix.spinnaker.echo.api.events.EventListener
import org.pf4j.Extension

@Extension
class EventListenerExtension : EventListener {
override fun processEvent(event: Event) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2020 Netflix, 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.netflix.spinnaker.echo.plugins.test

import com.netflix.spinnaker.echo.Application
import com.netflix.spinnaker.echo.plugins.EchoPlugin
import com.netflix.spinnaker.echo.plugins.EventListenerExtension
import com.netflix.spinnaker.kork.plugins.SpinnakerPluginManager
import com.netflix.spinnaker.kork.plugins.internal.PluginJar
import com.netflix.spinnaker.kork.plugins.tck.PluginsTckFixture
import java.io.File
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.ApplicationContext
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource

class EchoPluginsFixture : PluginsTckFixture, EchoTestService() {

final override val plugins = File("build/plugins")

final override val enabledPlugin: PluginJar
final override val disabledPlugin: PluginJar
final override val versionNotSupportedPlugin: PluginJar

override val extensionClassNames: MutableList<String> = mutableListOf(
EventListenerExtension::class.java.name
)

final override fun buildPlugin(pluginId: String, systemVersionRequirement: String): PluginJar {
return PluginJar.Builder(plugins.toPath().resolve("$pluginId.jar"), pluginId)
.pluginClass(EchoPlugin::class.java.name)
.pluginVersion("1.0.0")
.manifestAttribute("Plugin-Requires", "echo$systemVersionRequirement")
.extensions(extensionClassNames)
.build()
}

@Autowired
override lateinit var spinnakerPluginManager: SpinnakerPluginManager

@Autowired
lateinit var applicationContext: ApplicationContext

init {
plugins.delete()
plugins.mkdir()
enabledPlugin = buildPlugin("com.netflix.echo.enabled.plugin", ">=1.0.0")
disabledPlugin = buildPlugin("com.netflix.echo.disabled.plugin", ">=1.0.0")
versionNotSupportedPlugin = buildPlugin("com.netflix.echo.version.not.supported.plugin", ">=2.0.0")
}
}

@SpringBootTest(classes = [Application::class])
@ContextConfiguration(classes = [PluginTestConfiguration::class])
@TestPropertySource(properties = ["spring.config.location=classpath:echo-plugins-test.yml"])
@AutoConfigureMockMvc
abstract class EchoTestService

@TestConfiguration
internal open class PluginTestConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2020 Netflix, 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.netflix.spinnaker.echo.plugins.test

import com.netflix.spinnaker.echo.api.events.EventListener
import com.netflix.spinnaker.kork.plugins.tck.PluginsTck
import com.netflix.spinnaker.kork.plugins.tck.serviceFixture
import dev.minutest.rootContext
import strikt.api.expect
import strikt.assertions.isNotNull

class EchoPluginsTest : PluginsTck<EchoPluginsFixture>() {

fun tests() = rootContext<EchoPluginsFixture> {
context("an echo integration test environment and an echo plugin") {
serviceFixture {
EchoPluginsFixture()
}

defaultPluginTests()

test("Event listener extension is loaded into context") {
val eventListeners = applicationContext.getBeansOfType<EventListener>(EventListener::class.java)
val extensionBeanName = "com.netflix.echo.enabled.plugin.EventListenerExtension".replace(".", "")
val extension = eventListeners[extensionBeanName]
expect {
that(extension).isNotNull()
}
}
}
}
}
28 changes: 28 additions & 0 deletions echo-plugins-test/src/test/resources/echo-plugins-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
front50:
baseUrl: 'http://localhost:8080'

orca:
baseUrl: 'http://localhost:8083'

resilience4j.circuitbreaker:
instances:
telemetry:
# This needs to stay false, because if the telemetry endpoint goes down, Echo goes unhealthy (no good!)
registerHealthIndicator: false

spring:
application:
name: echo

spinnaker:
baseUrl: 'http://localhost:9000'

extensibility:
plugins-root-path: build/plugins
plugins:
com.netflix.echo.enabled.plugin:
enabled: true
com.netflix.echo.disabled.plugin:
enabled: false
com.netflix.echo.version.not.supported.plugin:
enabled: true
12 changes: 12 additions & 0 deletions echo-web/echo-web.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ run {
systemProperty('spring.config.additional-location', project.springConfigLocation)
systemProperty('spring.profiles.active', project.springProfiles)
}

test {
//The Implementation-Version is set in the MANIFEST.MF for the JAR produced via testing so that
//assertions can be made against the version (see echo-plugins-test, for example).
jar {
manifest {
attributes(
'Implementation-Version': '1.0.0'
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
import com.netflix.spinnaker.kork.boot.DefaultPropertiesBuilder;
import com.netflix.spinnaker.kork.configserver.ConfigServerBootstrap;
import java.util.Map;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

/** Application entry point. */
@Configuration
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, GsonAutoConfiguration.class})
@EnableScheduling
@ComponentScan({"com.netflix.spinnaker.echo.config", "com.netflix.spinnaker.config"})
@SpringBootApplication(
scanBasePackages = {"com.netflix.spinnaker.echo.config", "com.netflix.spinnaker.config"},
exclude = {DataSourceAutoConfiguration.class, GsonAutoConfiguration.class})
public class Application extends SpringBootServletInitializer {
private static final Map<String, Object> DEFAULT_PROPS =
new DefaultPropertiesBuilder().property("spring.application.name", "echo").build();
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ fiatVersion=1.18.3
korkVersion=7.37.0
org.gradle.parallel=true
spinnakerGradleVersion=8.0.0-rc.3
kotlinVersion=1.3.71
43 changes: 43 additions & 0 deletions gradle/kotlin.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2017 Netflix, 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.
*/

apply plugin: "nebula.kotlin"

compileKotlin {
kotlinOptions {
languageVersion = "1.3"
jvmTarget = "1.8"
freeCompilerArgs += ["-progressive"]
}
}

compileTestKotlin {
kotlinOptions {
languageVersion = "1.3"
jvmTarget = "1.8"
freeCompilerArgs += ["-progressive"]
}
}

configurations.all {
resolutionStrategy {
eachDependency { details ->
if (details.requested.group == "org.jetbrains.kotlin") {
details.useVersion kotlinVersion
}
}
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ include 'echo-api',
'echo-scheduler',
'echo-rest',
'echo-webhooks',
'echo-plugins-test',
'echo-pubsub-core',
'echo-pubsub-aws',
'echo-pubsub-google',
Expand Down

0 comments on commit 6978a4b

Please sign in to comment.