Skip to content

Commit

Permalink
add test case for inline configmap resources
Browse files Browse the repository at this point in the history
  • Loading branch information
linki committed Mar 20, 2024
1 parent ef7d88d commit eae7cce
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ func NewTestStacksetSpecFactory(stacksetName string) *TestStacksetSpecFactory {
}
}

func (f *TestStacksetSpecFactory) AddInlineConfigMap(configMap *zv1.ConfigMap) *TestStacksetSpecFactory {
f.configurationResources = append(f.configurationResources, zv1.ConfigurationResourcesSpec{
ConfigMap: configMap,
})

f.volumes = append(f.volumes, corev1.Volume{
Name: configMap.Name,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: configMap.Name,
},
},
},
})

return f
}

func (f *TestStacksetSpecFactory) AddReferencedConfigMap(configMapName string) *TestStacksetSpecFactory {
f.configurationResources = append(f.configurationResources, zv1.ConfigurationResourcesSpec{
ConfigMapRef: &corev1.LocalObjectReference{Name: configMapName},
Expand Down
40 changes: 40 additions & 0 deletions cmd/e2e/configuration_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/suite"
zv1 "github.com/zalando-incubator/stackset-controller/pkg/apis/zalando.org/v1"
"github.com/zalando-incubator/stackset-controller/pkg/core"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -30,6 +31,45 @@ func (suite *ConfigurationResourcesTestSuite) SetupTest() {
_ = deleteStackset(suite.stacksetName)
}

// TestInlineConfigMaps tests that ConfigMaps defined inline in the StackSet spec are created and owned by the Stack.
func (suite *ConfigurationResourcesTestSuite) TestInlineConfigMaps() {
// Add the inline ConfigMap data to the StackSet spec
suite.stacksetSpecFactory.AddInlineConfigMap(&zv1.ConfigMap{
Name: "my-configmap",
Data: map[string]string{"key": "value"},
})

// Generate the StackSet spec
stacksetSpec := suite.stacksetSpecFactory.Create(suite.T(), suite.stackVersion)

// Create the StackSet in the cluster
err := createStackSet(suite.stacksetName, 0, stacksetSpec)
suite.Require().NoError(err)

// Wait for the first Stack to be created
stack, err := waitForStack(suite.T(), suite.stacksetName, suite.stackVersion)
suite.Require().NoError(err)

// Fetch the generated ConfigMap in the cluster following the naming convention
configMap, err := waitForConfigMap(suite.T(), "stackset-cr-v1-my-configmap")
suite.Require().NoError(err)

// Ensure that the generated ConfigMap has the expected data
suite.Equal(map[string]string{"key": "value"}, configMap.Data)

// Ensure that the generated ConfigMap is owned by the Stack
suite.Equal([]metav1.OwnerReference{
{
APIVersion: core.APIVersion,
Kind: core.KindStack,
Name: stack.Name,
UID: stack.UID,
},
}, configMap.OwnerReferences)

// TODO: test the Pod Template rewrite
}

// TestReferencedConfigMaps tests that ConfigMaps referenced in the StackSet spec are owned by the Stack.
func (suite *ConfigurationResourcesTestSuite) TestReferencedConfigMaps() {
// Create a ConfigMap in the cluster following the naming convention
Expand Down

0 comments on commit eae7cce

Please sign in to comment.