summaryrefslogtreecommitdiffstats
path: root/src/dkv/api/initialise_test.go
diff options
context:
space:
mode:
authorShashank Kumar Shankar <shashank.kumar.shankar@intel.com>2018-05-23 16:01:03 -0700
committerShashank Kumar Shankar <shashank.kumar.shankar@intel.com>2018-05-23 16:03:24 -0700
commit18d9d994e85ef897d570081bc3a7e1da42b49c1e (patch)
treec1e05000de167c04f14fd81cc25fb8583078463d /src/dkv/api/initialise_test.go
parent5e6124aa915bd66734214ded0a25740b544bfa52 (diff)
Create Token Service JSON dynamically2.0.0-ONAPbeijing2.0.0-ONAP
This patch makes sure the Token Service JSON is dynically created so that this fits better when deployed on Kubernetes. Change-Id: I4426f68af2a6de4d2ffe4f488d5660c47f13ccaf Issue-ID: MUSIC-55 Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Diffstat (limited to 'src/dkv/api/initialise_test.go')
-rw-r--r--src/dkv/api/initialise_test.go66
1 files changed, 59 insertions, 7 deletions
diff --git a/src/dkv/api/initialise_test.go b/src/dkv/api/initialise_test.go
index 363edce..2d54bec 100644
--- a/src/dkv/api/initialise_test.go
+++ b/src/dkv/api/initialise_test.go
@@ -22,41 +22,93 @@ import (
"testing"
)
-func TestInitialise_cassandra(t *testing.T) {
+func TestInitialise_consul(t *testing.T) {
oldDatastore_ip := os.Getenv("DATASTORE_IP")
oldDatastore_type := os.Getenv("DATASTORE")
+ oldJsonExists := JsonChecker
+ oldJsonCreate := JsonCreate
os.Setenv("DATASTORE_IP", "localhost")
- os.Setenv("DATASTORE", "cassandra")
+ os.Setenv("DATASTORE", "consul")
defer func() {
os.Setenv("DATASTORE_IP", oldDatastore_ip)
os.Setenv("DATASTORE", oldDatastore_type)
+ JsonCreate = oldJsonCreate
+ JsonChecker = oldJsonExists
}()
+ JsonChecker = func(path string) (bool, error) {
+ return false, nil
+ }
+
+ JsonCreate = func(path string) error {
+ return nil
+ }
+
err := Initialise()
- assert.Nil(t, err)
+ assert.NotNil(t, err)
}
-func TestInitialise_consulError(t *testing.T) {
+
+func TestInitialise_cassandra(t *testing.T) {
oldDatastore_ip := os.Getenv("DATASTORE_IP")
oldDatastore_type := os.Getenv("DATASTORE")
+ oldMOUNTPATH := os.Getenv("MOUNTPATH")
+ oldJsonChecker := JsonChecker
os.Setenv("DATASTORE_IP", "localhost")
- os.Setenv("DATASTORE", "consul")
+ os.Setenv("DATASTORE", "cassandra")
defer func() {
os.Setenv("DATASTORE_IP", oldDatastore_ip)
os.Setenv("DATASTORE", oldDatastore_type)
+ os.Setenv("MOUNTPATH", oldMOUNTPATH)
+ JsonChecker = oldJsonChecker
}()
+ JsonChecker = func(path string) (bool, error) {
+ return true, nil
+ }
+
+ err := Initialise()
+ assert.Nil(t, err)
+}
+
+func TestInitialise_datastoreUnknown(t *testing.T) {
+ datastore := os.Getenv("DATASTORE")
+ defer os.Setenv("DATASTORE", datastore)
+ os.Setenv("DATASTORE", "test")
+
err := Initialise()
assert.NotNil(t, err)
}
-func TestInitialise_datastoreEmptyError(t *testing.T) {
+func TestInitialise_datastoreEmpty(t *testing.T) {
datastore := os.Getenv("DATASTORE")
- os.Unsetenv("DATASTORE")
defer os.Setenv("DATASTORE", datastore)
+ os.Setenv("DATASTORE", "")
+
+ err := Initialise()
+ assert.NotNil(t, err)
+}
+
+func TestInitialise_noJSON(t *testing.T) {
+ oldDatastore_ip := os.Getenv("DATASTORE_IP")
+ oldDatastore_type := os.Getenv("DATASTORE")
+ oldJsonChecker := JsonChecker
+
+ os.Setenv("DATASTORE_IP", "localhost")
+ os.Setenv("DATASTORE", "consul")
+
+ defer func() {
+ os.Setenv("DATASTORE_IP", oldDatastore_ip)
+ os.Setenv("DATASTORE", oldDatastore_type)
+ JsonChecker = oldJsonChecker
+ }()
+
+ JsonChecker = func(path string) (bool, error) {
+ return false, nil
+ }
err := Initialise()
assert.NotNil(t, err)