Skip to content

Commit

Permalink
[KOGITO-8961][KSW-Operator] Split use case and test examples
Browse files Browse the repository at this point in the history
Signed-off-by: desmax74 <mdessi@redhat.com>
  • Loading branch information
desmax74 committed May 30, 2023
1 parent 67aa342 commit d62a43a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 66 deletions.
8 changes: 4 additions & 4 deletions controllers/builder/openshiftbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
func Test_openshiftBuilderManager_Reconcile(t *testing.T) {
// Setup
ns := t.Name()
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, ns)
platform := test.GetKogitoServerlessPlatformInReadyPhase("../../config/samples/"+test.KogitoServerlessPlatformWithCacheYamlCR, ns)
workflow := test.GetBaseServerlessWorkflow(ns)
platform := test.GetBasePlatformWithCacheInReadyPhase(t.Name())
config := test.GetKogitoServerlessOperatorBuilderConfig("../../", ns)
namespacedName := types.NamespacedName{Namespace: workflow.Namespace, Name: workflow.Name}
client := test.NewKogitoClientBuilderWithOpenShift().WithRuntimeObjects(workflow, platform, config).Build()
Expand Down Expand Up @@ -89,8 +89,8 @@ func Test_openshiftBuilderManager_Reconcile(t *testing.T) {

func Test_openshiftbuilder_externalCMs(t *testing.T) {
ns := t.Name()
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, ns)
platform := test.GetKogitoServerlessPlatformInReadyPhase("../../config/samples/"+test.KogitoServerlessPlatformWithCacheYamlCR, ns)
workflow := test.GetBaseServerlessWorkflow(ns)
platform := test.GetBasePlatformWithCacheInReadyPhase(t.Name())
config := test.GetKogitoServerlessOperatorBuilderConfig("../../", ns)
externalCm := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down
5 changes: 3 additions & 2 deletions controllers/kogitoserverlessbuild_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import (

func TestKogitoServerlessBuildController(t *testing.T) {
namespace := t.Name()
ksw := test.GetKogitoServerlessWorkflow("../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, namespace)
ksw := test.GetBaseServerlessWorkflowNoPackage(namespace)
ksb := test.GetNewEmptyKogitoServerlessBuild(ksw.Name, namespace)

cl := test.NewKogitoClientBuilder().
WithRuntimeObjects(ksb, ksw).
WithRuntimeObjects(test.GetKogitoServerlessPlatformInReadyPhase("../config/samples/"+test.KogitoServerlessPlatformWithCacheYamlCR, namespace)).
WithRuntimeObjects(test.GetBasePlatformWithCacheInReadyPhaseNoPackage(namespace)).
WithRuntimeObjects(test.GetKogitoServerlessOperatorBuilderConfig("../", namespace)).
Build()

Expand Down
4 changes: 2 additions & 2 deletions controllers/kogitoserverlessworkflow_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func TestKogitoServerlessWorkflowController(t *testing.T) {
t.Run("verify that a basic reconcile is performed without error", func(t *testing.T) {
namespace := t.Name()
// Create a KogitoServerlessWorkflow object with metadata and spec.
ksw := test.GetKogitoServerlessWorkflow("../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, namespace)
ksw := test.GetBaseServerlessWorkflow(namespace)
// The Workflow controller needs at least to perform a call for Platforms, so we need to add this kind to the known
// ones by the fake client
ksp := test.GetKogitoServerlessPlatformInReadyPhase("../config/samples/"+test.KogitoServerlessPlatformWithCacheYamlCR, namespace)
ksp := test.GetBasePlatformWithCacheInReadyPhase(namespace)
// Objects to track in the fake Client.
objs := []runtime.Object{ksw, ksp}

Expand Down
6 changes: 3 additions & 3 deletions controllers/profiles/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
)

func Test_workflowIsDevProfile(t *testing.T) {
workflowWithDevProfile := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleDevModeYamlCR, t.Name())
workflowWithDevProfile := test.GetBaseServerlessWorkflowWithDevProfile(t.Name())
assert.True(t, IsDevProfile(workflowWithDevProfile))

workflowWithNoProfile := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, t.Name())
workflowWithNoProfile := test.GetBaseServerlessWorkflow(t.Name())
assert.False(t, IsDevProfile(workflowWithNoProfile))

workflowWithProdProfile := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowProdProfileSampleYamlCR, t.Name())
workflowWithProdProfile := test.GetBaseServerlessWorkflowWithProdProfile(t.Name())
assert.False(t, IsDevProfile(workflowWithProdProfile))
}
12 changes: 7 additions & 5 deletions controllers/profiles/reconciler_prod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Test_reconcilerProdBuildConditions(t *testing.T) {
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, t.Name())
// make sure that the workflow won't trigger a change
workflow.Status.Applied = workflow.Spec
platform := test.GetKogitoServerlessPlatformInReadyPhase("../../config/samples/"+test.KogitoServerlessPlatformWithCacheYamlCR, t.Name())
platform := test.GetBasePlatformWithCacheInReadyPhase(t.Name())
client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, platform).Build()

config := &rest.Config{}
Expand Down Expand Up @@ -88,7 +88,7 @@ func Test_deployWorkflowReconciliationHandler_handleObjects(t *testing.T) {
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, t.Name())
// make sure that the workflow won't trigger a change
workflow.Status.Applied = workflow.Spec
platform := test.GetKogitoServerlessPlatformInReadyPhase("../../config/samples/"+test.KogitoServerlessPlatformWithCacheYamlCR, t.Name())
platform := test.GetBasePlatformWithCacheInReadyPhase(t.Name())
client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, platform).Build()
handler := &deployWorkflowReconciliationState{
stateSupport: fakeReconcilerSupport(client),
Expand Down Expand Up @@ -132,10 +132,10 @@ func Test_deployWorkflowReconciliationHandler_handleObjects(t *testing.T) {
func Test_GenerationAnnotationCheck(t *testing.T) {
logger := ctrllog.FromContext(context.TODO())
// we load a workflow with metadata.generation to 0
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflow(t.Name())
// make sure that the workflow won't trigger a change
workflow.Status.Applied = workflow.Spec
platform := test.GetKogitoServerlessPlatformInReadyPhase("../../config/samples/"+test.KogitoServerlessPlatformWithCacheYamlCR, t.Name())
platform := test.GetBasePlatformWithCacheInReadyPhase(t.Name())
client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow, platform).Build()
handler := &deployWorkflowReconciliationState{
stateSupport: fakeReconcilerSupport(client),
Expand All @@ -147,7 +147,9 @@ func Test_GenerationAnnotationCheck(t *testing.T) {
assert.NotNil(t, result)
assert.Len(t, objects, 3)
// then we load a workflow with metadata.generation set to 1
workflowChanged := test.GetKogitoServerlessWorkflow("../../test/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, t.Name())
workflowChanged := test.GetBaseServerlessWorkflow(t.Name())
//we set the generation to 1
workflowChanged.Generation = int64(1)
client = test.NewKogitoClientBuilder().WithRuntimeObjects(workflowChanged, platform).Build()
handler = &deployWorkflowReconciliationState{
stateSupport: fakeReconcilerSupport(client),
Expand Down
50 changes: 0 additions & 50 deletions test/samples/sw.kogito_v1alpha08_kogitoserverlessworkflow.yaml

This file was deleted.

35 changes: 35 additions & 0 deletions test/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,38 @@ func GetKogitoServerlessOperatorBuilderConfig(path, namespace string) *corev1.Co
cm.Namespace = namespace
return cm
}

func GetBaseServerlessWorkflow(namespace string) *operatorapi.KogitoServerlessWorkflow {
return GetKogitoServerlessWorkflow("../../config/samples/"+KogitoServerlessWorkflowSampleYamlCR, namespace)
}

func GetBaseServerlessWorkflowNoPackage(namespace string) *operatorapi.KogitoServerlessWorkflow {
return GetKogitoServerlessWorkflow("../config/samples/"+KogitoServerlessWorkflowSampleYamlCR, namespace)
}

func GetBaseServerlessWorkflowWithDevProfile(namespace string) *operatorapi.KogitoServerlessWorkflow {
workflow := GetBaseServerlessWorkflow(namespace)
workflow.Annotations["sw.kogito.kie.org/profile"] = "dev"
return workflow
}

func GetBaseServerlessWorkflowWithProdProfile(namespace string) *operatorapi.KogitoServerlessWorkflow {
workflow := GetBaseServerlessWorkflow(namespace)
workflow.Annotations["sw.kogito.kie.org/profile"] = "prod"
return workflow
}

func GetBasePlatformWithCacheInReadyPhase(namespace string) *operatorapi.KogitoServerlessPlatform {
return getBasePlatformWithCacheInReadyPhaseNoPackage("../../config/samples/", namespace)
}

func GetBasePlatformWithCacheInReadyPhaseNoPackage(namespace string) *operatorapi.KogitoServerlessPlatform {
return getBasePlatformWithCacheInReadyPhaseNoPackage("../config/samples/", namespace)
}

func getBasePlatformWithCacheInReadyPhaseNoPackage(path string, namespace string) *operatorapi.KogitoServerlessPlatform {
platform := GetKogitoServerlessPlatformInReadyPhase(path+KogitoServerlessPlatformYamlCR, namespace)
buildStrategyOptions := map[string]string{"KanikoBuildCacheEnabled": "true"}
platform.Spec.BuildPlatform.BuildStrategyOptions = buildStrategyOptions
return platform
}

0 comments on commit d62a43a

Please sign in to comment.