-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinfo_test.go
73 lines (60 loc) · 1.77 KB
/
info_test.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
71
72
73
package microservicecore
import (
"fmt"
"os"
"testing"
)
// Example environment variables for testing.
var exampleEnvVars = map[string]string{
"SERVICE_NAME": "example-service",
"SERVICE_TYPE": "examples",
"SERVICE_SCOPE": "testing",
"SERVICE_VERSION": "0.0.1",
}
// TestServiceInfo - Test the GetMicroserviceInfo function is working.
func TestServiceInfo(t *testing.T) {
// Set our expected environment variables.
for key, value := range exampleEnvVars {
os.Setenv(key, value)
}
// Get the service info.
info := GetMicroserviceInfo()
// Check each expected env var.
if info.ServiceName != os.Getenv("SERVICE_NAME") {
t.Errorf("Expected %v, got %v", os.Getenv("SERVICE_NAME"), info.ServiceName)
}
if info.ServiceType != os.Getenv("SERVICE_TYPE") {
t.Errorf("Expected %v, got %v", os.Getenv("SERVICE_TYPE"), info.ServiceType)
}
if info.ServiceScope != os.Getenv("SERVICE_SCOPE") {
t.Errorf("Expected %v, got %v", os.Getenv("SERVICE_SCOPE"), info.ServiceScope)
}
if info.ServiceVersion != os.Getenv("SERVICE_VERSION") {
t.Errorf("Expected %v, got %v", os.Getenv("SERVICE_VERSION"), info.ServiceVersion)
}
}
// ExampleGetMicroserviceInfo - Example for GetMicroserviceInfo.
func ExampleGetMicroserviceInfo() {
envVars := map[string]string{
"SERVICE_NAME": "example-service",
"SERVICE_TYPE": "examples",
"SERVICE_SCOPE": "testing",
"SERVICE_VERSION": "0.0.1",
}
// Set our expected environment variables.
for key, value := range envVars {
os.Setenv(key, value)
}
// Get the service info.
info := GetMicroserviceInfo()
// Print the details.
fmt.Println(info.ServiceName)
fmt.Println(info.ServiceType)
fmt.Println(info.ServiceScope)
fmt.Println(info.ServiceVersion)
// Output:
// example-service
// examples
// testing
// 0.0.1
}