diff options
author | Manjunath Ranganathaiah <manjunath.ranganathaiah@intel.com> | 2020-03-30 18:37:18 +0000 |
---|---|---|
committer | Manjunath Ranganathaiah <manjunath.ranganathaiah@intel.com> | 2020-04-01 18:11:51 +0000 |
commit | 8e1269b1f3958d2caa57464b1aac0d086e10c509 (patch) | |
tree | 98c7c2657ea5eff029908af93f5adfbcc56336a5 /src/orchestrator/pkg/appcontext/appcontext_test.go | |
parent | 54ab79c77f0286b95074d2c714292c0b18fb18fb (diff) |
Add init and reinit interfaces to context libs
Issue-ID: MULTICLOUD-1005
Signed-off-by: Manjunath Ranganathaiah <manjunath.ranganathaiah@intel.com>
Change-Id: I9839d265840c25b2fbfbe0265a65c65388eaebcb
Diffstat (limited to 'src/orchestrator/pkg/appcontext/appcontext_test.go')
-rw-r--r-- | src/orchestrator/pkg/appcontext/appcontext_test.go | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/src/orchestrator/pkg/appcontext/appcontext_test.go b/src/orchestrator/pkg/appcontext/appcontext_test.go index a6f3e94e..3fde3a9e 100644 --- a/src/orchestrator/pkg/appcontext/appcontext_test.go +++ b/src/orchestrator/pkg/appcontext/appcontext_test.go @@ -18,15 +18,15 @@ package appcontext import ( "fmt" - "testing" - "strings" pkgerrors "github.com/pkg/errors" + "strings" + "testing" ) // Mock run time context type MockRunTimeContext struct { Items map[string]interface{} - Err error + Err error } func (c *MockRunTimeContext) RtcCreate() (interface{}, error) { @@ -40,6 +40,16 @@ func (c *MockRunTimeContext) RtcCreate() (interface{}, error) { } +func (c *MockRunTimeContext) RtcInit() (interface{}, error) { + var id string = "9345674458787728" + return id, c.Err +} + +func (c *MockRunTimeContext) RtcLoad(id interface{}) (interface{}, error) { + str := "/context/" + fmt.Sprintf("%v", id) + "/" + return interface{}(str), c.Err +} + func (c *MockRunTimeContext) RtcGet() (interface{}, error) { var key string = "/context/9345674458787728/" return key, c.Err @@ -65,13 +75,13 @@ func (c *MockRunTimeContext) RtcAddInstruction(handle interface{}, level string, return nil, c.Err } -func (c *MockRunTimeContext) RtcDeletePair(handle interface{}) (error) { +func (c *MockRunTimeContext) RtcDeletePair(handle interface{}) error { str := fmt.Sprintf("%v", handle) delete(c.Items, str) return c.Err } -func (c *MockRunTimeContext) RtcDeletePrefix(handle interface{}) (error) { +func (c *MockRunTimeContext) RtcDeletePrefix(handle interface{}) error { for k, _ := range c.Items { delete(c.Items, k) } @@ -87,7 +97,7 @@ func (c *MockRunTimeContext) RtcGetHandles(handle interface{}) ([]interface{}, e return keys, c.Err } -func (c *MockRunTimeContext) RtcGetValue(handle interface{}, value interface{}) (error) { +func (c *MockRunTimeContext) RtcGetValue(handle interface{}, value interface{}) error { key := fmt.Sprintf("%v", handle) var s *string s = value.(*string) @@ -100,7 +110,7 @@ func (c *MockRunTimeContext) RtcGetValue(handle interface{}, value interface{}) return c.Err } -func (c *MockRunTimeContext) RtcUpdateValue(handle interface{}, value interface{}) (error) { +func (c *MockRunTimeContext) RtcUpdateValue(handle interface{}, value interface{}) error { key := fmt.Sprintf("%v", handle) c.Items[key] = value return c.Err @@ -109,16 +119,16 @@ func (c *MockRunTimeContext) RtcUpdateValue(handle interface{}, value interface{ func TestCreateCompositeApp(t *testing.T) { var ac = AppContext{} testCases := []struct { - label string + label string mockRtcontext *MockRunTimeContext expectedError string }{ { - label: "Success case", + label: "Success case", mockRtcontext: &MockRunTimeContext{}, }, { - label: "Create returns error case", + label: "Create returns error case", mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error creating run time context:")}, expectedError: "Error creating run time context:", }, @@ -141,16 +151,16 @@ func TestCreateCompositeApp(t *testing.T) { func TestGetCompositeApp(t *testing.T) { var ac = AppContext{} testCases := []struct { - label string + label string mockRtcontext *MockRunTimeContext expectedError string }{ { - label: "Success case", + label: "Success case", mockRtcontext: &MockRunTimeContext{}, }, { - label: "Get returns error case", + label: "Get returns error case", mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error getting run time context:")}, expectedError: "Error getting run time context:", }, @@ -173,16 +183,16 @@ func TestGetCompositeApp(t *testing.T) { func TestDeleteCompositeApp(t *testing.T) { var ac = AppContext{} testCases := []struct { - label string + label string mockRtcontext *MockRunTimeContext expectedError string }{ { - label: "Success case", + label: "Success case", mockRtcontext: &MockRunTimeContext{}, }, { - label: "Delete returns error case", + label: "Delete returns error case", mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error deleting run time context:")}, expectedError: "Error deleting run time context:", }, @@ -205,20 +215,20 @@ func TestDeleteCompositeApp(t *testing.T) { func TestAddApp(t *testing.T) { var ac = AppContext{} testCases := []struct { - label string + label string mockRtcontext *MockRunTimeContext - key interface{} + key interface{} expectedError string }{ { - label: "Success case", + label: "Success case", mockRtcontext: &MockRunTimeContext{}, - key: "/context/9345674458787728/", + key: "/context/9345674458787728/", }, { - label: "Delete returns error case", + label: "Delete returns error case", mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error adding app to run time context:")}, - key: "/context/9345674458787728/", + key: "/context/9345674458787728/", expectedError: "Error adding app to run time context:", }, } @@ -241,29 +251,29 @@ func TestAddApp(t *testing.T) { func TestGetAppHandle(t *testing.T) { var ac = AppContext{} testCases := []struct { - label string + label string mockRtcontext *MockRunTimeContext - key interface{} - appname string + key interface{} + appname string expectedError string }{ { - label: "Success case", + label: "Success case", mockRtcontext: &MockRunTimeContext{}, - key: "/context/9345674458787728/", - appname: "testapp1", + key: "/context/9345674458787728/", + appname: "testapp1", }, { - label: "Invalid app name case", + label: "Invalid app name case", mockRtcontext: &MockRunTimeContext{}, - key: "/context/9345674458787728/", - appname: "", + key: "/context/9345674458787728/", + appname: "", }, { - label: "Delete returns error case", + label: "Delete returns error case", mockRtcontext: &MockRunTimeContext{Err: pkgerrors.Errorf("Error getting app handle from run time context:")}, - key: "/context/9345674458787728/", - appname: "testapp1", + key: "/context/9345674458787728/", + appname: "testapp1", expectedError: "Error getting app handle from run time context:", }, } |