-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcftools_test.go
More file actions
48 lines (37 loc) · 1.22 KB
/
cftools_test.go
File metadata and controls
48 lines (37 loc) · 1.22 KB
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
package cftools_test
import (
"testing"
"github.com/cloudfoundry-community/go-cfenv"
. "github.com/cloudnativego/cf-tools"
)
func TestGetVCAPServiceProperty(t *testing.T) {
fakeVCAP := []string{
`VCAP_APPLICATION={}`,
`VCAP_SERVICES={"user-provided": [{"credentials": {"target-url": "http://beer.com"}, "label": "user-provided", "name": "beer", "syslog_drain_url": "", "tags": []}]}`,
}
testEnv := cfenv.Env(fakeVCAP)
cfenv, err := cfenv.New(testEnv)
if cfenv == nil || err != nil {
t.Errorf("cfenv is nil: %v", err.Error())
}
propertyValue, err := GetVCAPServiceProperty("beer", "target-url", cfenv)
if err != nil {
t.Errorf("Could not find service property: %v", err.Error())
}
expectedValue := "http://beer.com"
if propertyValue != expectedValue {
t.Errorf("Expected property to equal %s, got %s instead.", expectedValue, propertyValue)
}
}
func TestNoVCAPDoesNotPanic(t *testing.T) {
noVCAP := []string{}
testEnv := cfenv.Env(noVCAP)
cfenv, err := cfenv.New(testEnv)
if err == nil {
t.Error("err should not be nil if VCAP is not present")
}
_, err = GetVCAPServiceProperty("beer", "target-url", cfenv)
if err == nil {
t.Error("GetVCAPServiceProperty should return error if no valid VCAP present")
}
}