generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding unit tests for ExtendWithSeedSelector extender function
- Loading branch information
Showing
3 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package extender | ||
|
||
import ( | ||
"testing" | ||
|
||
imv1 "github.com/kyma-project/infrastructure-manager/api/v1" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSeedSelectorExtender(t *testing.T) { | ||
t.Run("Add and populate seed selector field if RuntimeCR has SeedInSameRegionFlag set to true", func(t *testing.T) { | ||
// given | ||
runtimeShoot := getRuntimeWithSeedInSameRegionFlag(true) | ||
shoot := fixEmptyGardenerShoot("test", "dev") | ||
|
||
// when | ||
err := ExtendWithSeedSelector(runtimeShoot, &shoot) | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.NotNil(t, shoot.Spec.SeedSelector) | ||
assert.Equal(t, runtimeShoot.Spec.Shoot.Region, shoot.Spec.SeedSelector.LabelSelector.MatchLabels[seedRegionSelectorLabel]) | ||
}) | ||
|
||
t.Run("Don't add seed selector field if RuntimeCR has SeedInSameRegionFlag set to false", func(t *testing.T) { | ||
// given | ||
runtimeShoot := getRuntimeWithSeedInSameRegionFlag(false) | ||
shoot := fixEmptyGardenerShoot("test", "dev") | ||
|
||
// when | ||
err := ExtendWithSeedSelector(runtimeShoot, &shoot) | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Nil(t, shoot.Spec.SeedSelector) | ||
}) | ||
|
||
t.Run("Don't add seed selector field if RuntimeCR has no SeedInSameRegionFlag set", func(t *testing.T) { | ||
// given | ||
runtimeShoot := getRuntimeWithoutSeedInSameRegionFlag() | ||
shoot := fixEmptyGardenerShoot("test", "dev") | ||
|
||
// when | ||
err := ExtendWithSeedSelector(runtimeShoot, &shoot) | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Nil(t, shoot.Spec.SeedSelector) | ||
}) | ||
} | ||
|
||
func getRuntimeWithSeedInSameRegionFlag(enabled bool) imv1.Runtime { | ||
return imv1.Runtime{ | ||
Spec: imv1.RuntimeSpec{ | ||
Shoot: imv1.RuntimeShoot{ | ||
Name: "myshoot", | ||
EnforceSeedLocation: &enabled, | ||
Region: "far-far-away", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func getRuntimeWithoutSeedInSameRegionFlag() imv1.Runtime { | ||
return imv1.Runtime{ | ||
Spec: imv1.RuntimeSpec{ | ||
Shoot: imv1.RuntimeShoot{ | ||
Name: "myshoot", | ||
Region: "far-far-away", | ||
}, | ||
}, | ||
} | ||
} |