Skip to content

Commit 19fba8f

Browse files
radtristeMarianMacik
authored andcommitted
[KOGITO-997] Setup service discovery feature scenario (apache#179)
1 parent c2d7189 commit 19fba8f

File tree

5 files changed

+101
-15
lines changed

5 files changed

+101
-15
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@discovery
2+
@cr
3+
Feature: Discovery with onboarding
4+
5+
Background:
6+
Given Namespace is created
7+
8+
Scenario Outline: Deploy onboarding example
9+
Given Kogito Operator is deployed
10+
11+
When Deploy quarkus example service "onboarding-example/hr" with native <native> and labels
12+
| department | process |
13+
| id | process |
14+
| employeeValidation | process |
15+
16+
And Deploy quarkus example service "onboarding-example/payroll" with native <native> and labels
17+
| taxes/rate | process |
18+
| vacations/days | process |
19+
| payments/date | process |
20+
21+
And Deploy quarkus example service "onboarding-example/onboarding" with native <native> and labels
22+
| onboarding | process |
23+
24+
And Kogito application "hr" has 1 pods running within <minutes> minutes
25+
And Kogito application "payroll" has 1 pods running within <minutes> minutes
26+
And Kogito application "onboarding" has 1 pods running within <minutes> minutes
27+
28+
Then HTTP POST request on service "onboarding" is successful within 2 minutes with path "onboarding" and body:
29+
"""json
30+
{
31+
"employee" : {
32+
"firstName" : "Mark",
33+
"lastName" : "Test",
34+
"personalId" : "xxx-yy-zzz",
35+
"birthDate" : "1995-12-10T14:50:12.123+02:00",
36+
"address" : {
37+
"country" : "US",
38+
"city" : "Boston",
39+
"street" : "any street 3",
40+
"zipCode" : "10001"
41+
}
42+
}
43+
}
44+
"""
45+
46+
Examples: Non Native
47+
| native | minutes |
48+
| "disabled" | 10 |
49+
50+
@native
51+
Examples: Native
52+
| native | minutes |
53+
| "enabled" | 20 |

bddframework/framework/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type TestConfig struct {
4545

4646
showScenarios bool
4747
dryRun bool
48+
keepNamespace bool
4849
}
4950

5051
const (
@@ -69,6 +70,7 @@ func BindTestsConfigFlags(set *flag.FlagSet) {
6970
set.BoolVar(&env.localTests, prefix+"local", false, "If tests are launch on local machine")
7071
set.StringVar(&env.ciName, prefix+"ci", "", "If tests are launch on ci machine, give the CI name")
7172
set.BoolVar(&env.smoke, prefix+"smoke", false, "Launch only smoke tests")
73+
set.BoolVar(&env.keepNamespace, prefix+"keep-namespace", false, "Do not delete namespace(s) after scenario run (WARNING: can be resources consuming ...)")
7274

7375
set.StringVar(&env.operatorImageName, prefix+"operator-image-name", defaultOperatorImageName, "Operator image name")
7476
set.StringVar(&env.operatorImageTag, prefix+"operator-image-tag", defaultOperatorImageTag, "Operator image tag")
@@ -156,12 +158,17 @@ func IsSmokeTests() bool {
156158
return env.smoke
157159
}
158160

159-
// IsConfigShowScenarios return we should display scenarios
161+
// IsConfigShowScenarios return whether we should display scenarios
160162
func IsConfigShowScenarios() bool {
161163
return env.showScenarios
162164
}
163165

164-
// IsConfigDryRun return we should do a dry run
166+
// IsConfigDryRun return whether we should do a dry run
165167
func IsConfigDryRun() bool {
166168
return env.dryRun
167169
}
170+
171+
// IsConfigKeepNamespace return whether we should keep namespace after scenario run
172+
func IsConfigKeepNamespace() bool {
173+
return env.keepNamespace
174+
}

bddframework/framework/kogitoapp.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ const (
3131
)
3232

3333
// DeployQuarkusExample deploy a Quarkus example
34-
func DeployQuarkusExample(namespace, appName, contextDir string, native, persistence, events bool) error {
34+
func DeployQuarkusExample(namespace, appName, contextDir string, native, persistence, events bool, labels map[string]string) error {
3535
GetLogger(namespace).Infof("Deploy quarkus example %s with name %s, native %v and persistence %v", contextDir, appName, native, persistence)
36-
return DeployExample(namespace, appName, contextDir, "quarkus", native, persistence, events)
36+
return DeployExample(namespace, appName, contextDir, "quarkus", native, persistence, events, labels)
3737
}
3838

3939
// DeploySpringBootExample deploys a Spring boot example
40-
func DeploySpringBootExample(namespace, appName, contextDir string, persistence, events bool) error {
40+
func DeploySpringBootExample(namespace, appName, contextDir string, persistence, events bool, labels map[string]string) error {
4141
GetLogger(namespace).Infof("Deploy spring boot example %s with name %s and persistence %v", contextDir, appName, persistence)
42-
return DeployExample(namespace, appName, contextDir, "springboot", false, persistence, events)
42+
return DeployExample(namespace, appName, contextDir, "springboot", false, persistence, events, labels)
4343
}
4444

4545
// DeployExample deploys an example
46-
func DeployExample(namespace, appName, contextDir, runtime string, native, persistence, events bool) error {
47-
kogitoApp := getKogitoAppStub(namespace, appName)
46+
func DeployExample(namespace, appName, contextDir, runtime string, native, persistence, events bool, labels map[string]string) error {
47+
kogitoApp := getKogitoAppStub(namespace, appName, labels)
4848
if runtime == "quarkus" {
4949
kogitoApp.Spec.Runtime = v1alpha1.QuarkusRuntimeType
5050
} else if runtime == "springboot" {
@@ -57,6 +57,10 @@ func DeployExample(namespace, appName, contextDir, runtime string, native, persi
5757
kogitoApp.Spec.Build.GitSource.ContextDir = contextDir
5858
kogitoApp.Spec.Build.GitSource.Reference = GetConfigExamplesRepositoryRef()
5959

60+
// Add namespace for service discovery
61+
// Can be removed once https://issues.redhat.com/browse/KOGITO-675 is done
62+
appendNewEnvToKogitoApp(kogitoApp, "NAMESPACE", namespace)
63+
6064
profiles := ""
6165
if persistence {
6266
profiles = profiles + "persistence,"
@@ -95,7 +99,7 @@ func SetKogitoAppReplicas(namespace, name string, nbPods int) error {
9599
return kubernetes.ResourceC(kubeClient).Update(kogitoApp)
96100
}
97101

98-
func getKogitoAppStub(namespace, appName string) *v1alpha1.KogitoApp {
102+
func getKogitoAppStub(namespace, appName string, labels map[string]string) *v1alpha1.KogitoApp {
99103
kogitoApp := &v1alpha1.KogitoApp{
100104
ObjectMeta: metav1.ObjectMeta{
101105
Name: appName,
@@ -113,6 +117,13 @@ func getKogitoAppStub(namespace, appName string) *v1alpha1.KogitoApp {
113117
},
114118
}
115119

120+
// Add labels
121+
if labels != nil {
122+
kogitoApp.Spec.Service = v1alpha1.KogitoAppServiceObject{
123+
Labels: labels,
124+
}
125+
}
126+
116127
if mavenMirrorURL := GetConfigMavenMirrorURL(); len(mavenMirrorURL) > 0 {
117128
kogitoApp.Spec.Build.MavenMirrorURL = mavenMirrorURL
118129
}

bddframework/main_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ func FeatureContext(s *godog.Suite) {
113113
data.AfterScenario(s, err)
114114

115115
// Namespace should be deleted after all other operations have been done
116-
deleteNamespaceIfExists(data.Namespace)
116+
if !framework.IsConfigKeepNamespace() {
117+
deleteNamespaceIfExists(data.Namespace)
118+
}
117119
})
118120

119121
// Step handlers

bddframework/steps/kogitoapp.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ import (
1818
"path/filepath"
1919

2020
"github.com/cucumber/godog"
21+
"github.com/cucumber/godog/gherkin"
2122
"github.com/kiegroup/kogito-cloud-operator/test/framework"
23+
"github.com/rdumont/assistdog"
2224
)
2325

26+
var assist = assistdog.NewDefault()
27+
2428
// RegisterCliSteps register all CLI steps existing
2529
func registerKogitoAppSteps(s *godog.Suite, data *Data) {
2630
// Deploy steps
2731
s.Step(`^Deploy quarkus example service "([^"]*)" with native "([^"]*)"$`, data.deployQuarkusExampleServiceWithNative)
32+
s.Step(`^Deploy quarkus example service "([^"]*)" with native "([^"]*)" and labels$`, data.deployQuarkusExampleServiceWithNativeAndLabels)
2833
s.Step(`^Deploy quarkus example service "([^"]*)" with persistence enabled and native "([^"]*)"$`, data.deployQuarkusExampleServiceWithPersistenceAndNative)
2934
s.Step(`^Deploy quarkus example service "([^"]*)" with persistence enabled and native "([^"]*)" and events "([^"]*)"$`, data.deployQuarkusExampleServiceWithPersistenceAndNativeAndEvents)
3035
s.Step(`^Deploy spring boot example service "([^"]*)"$`, data.deploySpringBootExampleService)
@@ -42,23 +47,31 @@ func registerKogitoAppSteps(s *godog.Suite, data *Data) {
4247

4348
// Deploy service steps
4449
func (data *Data) deployQuarkusExampleServiceWithNative(contextDir, native string) error {
45-
return framework.DeployQuarkusExample(data.Namespace, filepath.Base(contextDir), contextDir, native == "enabled", false, false)
50+
return framework.DeployQuarkusExample(data.Namespace, filepath.Base(contextDir), contextDir, native == "enabled", false, false, nil)
51+
}
52+
53+
func (data *Data) deployQuarkusExampleServiceWithNativeAndLabels(contextDir, native string, dt *gherkin.DataTable) error {
54+
labels, err := assist.ParseMap(dt)
55+
if err != nil {
56+
return err
57+
}
58+
return framework.DeployQuarkusExample(data.Namespace, filepath.Base(contextDir), contextDir, native == "enabled", false, false, labels)
4659
}
4760

4861
func (data *Data) deployQuarkusExampleServiceWithPersistenceAndNative(contextDir, native string) error {
49-
return framework.DeployQuarkusExample(data.Namespace, filepath.Base(contextDir), contextDir, native == "enabled", true, false)
62+
return framework.DeployQuarkusExample(data.Namespace, filepath.Base(contextDir), contextDir, native == "enabled", true, false, nil)
5063
}
5164

5265
func (data *Data) deployQuarkusExampleServiceWithPersistenceAndNativeAndEvents(contextDir, native, events string) error {
53-
return framework.DeployQuarkusExample(data.Namespace, filepath.Base(contextDir), contextDir, native == "enabled", true, events == "enabled")
66+
return framework.DeployQuarkusExample(data.Namespace, filepath.Base(contextDir), contextDir, native == "enabled", true, events == "enabled", nil)
5467
}
5568

5669
func (data *Data) deploySpringBootExampleService(contextDir string) error {
57-
return framework.DeploySpringBootExample(data.Namespace, filepath.Base(contextDir), contextDir, false, false)
70+
return framework.DeploySpringBootExample(data.Namespace, filepath.Base(contextDir), contextDir, false, false, nil)
5871
}
5972

6073
func (data *Data) deploySpringBootExampleServiceWithPersistence(contextDir string) error {
61-
return framework.DeploySpringBootExample(data.Namespace, filepath.Base(contextDir), contextDir, true, false)
74+
return framework.DeploySpringBootExample(data.Namespace, filepath.Base(contextDir), contextDir, true, false, nil)
6275
}
6376

6477
// Build steps

0 commit comments

Comments
 (0)