Update charts/gha-runner-scale-set/tests/template_test.go
Co-authored-by: Nikola Jokic <jokicnikola07@gmail.com>
This commit is contained in:
		
							parent
							
								
									79bc36740a
								
							
						
					
					
						commit
						9880df4a68
					
				|  | @ -2326,133 +2326,143 @@ func TestNamespaceOverride(t *testing.T) { | ||||||
| 	releaseNamespace := "test-" + strings.ToLower(random.UniqueId()) | 	releaseNamespace := "test-" + strings.ToLower(random.UniqueId()) | ||||||
| 	namespaceOverride := "test-" + strings.ToLower(random.UniqueId()) | 	namespaceOverride := "test-" + strings.ToLower(random.UniqueId()) | ||||||
| 
 | 
 | ||||||
| 	options := map[string]*helm.Options{ | 	tt := map[string]struct { | ||||||
| 		"_": { | 		file    string | ||||||
| 			Logger: logger.Discard, | 		options *helm.Options | ||||||
| 			SetValues: map[string]string{ | 	}{ | ||||||
| 				"namespaceOverride": namespaceOverride, |  | ||||||
| 			}, |  | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, |  | ||||||
| 		"manager_role": { | 		"manager_role": { | ||||||
| 			Logger: logger.Discard, | 			file: "manager_role.yaml", | ||||||
| 			SetValues: map[string]string{ | 			options: &helm.Options{ | ||||||
| 				"namespaceOverride":                  namespaceOverride, | 				Logger: logger.Discard, | ||||||
| 				"controllerServiceAccount.name":      "foo", | 				SetValues: map[string]string{ | ||||||
| 				"controllerServiceAccount.namespace": "bar", | 					"namespaceOverride":                  namespaceOverride, | ||||||
| 				"githubConfigSecret.github_token":    "gh_token12345", | 					"controllerServiceAccount.name":      "foo", | ||||||
| 				"githubConfigUrl":                    "https://github.com", | 					"controllerServiceAccount.namespace": "bar", | ||||||
|  | 					"githubConfigSecret.github_token":    "gh_token12345", | ||||||
|  | 					"githubConfigUrl":                    "https://github.com", | ||||||
|  | 				}, | ||||||
|  | 				KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), | ||||||
| 			}, | 			}, | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, | 		}, | ||||||
| 		"manager_role_binding": { | 		"manager_role_binding": { | ||||||
| 			Logger: logger.Discard, | 			file: "manager_role_binding.yaml", | ||||||
| 			SetValues: map[string]string{ | 			options: &helm.Options{ | ||||||
| 				"namespaceOverride":                  namespaceOverride, | 				Logger: logger.Discard, | ||||||
| 				"controllerServiceAccount.name":      "foo", | 				SetValues: map[string]string{ | ||||||
| 				"controllerServiceAccount.namespace": "bar", | 					"namespaceOverride":                  namespaceOverride, | ||||||
| 				"githubConfigSecret.github_token":    "gh_token12345", | 					"controllerServiceAccount.name":      "foo", | ||||||
| 				"githubConfigUrl":                    "https://github.com", | 					"controllerServiceAccount.namespace": "bar", | ||||||
|  | 					"githubConfigSecret.github_token":    "gh_token12345", | ||||||
|  | 					"githubConfigUrl":                    "https://github.com", | ||||||
|  | 				}, | ||||||
|  | 				KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), | ||||||
| 			}, | 			}, | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, | 		}, | ||||||
| 		"no_permission_serviceaccount": { | 		"no_permission_serviceaccount": { | ||||||
| 			Logger: logger.Discard, | 			file: "no_permission_serviceaccount.yaml", | ||||||
| 			SetValues: map[string]string{ | 			options: &helm.Options{ | ||||||
| 				"namespaceOverride":                  namespaceOverride, | 				Logger: logger.Discard, | ||||||
| 				"controllerServiceAccount.name":      "foo", | 				SetValues: map[string]string{ | ||||||
| 				"controllerServiceAccount.namespace": "bar", | 					"namespaceOverride":                  namespaceOverride, | ||||||
| 				"githubConfigSecret.github_token":    "gh_token12345", | 					"controllerServiceAccount.name":      "foo", | ||||||
| 				"githubConfigUrl":                    "https://github.com", | 					"controllerServiceAccount.namespace": "bar", | ||||||
|  | 					"githubConfigSecret.github_token":    "gh_token12345", | ||||||
|  | 					"githubConfigUrl":                    "https://github.com", | ||||||
|  | 				}, | ||||||
|  | 				KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), | ||||||
| 			}, | 			}, | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, | 		}, | ||||||
| 		"autoscalingrunnerset": { | 		"autoscalingrunnerset": { | ||||||
| 			Logger: logger.Discard, | 			file: "autoscalingrunnerset.yaml", | ||||||
| 			SetValues: map[string]string{ | 			options: &helm.Options{ | ||||||
| 				"namespaceOverride":                  namespaceOverride, | 				Logger: logger.Discard, | ||||||
| 				"controllerServiceAccount.name":      "foo", | 				SetValues: map[string]string{ | ||||||
| 				"controllerServiceAccount.namespace": "bar", | 					"namespaceOverride":                  namespaceOverride, | ||||||
| 				"githubConfigSecret.github_token":    "gh_token12345", | 					"controllerServiceAccount.name":      "foo", | ||||||
| 				"githubConfigUrl":                    "https://github.com", | 					"controllerServiceAccount.namespace": "bar", | ||||||
|  | 					"githubConfigSecret.github_token":    "gh_token12345", | ||||||
|  | 					"githubConfigUrl":                    "https://github.com", | ||||||
|  | 				}, | ||||||
|  | 				KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), | ||||||
| 			}, | 			}, | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, | 		}, | ||||||
| 		"githubsecret": { | 		"githubsecret": { | ||||||
| 			Logger: logger.Discard, | 			file: "githubsecret.yaml", | ||||||
| 			SetValues: map[string]string{ | 			options: &helm.Options{ | ||||||
| 				"namespaceOverride":                  namespaceOverride, | 				Logger: logger.Discard, | ||||||
| 				"controllerServiceAccount.name":      "foo", | 				SetValues: map[string]string{ | ||||||
| 				"controllerServiceAccount.namespace": "bar", | 					"namespaceOverride":                  namespaceOverride, | ||||||
| 				"githubConfigSecret.github_token":    "gh_token12345", | 					"controllerServiceAccount.name":      "foo", | ||||||
| 				"githubConfigUrl":                    "https://github.com", | 					"controllerServiceAccount.namespace": "bar", | ||||||
|  | 					"githubConfigSecret.github_token":    "gh_token12345", | ||||||
|  | 					"githubConfigUrl":                    "https://github.com", | ||||||
|  | 				}, | ||||||
|  | 				KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), | ||||||
| 			}, | 			}, | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, | 		}, | ||||||
| 		"kube_mode_role": { | 		"kube_mode_role": { | ||||||
| 			Logger: logger.Discard, | 			file: "kube_mode_role.yaml", | ||||||
| 			SetValues: map[string]string{ | 			options: &helm.Options{ | ||||||
| 				"namespaceOverride":                  namespaceOverride, | 				Logger: logger.Discard, | ||||||
| 				"containerMode.type":                 "kubernetes", | 				SetValues: map[string]string{ | ||||||
| 				"controllerServiceAccount.name":      "foo", | 					"namespaceOverride":                  namespaceOverride, | ||||||
| 				"controllerServiceAccount.namespace": "bar", | 					"containerMode.type":                 "kubernetes", | ||||||
| 				"githubConfigSecret.github_token":    "gh_token12345", | 					"controllerServiceAccount.name":      "foo", | ||||||
| 				"githubConfigUrl":                    "https://github.com", | 					"controllerServiceAccount.namespace": "bar", | ||||||
|  | 					"githubConfigSecret.github_token":    "gh_token12345", | ||||||
|  | 					"githubConfigUrl":                    "https://github.com", | ||||||
|  | 				}, | ||||||
|  | 				KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), | ||||||
| 			}, | 			}, | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, | 		}, | ||||||
| 		"kube_mode_role_binding": { | 		"kube_mode_role_binding": { | ||||||
| 			Logger: logger.Discard, | 			file: "kube_mode_role_binding.yaml", | ||||||
| 			SetValues: map[string]string{ | 			options: &helm.Options{ | ||||||
| 				"namespaceOverride":                  namespaceOverride, | 				Logger: logger.Discard, | ||||||
| 				"containerMode.type":                 "kubernetes", | 				SetValues: map[string]string{ | ||||||
| 				"controllerServiceAccount.name":      "foo", | 					"namespaceOverride":                  namespaceOverride, | ||||||
| 				"controllerServiceAccount.namespace": "bar", | 					"containerMode.type":                 "kubernetes", | ||||||
| 				"githubConfigSecret.github_token":    "gh_token12345", | 					"controllerServiceAccount.name":      "foo", | ||||||
| 				"githubConfigUrl":                    "https://github.com", | 					"controllerServiceAccount.namespace": "bar", | ||||||
|  | 					"githubConfigSecret.github_token":    "gh_token12345", | ||||||
|  | 					"githubConfigUrl":                    "https://github.com", | ||||||
|  | 				}, | ||||||
|  | 				KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), | ||||||
| 			}, | 			}, | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, | 		}, | ||||||
| 		"kube_mode_serviceaccount": { | 		"kube_mode_serviceaccount": { | ||||||
| 			Logger: logger.Discard, | 			file: "kube_mode_serviceaccount.yaml", | ||||||
| 			SetValues: map[string]string{ | 			options: &helm.Options{ | ||||||
| 				"namespaceOverride":                  namespaceOverride, | 				Logger: logger.Discard, | ||||||
| 				"containerMode.type":                 "kubernetes", | 				SetValues: map[string]string{ | ||||||
| 				"controllerServiceAccount.name":      "foo", | 					"namespaceOverride":                  namespaceOverride, | ||||||
| 				"controllerServiceAccount.namespace": "bar", | 					"containerMode.type":                 "kubernetes", | ||||||
| 				"githubConfigSecret.github_token":    "gh_token12345", | 					"controllerServiceAccount.name":      "foo", | ||||||
| 				"githubConfigUrl":                    "https://github.com", | 					"controllerServiceAccount.namespace": "bar", | ||||||
|  | 					"githubConfigSecret.github_token":    "gh_token12345", | ||||||
|  | 					"githubConfigUrl":                    "https://github.com", | ||||||
|  | 				}, | ||||||
|  | 				KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), | ||||||
| 			}, | 			}, | ||||||
| 			KubectlOptions: k8s.NewKubectlOptions("", "", releaseNamespace), |  | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	templateFiles, err := os.ReadDir(filepath.Join(chartPath, "templates")) |  | ||||||
| 	require.NoError(t, err) |  | ||||||
| 
 | 
 | ||||||
| 	for _, f := range templateFiles { | 	for name, tc := range tt { | ||||||
| 		fileExtension := filepath.Ext(f.Name()) | 		t.Run(name, func(t *testing.T) { | ||||||
| 		if fileExtension != ".yaml" && fileExtension != ".yml" { | 			t.Parallel() | ||||||
| 			continue | 			templateFile := filepath.Join("templates", tc.file) | ||||||
| 		} | 
 | ||||||
| 		templateFile := filepath.Join("templates", f.Name()) | 			output, err := helm.RenderTemplateE(t, tc.options, chartPath, releaseName, []string{templateFile}) | ||||||
| 		opts := options["_"] | 			if err != nil { | ||||||
| 		for k := range options { | 				t.Errorf("Error rendering template %s from chart %s: %s", tc.file, chartPath, err) | ||||||
| 			if strings.TrimSuffix(f.Name(), fileExtension) == k { |  | ||||||
| 				opts = options[k] |  | ||||||
| 				break |  | ||||||
| 			} | 			} | ||||||
| 		} |  | ||||||
| 		output, err := helm.RenderTemplateE(t, opts, chartPath, releaseName, []string{templateFile}) |  | ||||||
| 
 | 
 | ||||||
| 		if err != nil { | 			type object struct { | ||||||
| 			t.Errorf("Error rendering template %s from chart %s: %s", f.Name(), chartPath, err) | 				Metadata metav1.ObjectMeta | ||||||
| 		} | 			} | ||||||
| 
 | 			var renderedObject object | ||||||
| 		var renderedObject map[string]interface{} | 			helm.UnmarshalK8SYaml(t, output, &renderedObject) | ||||||
| 		helm.UnmarshalK8SYaml(t, output, &renderedObject) | 			assert.Equal(t, namespaceOverride, renderedObject.Metadata.Namespace) | ||||||
| 
 | 		}) | ||||||
| 		if renderedObject["metadata"].(map[string]interface{})["namespace"] != nil { |  | ||||||
| 			assert.Equal(t, namespaceOverride, renderedObject["metadata"].(map[string]interface{})["namespace"], fmt.Sprintf("template %s from chart %s should have namespace %s", f.Name(), chartPath, namespaceOverride)) |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue