Chart naming validation on AutoscalingRunnerSet install (#2347)

Co-authored-by: Bassem Dghaidi <568794+Link-@users.noreply.github.com>
Co-authored-by: Bassem Dghaidi <Link-@github.com>
This commit is contained in:
Nikola Jokic
2023-03-02 10:35:55 +01:00
committed by GitHub
parent e8d8c6f357
commit be47190d4c
3 changed files with 73 additions and 11 deletions

View File

@@ -780,3 +780,45 @@ func TestTemplateRenderedWithProxy(t *testing.T) {
assert.Contains(t, ars.Spec.Proxy.NoProxy, "example.com")
assert.Contains(t, ars.Spec.Proxy.NoProxy, "example.org")
}
func TestTemplateNamingConstraints(t *testing.T) {
t.Parallel()
// Path to the helm chart we will test
helmChartPath, err := filepath.Abs("../../gha-runner-scale-set")
require.NoError(t, err)
setValues := map[string]string{
"githubConfigUrl": "https://github.com/actions",
"githubConfigSecret": "",
}
tt := map[string]struct {
releaseName string
namespaceName string
expectedError string
}{
"Name too long": {
releaseName: strings.Repeat("a", 46),
namespaceName: "test-" + strings.ToLower(random.UniqueId()),
expectedError: "Name must have up to 45 characters",
},
"Namespace too long": {
releaseName: "test-" + strings.ToLower(random.UniqueId()),
namespaceName: strings.Repeat("a", 64),
expectedError: "Namespace must have up to 63 characters",
},
}
for name, tc := range tt {
t.Run(name, func(t *testing.T) {
options := &helm.Options{
SetValues: setValues,
KubectlOptions: k8s.NewKubectlOptions("", "", tc.namespaceName),
}
_, err = helm.RenderTemplateE(t, options, helmChartPath, tc.releaseName, []string{"templates/autoscalingrunnerset.yaml"})
require.Error(t, err)
assert.ErrorContains(t, err, tc.expectedError)
})
}
}