forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
70 lines (57 loc) · 1.91 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package helmtest
import (
"errors"
"fmt"
"os"
"strconv"
log "github.com/sirupsen/logrus"
)
const (
applicationEnvName = "APPLICATION"
namespaceEnvName = "NAMESPACE"
serviceAccountEnvName = "SERVICE_ACCOUNT"
mockServicePortEnvName = "MOCK_SERVICE_PORT"
testExecutorImageEnvName = "TEST_EXECUTOR_IMAGE"
)
type TestConfig struct {
Application string
Namespace string
ServiceAccountName string
MockServicePort int
TestExecutorImage string
}
func ReadConfig() (TestConfig, error) {
namespace, found := os.LookupEnv(namespaceEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", namespaceEnvName))
}
application, found := os.LookupEnv(applicationEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", applicationEnvName))
}
serviceAccountName, found := os.LookupEnv(serviceAccountEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", serviceAccountEnvName))
}
mockServicePortStr, found := os.LookupEnv(mockServicePortEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", mockServicePortEnvName))
}
mockServicePort, err := strconv.Atoi(mockServicePortStr)
if err != nil {
return TestConfig{}, errors.New(fmt.Sprintf("failed to parse %s env value to int", mockServicePortEnvName))
}
testExecutorImage, found := os.LookupEnv(testExecutorImageEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to parse %s env value to int", testExecutorImageEnvName))
}
config := TestConfig{
Application: application,
Namespace: namespace,
ServiceAccountName: serviceAccountName,
MockServicePort: mockServicePort,
TestExecutorImage: testExecutorImage,
}
log.Printf("Read configuration: %+v", config)
return config, nil
}