Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom glue packages #81

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,40 @@ You can add the configuration file when running the test via `yaks` CLI like fol
yaks test --settings yaks.dependency.yaml camel-route.feature
```

## Runtime configuration

There are several runtime options that you can set in order to configure which tests to run for instance. Each test directory
can have its own `yaks-config.yaml` configuration file that holds the runtime options for this specific test suite.

```yaml
config:
runtime:
cucumber:
tags:
- "not @ignored"
glue:
- "org.citrusframework.yaks"
- "com.company.steps.custom"
```

The sample above uses different runtime options for Cucumber to specify a tag filter and some custom glue packages that
should be loaded. The given runtime options will be set as environment variables in the YAKS runtime pod.

You can also specify the Cucumber options that get passed to the Cucumber runtime.

```yaml
config:
runtime:
cucumber:
options: "--strict --monochrome --glue org.citrusframework.yaks"
```

Also we can make use of command line options when using the `yaks` binary.

```bash
yaks test hello-world.feature --tag @regression --glue org.citrusframework.yaks
```

## For YAKS Developers

Requirements:
Expand Down
4 changes: 4 additions & 0 deletions examples/extension/extension.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ Feature: extension
Scenario: print extended slogan
Given YAKS does Cloud-Native BDD testing
Then YAKS can be extended!

@ignored
Scenario:
Given Should fail if not ignored
15 changes: 7 additions & 8 deletions examples/extension/steps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,27 @@
<artifactId>steps</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<citrus.version>3.0.0-M1</citrus.version>
<cucumber.version>5.4.2</cucumber.version>
</properties>
<dependencies>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>3.0.2</version>
<version>${cucumber.version}</version>
</dependency>

<dependency>
<groupId>com.consol.citrus</groupId>
<artifactId>citrus-core</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.consol.citrus</groupId>
<artifactId>citrus-java-dsl</artifactId>
<version>2.8.0</version>
<version>${citrus.version}</version>
</dependency>
<dependency>
<groupId>com.consol.citrus</groupId>
<artifactId>citrus-cucumber</artifactId>
<version>2.8.0</version>
<version>${citrus.version}</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.company.steps.custom;

import com.consol.citrus.TestCaseRunner;
import com.consol.citrus.annotations.CitrusResource;
import io.cucumber.java.en.Then;

import static com.consol.citrus.actions.EchoAction.Builder.echo;

public class CustomSteps {

@CitrusResource
private TestCaseRunner runner;

@Then("^YAKS can be extended!$")
public void yaksCanBeExtended() {
runner.run(echo("YAKS can be extended!"));
}

}

This file was deleted.

8 changes: 8 additions & 0 deletions examples/extension/yaks-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config:
runtime:
cucumber:
tags:
- "not @ignored"
glue:
- "org.citrusframework.yaks"
- "com.company.steps.custom"
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,7 @@
@RunWith(Cucumber.class)
@CucumberOptions(
strict = true,
glue = {
"com.consol.citrus.cucumber.step.runner.core",
"org.citrusframework.yaks.http",
"org.citrusframework.yaks.swagger",
"org.citrusframework.yaks.camel",
"org.citrusframework.yaks.camelk",
"org.citrusframework.yaks.jdbc",
"org.citrusframework.yaks.jms",
"org.citrusframework.yaks.kafka",
"org.citrusframework.yaks.standard",
"org.citrusframework.yaks.hooks",
},
extraGlue = { "com.consol.citrus.cucumber.step.runner.core" },
plugin = { "org.citrusframework.yaks.report.TestReporter" }
)
public class YaksTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public void yaksRocks() {
public void print(String message) {
runner.run(echo(message));
}

@Then("^(?:log|print)$")
public void printMultiline(String message) {
runner.run(echo(message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ Feature: Standard steps
Scenario: print log messages
Given print 'BDD testing on Kubernetes with YAKS'
Then print 'YAKS rocks!'

Scenario: print multiline log messages
Given print
"""
YAKS rocks!
"""
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class EnvironmentSettingDependencyLoaderTest {
private Properties properties = new Properties();

@Test
public void shouldLoadFromSystemProperties() throws LifecycleExecutionException {
public void shouldLoadFromEnv() throws LifecycleExecutionException {
EnvironmentSettingDependencyLoader loader = new EnvironmentSettingDependencyLoader() {
@Override
protected String getEnvSetting(String name) {
Expand All @@ -49,7 +49,7 @@ protected String getEnvSetting(String name) {
}

@Test
public void shouldLoadFromSystemPropertiesWithVersionResolving() throws LifecycleExecutionException {
public void shouldLoadFromEnvWithVersionResolving() throws LifecycleExecutionException {
EnvironmentSettingDependencyLoader loader = new EnvironmentSettingDependencyLoader() {
@Override
protected String getEnvSetting(String name) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ type RunConfig struct {
type Config struct {
Recursive bool `yaml:"recursive"`
Namespace NamespaceConfig
Runtime RuntimeConfig
}

type RuntimeConfig struct {
Cucumber CucumberConfig
}

type CucumberConfig struct {
Tags []string `yaml:"tags"`
Glue []string `yaml:"glue"`
Options string `yaml:"options"`
}

type NamespaceConfig struct {
Expand Down
55 changes: 53 additions & 2 deletions pkg/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ const (
ConfigFile = "yaks-config.yaml"
)

const (
CucumberOptions = "CUCUMBER_OPTIONS"
CucumberGlue = "CUCUMBER_GLUE"
CucumberFeatures = "CUCUMBER_FEATURES"
CucumberFilterTags = "CUCUMBER_FILTER_TAGS"
)

func newCmdTest(rootCmdOptions *RootCmdOptions) *cobra.Command {
options := testCmdOptions{
RootCmdOptions: rootCmdOptions,
Expand All @@ -73,6 +80,10 @@ func newCmdTest(rootCmdOptions *RootCmdOptions) *cobra.Command {
cmd.Flags().StringArrayVarP(&options.uploads, "upload", "u", nil, "Upload a given library to the cluster to allow it to be used by tests.")
cmd.Flags().StringVarP(&options.settings, "settings", "s", "", "Path to runtime settings file. File content is added to the test runtime and can hold runtime dependency information for instance.")
cmd.Flags().StringArrayVarP(&options.env, "env", "e", nil, "Set an environment variable in the integration container. E.g \"-e MY_VAR=my-value\"")
cmd.Flags().StringArrayVarP(&options.tags, "tag", "t", nil, "Specify a tag filter to only run tests that match given tag expression")
cmd.Flags().StringArrayVarP(&options.features, "feature", "f", nil, "Feature file to include in the test run")
cmd.Flags().StringArrayVarP(&options.glue, "glue", "g", nil, "Additional glue path to be added in the Cucumber runtime options")
cmd.Flags().StringVarP(&options.options, "options", "o", "", "Cucumber runtime options")

return &cmd
}
Expand All @@ -83,6 +94,10 @@ type testCmdOptions struct {
uploads []string
settings string
env []string
tags []string
features []string
glue []string
options string
}

func (o *testCmdOptions) validateArgs(_ *cobra.Command, args []string) error {
Expand Down Expand Up @@ -284,8 +299,8 @@ func (o *testCmdOptions) createAndRunTest(c client.Client, rawName string, runCo
}
}

if o.env != nil {
test.Spec.Env = o.env
if err := o.setupEnvSettings(&test, runConfig); err != nil {
return nil, err
}

existed := false
Expand Down Expand Up @@ -364,6 +379,42 @@ func (o *testCmdOptions) uploadArtifacts(runConfig *config.RunConfig) error {
return nil
}

func (o *testCmdOptions) setupEnvSettings(test *v1alpha1.Test, runConfig *config.RunConfig) error {
env := make([]string, 0)

if o.tags != nil {
env = append(env, CucumberFilterTags + "=" + strings.Join(o.tags, ","))
} else if len(runConfig.Config.Runtime.Cucumber.Tags) > 0 {
env = append(env, CucumberFilterTags + "=" + strings.Join(runConfig.Config.Runtime.Cucumber.Tags, ","))
}

if o.features != nil {
env = append(env, CucumberFeatures + "=" + strings.Join(o.features, ","))
}

if o.glue != nil {
env = append(env, CucumberGlue + "=" + strings.Join(o.glue, ","))
} else if len(runConfig.Config.Runtime.Cucumber.Glue) > 0 {
env = append(env, CucumberGlue + "=" + strings.Join(runConfig.Config.Runtime.Cucumber.Glue, ","))
}

if len(o.options) > 0 {
env = append(env, CucumberOptions + "=" + o.options)
} else if len(runConfig.Config.Runtime.Cucumber.Options) > 0 {
env = append(env, CucumberOptions + "=" + runConfig.Config.Runtime.Cucumber.Options)
}

if o.env != nil {
copy(env, o.env)
}

if len(env) > 0 {
test.Spec.Env = env
}

return nil
}

func (o *testCmdOptions) newSettings() (*v1alpha1.SettingsSpec, error) {
runtimeDependencies := o.dependencies

Expand Down