forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
70 lines (57 loc) · 1.89 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 executor
import (
"errors"
"fmt"
"os"
"strconv"
log "github.com/sirupsen/logrus"
)
const (
applicationEnvName = "APPLICATION"
namespaceEnvName = "NAMESPACE"
mockSelectorKeyEnvName = "SELECTOR_KEY"
mockSelectorValueEnvName = "SELECTOR_VALUE"
mockServicePortEnvName = "MOCK_SERVICE_PORT"
)
type TestConfig struct {
Application string
Namespace string
MockSelectorKey string
MockSelectorValue string
MockServicePort int32
}
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))
}
selectorKey, found := os.LookupEnv(mockSelectorKeyEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", mockSelectorKeyEnvName))
}
selectorValue, found := os.LookupEnv(mockSelectorValueEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", mockSelectorValueEnvName))
}
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))
}
config := TestConfig{
Application: application,
Namespace: namespace,
MockSelectorKey: selectorKey,
MockSelectorValue: selectorValue,
MockServicePort: int32(mockServicePort),
}
log.Printf("Read configuration: %+v", config)
return config, nil
}