Skip to content

Commit

Permalink
more e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel committed Oct 7, 2024
1 parent 2a3ec04 commit 6c2f552
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,5 @@ delete-cluster: install-kind
workflow_test_image_build-and-push:
docker build -t localhost:5001/testimage/sonataflow-minimal-example:0.1 ./test/testdata/workflow/docker-image/
docker push localhost:5001/testimage/sonataflow-minimal-example:0.1
docker build --build-arg WORKFLOW_FILE=broken-workflow.sw.json -t localhost:5001/testimage/sonataflow-minimal-example-broken:0.1 ./test/testdata/workflow/docker-image/
docker push localhost:5001/testimage/sonataflow-minimal-example-broken:0.1
14 changes: 14 additions & 0 deletions internal/controller/validation/common_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Apache Software Foundation (ASF)
//
// 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 validation

import (
Expand Down
4 changes: 0 additions & 4 deletions internal/controller/validation/image_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ func validateImage(ctx context.Context, sonataflow *operatorapi.SonataFlow) (boo
}

func remoteImage(sonataflow *operatorapi.SonataFlow) (v1.Image, error) {
fmt.Println("remoteImage")

imageRef, err := name.ParseReference(sonataflow.Spec.PodTemplate.Container.Image)
if err != nil {
return nil, err
Expand All @@ -97,8 +95,6 @@ func remoteImage(sonataflow *operatorapi.SonataFlow) (v1.Image, error) {
}

func kindRegistryImage(sonataflow *operatorapi.SonataFlow) (v1.Image, error) {
fmt.Println("kindRegistryImage")

transportOptions := []remote.Option{
remote.WithTransport(&http.Transport{
Proxy: http.ProxyFromEnvironment,
Expand Down
63 changes: 42 additions & 21 deletions test/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,51 @@ var _ = Describe("Workflow Non-Persistence Use Cases :: ", Label("flows-non-pers
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())
})

It("should not deploy the Simple Workflow because image contains no workflow definition", func() {
By("creating an instance of the SonataFlow Operand(CR)")
EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "apply", "-f", filepath.Join(projectDir,
"test/testdata/"+test.SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())

By("verifying that the workflow is not in a running state within one minute")
ConsistentlyWithOffset(1, func() bool {
return verifyWorkflowIsInRunningState("simple", targetNamespace)
}, 1*time.Minute, 10*time.Second).Should(BeFalse(), "Workflow unexpectedly reached the running state")

It("should not deploy the Simple Workflow because image contains no workflow definition", func() {
By("creating an instance of the SonataFlow Operand(CR)")
EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "apply", "-f", filepath.Join(projectDir,
"test/testdata/"+test.SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())

By("verifying that the workflow is not in a running state within one minute")
ConsistentlyWithOffset(1, func() bool {
return verifyWorkflowIsInRunningState("simple", targetNamespace)
}, 1*time.Minute, 10*time.Second).Should(BeFalse(), "Workflow unexpectedly reached the running state")

EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "delete", "-f", filepath.Join(projectDir,
"test/testdata/"+test.SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())
})
EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "delete", "-f", filepath.Join(projectDir,
"test/testdata/"+test.SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())
})

It("should not deploy the Simple Workflow because image contains broken (not equals to flow from yaml) workflow definition", func() {
By("creating an instance of the SonataFlow Operand(CR)")
EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "apply", "-f", filepath.Join(projectDir,
"test/testdata/"+test.SonataFlowSimpleOpsYamlCRImageContainsBrokenWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())

By("verifying that the workflow is not in a running state within one minute")
ConsistentlyWithOffset(1, func() bool {
return verifyWorkflowIsInRunningState("simple", targetNamespace)
}, 1*time.Minute, 10*time.Second).Should(BeFalse(), "Workflow unexpectedly reached the running state")

EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "delete", "-f", filepath.Join(projectDir,
"test/testdata/"+test.SonataFlowSimpleOpsYamlCRImageContainsBrokenWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())
})
})

})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2023 Red Hat, Inc. and/or its affiliates
#
# 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.

apiVersion: sonataflow.org/v1alpha08
kind: SonataFlow
metadata:
name: simple
annotations:
sonataflow.org/description: Simple example on k8s!
sonataflow.org/version: 0.0.1
labels:
test: test
spec:
podTemplate:
container:
image: testimage/sonataflow-minimal-example-broken:0.1
flow:
start: HelloWorld
states:
- name: HelloWorld
type: inject
data:
message: Hello World
end: true
18 changes: 18 additions & 0 deletions test/testdata/workflow/docker-image/broken-workflow.sw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "hello",
"version": "1.0",
"specVersion": "0.8.0",
"name": "Hello World",
"description": "Description",
"start": "HelloWorld",
"states": [
{
"name": "HelloWorld",
"type": "inject",
"data": {
"message": "Hello World"
},
"end": true
}
]
}
7 changes: 4 additions & 3 deletions test/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ const (
sonataFlowBuildSucceed = "sonataflow.org_v1alpha08_sonataflowbuild.yaml"
knativeDefaultBrokerCR = "knative_default_broker.yaml"

SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow = "sonataflow.org_v1alpha08_sonataflow-simpleops-no-workflow-in-image.yaml"
e2eSamples = "test/testdata/"
manifestsPath = "bundle/manifests/"
SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow = "sonataflow.org_v1alpha08_sonataflow-simpleops-no-workflow-in-image.yaml"
SonataFlowSimpleOpsYamlCRImageContainsBrokenWorkflow = "sonataflow.org_v1alpha08_sonataflow-simpleops-broken-workflow-in-image.yaml"
e2eSamples = "test/testdata/"
manifestsPath = "bundle/manifests/"
)

var projectDir = ""
Expand Down

0 comments on commit 6c2f552

Please sign in to comment.