Skip to content

Commit

Permalink
Test multiple apps connecting to single service
Browse files Browse the repository at this point in the history
  • Loading branch information
baijum committed Jun 9, 2021
1 parent af6e990 commit 53bb65a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 62 deletions.
72 changes: 10 additions & 62 deletions test/acceptance/features/bindAppToServiceWithLabelSelector.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Feature: Bind an application with label selector to a service
Given Namespace [TEST_NAMESPACE] is used
* Service Binding Operator is running

Scenario: Bind successfully an application owning a given label to a service
Given Generic test application "gen-app-a-s-c" is running
Scenario: Successfully bind two applications with same label to a service
Given Test applications "gen-app-a-s-f-1" and "gen-app-a-s-f-2" is running
* The common label "app-custom=test" is set for both apps
* CustomResourceDefinition backends.stable.example.com is available
* The Secret is present
"""
Expand All @@ -25,7 +26,7 @@ Feature: Bind an application with label selector to a service
apiVersion: stable.example.com/v1
kind: Backend
metadata:
name: service-a-s-c
name: service-a-s-f
annotations:
service.binding: path={.status.data.dbCredentials},objectType=Secret,elementType=map
status:
Expand All @@ -37,75 +38,22 @@ Feature: Bind an application with label selector to a service
apiVersion: binding.operators.coreos.com/v1alpha1
kind: ServiceBinding
metadata:
name: service-binding-a-s-c
name: service-binding-a-s-f
spec:
bindAsFiles: false
services:
- group: stable.example.com
version: v1
kind: Backend
name: service-a-s-c
name: service-a-s-f
application:
labelSelector:
matchLabels:
app: gen-app-a-s-c
app-custom: test
group: apps
version: v1
resource: deployments
"""
Then Service Binding "service-binding-a-s-c" is ready
And The application env var "BACKEND_USERNAME" has value "AzureDiamond"
And The application env var "BACKEND_PASSWORD" has value "hunter2"

Scenario: Unsuccessful attempt to bind an application with label selector and name to a service
Given Generic test application "gen-app-a-s-e" is running
* CustomResourceDefinition backends.stable.example.com is available
* The Secret is present
"""
apiVersion: v1
kind: Secret
metadata:
name: backend-secret
stringData:
username: AzureDiamond
password: hunter2
"""
And The Custom Resource is present
"""
apiVersion: stable.example.com/v1
kind: Backend
metadata:
name: service-a-s-e
annotations:
service.binding: path={.status.data.dbCredentials},objectType=Secret,elementType=map
status:
data:
dbCredentials: backend-secret
"""
When Service Binding is applied
"""
apiVersion: binding.operators.coreos.com/v1alpha1
kind: ServiceBinding
metadata:
name: service-binding-a-s-e
spec:
bindAsFiles: false
services:
- group: stable.example.com
version: v1
kind: Backend
name: service-a-s-e
application:
name: gen-app-a-s-e
labelSelector:
matchLabels:
app: gen-app-a-s-e
group: apps
version: v1
resource: deployments
"""

Then jq ".status.conditions[] | select(.type=="CollectionReady").status" of Service Binding "service-binding-a-s-e" should be changed to "True"
And jq ".status.conditions[] | select(.type=="InjectionReady").status" of Service Binding "service-binding-a-s-e" should be changed to "False"
And jq ".status.conditions[] | select(.type=="InjectionReady").reason" of Service Binding "service-binding-a-s-e" should be changed to "ApplicationNotFound"
And jq ".status.conditions[] | select(.type=="Ready").status" of Service Binding "service-binding-a-s-e" should be changed to "False"
Then Service Binding "service-binding-a-s-f" is ready
And The application env var "BACKEND_USERNAME" has value "AzureDiamond" in both apps
And The application env var "BACKEND_PASSWORD" has value "hunter2" in both apps
32 changes: 32 additions & 0 deletions test/acceptance/features/steps/generic_testapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def assert_file_not_exist(self, file_path):
polling2.poll(lambda: requests.get(url=f"http://{self.route_url}{file_path}"),
check_success=lambda r: r.status_code == 404, step=5, timeout=400, ignore_exceptions=(requests.exceptions.ConnectionError,))

def set_label(self, label):
self.openshift.set_label(self.name, label, self.namespace)

@step(u'Generic test application "{application_name}" is running')
@step(u'Generic test application "{application_name}" is running with binding root as "{bindingRoot}"')
Expand Down Expand Up @@ -74,3 +76,33 @@ def check_file_value(context, file_path):
@step(u'File "{file_path}" is unavailable in application pod')
def check_file_unavailable(context, file_path):
context.application.assert_file_not_exist(file_path)


@given(u'Test applications "{first_app_name}" and "{second_app_name}" is running')
def are_two_apps_running(context, first_app_name, second_app_name, bindingRoot=None):
application1 = GenericTestApp(first_app_name, context.namespace.name)
if not application1.is_running():
print("application1 is not running, trying to import it")
application1.install(bindingRoot=bindingRoot)
context.application1 = application1

application2 = GenericTestApp(second_app_name, context.namespace.name)
if not application2.is_running():
print("application2 is not running, trying to import it")
application2.install(bindingRoot=bindingRoot)
context.application2 = application2


@given(u'The common label "{label}" is set for both apps')
def set_common_label(context, label):
context.application1.set_label(f"{label}")
context.application2.set_label(f"{label}")


@then(u'The application env var "{name}" has value "{value}" in both apps')
def check_env_var_value_in_both_apps(context, name, value):
found = polling2.poll(lambda: context.application1.get_env_var_value(name) == value, step=5, timeout=400)
assert found, f'Env var "{name}" should contain value "{value}" in {context.application1}'

found = polling2.poll(lambda: context.application2.get_env_var_value(name) == value, step=5, timeout=400)
assert found, f'Env var "{name}" should contain value "{value}" in {context.application2}'
5 changes: 5 additions & 0 deletions test/acceptance/features/steps/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,8 @@ def new_app(self, name, image_name, namespace, bindingRoot=None):
else:
(output, exit_code) = self.cmd.run(cmd)
assert exit_code == 0, f"Non-zero exit code ({exit_code}) returned when attempting to create a new app using following command line {cmd}\n: {output}"

def set_label(self, name, label, namespace):
cmd = f"{ctx.cli} label deployments {name} '{label}' -n {namespace}"
(output, exit_code) = self.cmd.run(cmd)
assert exit_code == 0, f"Non-zero exit code ({exit_code}) returned when attempting set label: {cmd}\n: {output}"

0 comments on commit 53bb65a

Please sign in to comment.