Semaphore/db_lib/LocalApp_test.go

53 lines
948 B
Go
Raw Normal View History

2024-10-24 20:07:25 +02:00
package db_lib
import (
"os"
2024-10-28 09:46:24 +01:00
"strings"
2024-10-24 20:07:25 +02:00
"testing"
"github.com/semaphoreui/semaphore/util"
2024-10-24 20:07:25 +02:00
)
// contains checks if a slice contains a specific string
func contains(slice []string, item string) bool {
for _, s := range slice {
2024-10-28 09:46:24 +01:00
if strings.HasPrefix(s, item) {
2024-10-24 20:07:25 +02:00
return true
}
}
return false
}
func TestGetEnvironmentVars(t *testing.T) {
os.Setenv("SEMAPHORE_TEST", "test123")
os.Setenv("SEMAPHORE_TEST2", "test222")
os.Setenv("PASSWORD", "test222")
util.Config = &util.ConfigType{
ForwardedEnvVars: []string{"SEMAPHORE_TEST"},
EnvVars: map[string]string{
"ANSIBLE_FORCE_COLOR": "False",
},
}
res := getEnvironmentVars()
expected := []string{
"SEMAPHORE_TEST=test123",
"ANSIBLE_FORCE_COLOR=False",
2024-10-28 09:46:24 +01:00
"PATH=",
2024-10-24 20:07:25 +02:00
}
if len(res) != len(expected) {
t.Errorf("Expected %v, got %v", expected, res)
}
for _, e := range expected {
if !contains(res, e) {
t.Errorf("Expected %v, got %v", expected, res)
}
}
}