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 31, 2023
1 parent 67aa342 commit 91f326f
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 298 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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.GetBasePlatformInReadyPhase(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.GetBasePlatformInReadyPhase(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.GetBasePlatformInReadyPhaseNoPackage(namespace)).
WithRuntimeObjects(test.GetKogitoServerlessOperatorBuilderConfig("../", namespace)).
Build()

Expand Down
2 changes: 1 addition & 1 deletion controllers/kogitoserverlessplatform_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
func TestKogitoServerlessPlatformController(t *testing.T) {
t.Run("verify that a basic reconcile is performed without error", func(t *testing.T) {
// Create a KogitoServerlessPlatform object with metadata and spec.
ksp := test.GetKogitoServerlessPlatform("../config/samples/sw.kogito_v1alpha08_kogitoserverlessplatform.yaml")
ksp := test.GetBasePlatform("../config/samples/")

// Create a fake client to mock API calls.
cl := test.NewKogitoClientBuilder().WithRuntimeObjects(ksp).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.GetBaseServerlessWorkflowNoPackage(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.GetBasePlatformInReadyPhaseNoPackage(namespace)
// Objects to track in the fake Client.
objs := []runtime.Object{ksw, ksp}

Expand Down
2 changes: 1 addition & 1 deletion controllers/profiles/object_creators_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func Test_ensureWorkflowDevServiceIsExposed(t *testing.T) {
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleDevModeYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflowWithDevProfile(t.Name())

//On Kubernetes we want the service exposed in Dev with NodePort
service, _ := devServiceCreator(workflow)
Expand Down
2 changes: 1 addition & 1 deletion controllers/profiles/object_creators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func Test_ensureWorkflowPropertiesConfigMapMutator(t *testing.T) {
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleDevModeYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflowWithDevProfile(t.Name())
// can't be new
cm, _ := workflowPropsConfigMapCreator(workflow)
cm.SetUID("1")
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))
}
28 changes: 10 additions & 18 deletions controllers/profiles/reconciler_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (

"github.com/kiegroup/kogito-serverless-operator/utils"

operatorapi "github.com/kiegroup/kogito-serverless-operator/api/v1alpha08"

"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -41,7 +39,7 @@ import (

func Test_recoverFromFailureNoDeployment(t *testing.T) {
logger := ctrllog.FromContext(context.TODO())
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflow(t.Name())
workflowID := clientruntime.ObjectKeyFromObject(workflow)

workflow.Status.Manager().MarkFalse(api.RunningConditionType, api.DeploymentFailureReason, "")
Expand Down Expand Up @@ -86,7 +84,7 @@ func Test_recoverFromFailureNoDeployment(t *testing.T) {

func Test_newDevProfile(t *testing.T) {
logger := ctrllog.FromContext(context.TODO())
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflow(t.Name())

client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).Build()

Expand Down Expand Up @@ -163,7 +161,7 @@ func Test_newDevProfile(t *testing.T) {

func Test_devProfileImageDefaultsNoPlatform(t *testing.T) {
logger := ctrllog.FromContext(context.TODO())
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleDevModeYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflowWithDevProfile(t.Name())
client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).Build()
config := &rest.Config{}
devReconciler := newDevProfileReconciler(client, config, &logger)
Expand All @@ -179,11 +177,9 @@ func Test_devProfileImageDefaultsNoPlatform(t *testing.T) {

func Test_devProfileWithImageSnapshotOverrideWithPlatform(t *testing.T) {
logger := ctrllog.FromContext(context.TODO())
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleDevModeYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflowWithDevProfile(t.Name())

platform := test.GetKogitoServerlessPlatform("../../config/samples/" + test.KogitoServerlessPlatformWithDevBaseImageYamlCR)
platform.Status.Phase = operatorapi.PlatformPhaseReady
platform.Namespace = workflow.Namespace
platform := test.GetBasePlatformWithDevBaseImageInReadyPhase(workflow.Namespace)

client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).Build()
errCreatePlatform := client.Create(context.Background(), platform)
Expand All @@ -202,11 +198,9 @@ func Test_devProfileWithImageSnapshotOverrideWithPlatform(t *testing.T) {

func Test_devProfileWithWPlatformWithoutDevBaseImageAndWithBaseImage(t *testing.T) {
logger := ctrllog.FromContext(context.TODO())
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleDevModeYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflowWithDevProfile(t.Name())

platform := test.GetKogitoServerlessPlatform("../../config/samples/" + test.KogitoServerlessPlatformWithBaseImageYamlCR)
platform.Status.Phase = operatorapi.PlatformPhaseReady
platform.Namespace = workflow.Namespace
platform := test.GetBasePlatformWithBaseImageInReadyPhase(workflow.Namespace)

client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).Build()
errCreatePlatform := client.Create(context.Background(), platform)
Expand All @@ -225,11 +219,9 @@ func Test_devProfileWithWPlatformWithoutDevBaseImageAndWithBaseImage(t *testing.

func Test_devProfileWithPlatformWithoutDevBaseImageAndWithoutBaseImage(t *testing.T) {
logger := ctrllog.FromContext(context.TODO())
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleDevModeYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflowWithDevProfile(t.Name())

platform := test.GetKogitoServerlessPlatform("../../config/samples/" + test.KogitoServerlessPlatformYamlCR)
platform.Status.Phase = operatorapi.PlatformPhaseReady
platform.Namespace = workflow.Namespace
platform := test.GetBasePlatformInReadyPhase(workflow.Namespace)

client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).Build()
errCreatePlatform := client.Create(context.Background(), platform)
Expand All @@ -248,7 +240,7 @@ func Test_devProfileWithPlatformWithoutDevBaseImageAndWithoutBaseImage(t *testin

func Test_newDevProfileWithExternalConfigMaps(t *testing.T) {
logger := ctrllog.FromContext(context.TODO())
workflow := test.GetKogitoServerlessWorkflow("../../config/samples/"+test.KogitoServerlessWorkflowSampleDevModeWithExternalResourceYamlCR, t.Name())
workflow := test.GetBaseServerlessWorkflowWithDevProfileAndExternalResource(t.Name())
client := test.NewKogitoClientBuilder().WithRuntimeObjects(workflow).Build()
config := &rest.Config{}
devReconciler := newDevProfileReconciler(client, config, &logger)
Expand Down
Loading

0 comments on commit 91f326f

Please sign in to comment.