Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(util): update map to envVars func #71

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/util/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package util

import corev1 "k8s.io/api/core/v1"

func EnvsToEnvVars(envs map[string]string) []corev1.EnvVar {
func NewEnvVarsFromMap(envs map[string]string) []corev1.EnvVar {
envVars := make([]corev1.EnvVar, 0, len(envs))
for k, v := range envs {
envVars = append(envVars, corev1.EnvVar{Name: k, Value: v})
Expand Down
31 changes: 31 additions & 0 deletions pkg/util/env_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package util

import (
"testing"

corev1 "k8s.io/api/core/v1"
)

func TestNewEnvVarsFromMap(t *testing.T) {
envs := map[string]string{
"KEY1": "VALUE1",
"KEY2": "VALUE2",
}

expectedEnvVars := []corev1.EnvVar{
{Name: "KEY1", Value: "VALUE1"},
{Name: "KEY2", Value: "VALUE2"},
}

envVars := NewEnvVarsFromMap(envs)

if len(envVars) != len(expectedEnvVars) {
t.Errorf("Expected %d env vars, but got %d", len(expectedEnvVars), len(envVars))
}

for i, expectedEnvVar := range expectedEnvVars {
if envVars[i].Name != expectedEnvVar.Name || envVars[i].Value != expectedEnvVar.Value {
t.Errorf("Expected env var %s=%s, but got %s=%s", expectedEnvVar.Name, expectedEnvVar.Value, envVars[i].Name, envVars[i].Value)
}
}
}
Loading