Skip to content

Commit

Permalink
minimal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslaw-pieszka committed Jul 10, 2024
1 parent 798ce6c commit af99fa7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/process/provisioning/create_runtime_resource_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func (s *CreateRuntimeResourceStep) Run(operation internal.Operation, log logrus
}

if !s.kimConfig.IsEnabledForPlan(broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID]) {
log.Infof("KIM is disabled for plan %s, skipping", broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID])
log.Infof("KIM is not enabled for plan %s, skipping", broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID])
}

log.Info("Runtime CR creation process finished successfully")
return operation, 0, nil
}

//TODO remember labels and annotations
//TODO remember - labels and annotations

func (s *CreateRuntimeResourceStep) createRuntimeResourceObject(operation internal.Operation) (imv1.Runtime, error) {
runtime := imv1.Runtime{}
Expand Down
45 changes: 45 additions & 0 deletions internal/process/provisioning/create_runtime_resource_step_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package provisioning

import (
"github.com/kyma-project/kyma-environment-broker/internal/fixture"
"github.com/kyma-project/kyma-environment-broker/internal/kim"
"testing"

"github.com/kyma-project/kyma-environment-broker/internal/storage"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func TestCreateRuntimeResourceStep_HappyPath_YamlOnly(t *testing.T) {
// given
log := logrus.New()
memoryStorage := storage.NewMemoryStorage()

preOperation := fixture.FixProvisioningOperation(operationID, instanceID)
err := memoryStorage.Operations().InsertOperation(preOperation)
assert.NoError(t, err)

err = memoryStorage.Instances().Insert(fixInstance())
assert.NoError(t, err)

kimConfig := kim.Config{
Enabled: true,
Plans: []string{"preview"},
ViewOnly: false,
DryRun: true,
}
step := NewCreateRuntimeResourceStep(memoryStorage.Operations(), memoryStorage.RuntimeStates(), memoryStorage.Instances(), kimConfig)

// when
entry := log.WithFields(logrus.Fields{"step": "TEST"})
_, repeat, err := step.Run(preOperation, entry)

// then
assert.NoError(t, err)
assert.Zero(t, repeat)

_, err = memoryStorage.Instances().GetByID(preOperation.InstanceID)
assert.NoError(t, err)

//assert.YAMLEq(t, expectedKymaTemplate, op.KymaTemplate)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package provisioning

import (
"github.com/kyma-project/kyma-environment-broker/internal/broker"
"github.com/kyma-project/kyma-environment-broker/internal/fixture"
"testing"

"github.com/sirupsen/logrus"
Expand All @@ -19,8 +19,7 @@ func TestNewGenerateRuntimeIDStep_LeaveRuntimeIDIfNotEmpty(t *testing.T) {
err := memoryStorage.Instances().Insert(instance)
assert.NoError(t, err)

operation := fixOperationCreateRuntime(t, broker.GCPPlanID, "europe-west3")
operation.ShootDomain = "kyma.org"
operation := fixture.FixProvisioningOperation(operationID, instanceID)
operation.RuntimeID = instance.RuntimeID

err = memoryStorage.Operations().InsertOperation(operation)
Expand All @@ -47,8 +46,7 @@ func TestNewGenerateRuntimeIDStep_LeaveCreateRuntimeIDIfEmpty(t *testing.T) {
log := logrus.New()
memoryStorage := storage.NewMemoryStorage()

operation := fixOperationCreateRuntime(t, broker.GCPPlanID, "europe-west3")
operation.ShootDomain = "kyma.org"
operation := fixture.FixProvisioningOperation(operationID, instanceID)
operation.RuntimeID = ""
err := memoryStorage.Operations().InsertOperation(operation)
assert.NoError(t, err)
Expand Down

0 comments on commit af99fa7

Please sign in to comment.