summaryrefslogtreecommitdiffstats
path: root/src/orchestrator
diff options
context:
space:
mode:
authorRitu Sood <Ritu.Sood@intel.com>2020-03-20 17:53:04 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-20 17:53:04 +0000
commit2bd2f4e76bbf7d5bce6a320ca8958fa547958a8b (patch)
tree3686f8083391a1ba8945af0c128409d4d6a0a760 /src/orchestrator
parentd08b7efcb335d892f0eb6f2c8e4a7d406a9b27fc (diff)
parentb2c0a68d0abf7457d18c89b634265087758b63fd (diff)
Merge "Add update interface to run time context library"
Diffstat (limited to 'src/orchestrator')
-rw-r--r--src/orchestrator/pkg/rtcontext/rtcontext.go16
-rw-r--r--src/orchestrator/pkg/rtcontext/rtcontext_test.go47
2 files changed, 63 insertions, 0 deletions
diff --git a/src/orchestrator/pkg/rtcontext/rtcontext.go b/src/orchestrator/pkg/rtcontext/rtcontext.go
index 5c5bee13..e1f1c03b 100644
--- a/src/orchestrator/pkg/rtcontext/rtcontext.go
+++ b/src/orchestrator/pkg/rtcontext/rtcontext.go
@@ -42,6 +42,7 @@ type Rtcontext interface {
RtcDeletePrefix(handle interface{}) (error)
RtcGetHandles(handle interface{}) ([]interface{}, error)
RtcGetValue(handle interface{}, value interface{}) (error)
+ RtcUpdateValue(handle interface{}, value interface{}) (error)
}
//Create context by assiging a new id
@@ -220,3 +221,18 @@ func (rtc *RunTimeContext) RtcGetValue(handle interface{}, value interface{}) (e
return nil
}
+
+// Update the value of a given handle
+func (rtc *RunTimeContext) RtcUpdateValue(handle interface{}, value interface{}) (error) {
+ str := fmt.Sprintf("%v", handle)
+ sid := fmt.Sprintf("%v", rtc.cid)
+ if !strings.HasPrefix(str, sid) {
+ return pkgerrors.Errorf("Not a valid run time context handle")
+ }
+ err := contextdb.Db.Put(str, value)
+ if err != nil {
+ return pkgerrors.Errorf("Error updating run time context value: %s", err.Error())
+ }
+ return nil
+
+}
diff --git a/src/orchestrator/pkg/rtcontext/rtcontext_test.go b/src/orchestrator/pkg/rtcontext/rtcontext_test.go
index 670b76bb..29df9a25 100644
--- a/src/orchestrator/pkg/rtcontext/rtcontext_test.go
+++ b/src/orchestrator/pkg/rtcontext/rtcontext_test.go
@@ -468,6 +468,53 @@ func TestRtcGetValue(t *testing.T) {
}
}
+func TestRtcUpdateValue(t *testing.T) {
+ var rtc = RunTimeContext{"/context/5345674458787728/"}
+ testCases := []struct {
+ label string
+ mockContextDb *MockContextDb
+ key interface{}
+ value interface{}
+ expectedError string
+ }{
+ {
+ label: "Not valid input handle case",
+ mockContextDb: &MockContextDb{},
+ key: "/context/3528435435454354/",
+ value: "{apporder: [app1, app2, app3]}",
+ expectedError: "Not a valid run time context handle",
+ },
+ {
+ label: "Contextdb call returns error case",
+ mockContextDb: &MockContextDb{Err: pkgerrors.Errorf("Key does not exist")},
+ key: "/context/5345674458787728/",
+ value: "{apporder: [app1, app2, app3]}",
+ expectedError: "Error updating run time context value:",
+ },
+ {
+ label: "Success case",
+ mockContextDb: &MockContextDb{},
+ key: "/context/5345674458787728/",
+ value: "{apporder: [app2, app3, app1]}",
+ },
+ }
+
+ for _, testCase := range testCases {
+ t.Run(testCase.label, func(t *testing.T) {
+ contextdb.Db = testCase.mockContextDb
+ if testCase.label == "Success case" {
+ contextdb.Db.Put("/context/5345674458787728/", "5345674458787728")
+ }
+ err := rtc.RtcUpdateValue(testCase.key, testCase.value)
+ if err != nil {
+ if !strings.Contains(string(err.Error()), testCase.expectedError) {
+ t.Fatalf("Method returned an error (%s)", err)
+ }
+ }
+ })
+ }
+}
+
func TestRtcDeletePair(t *testing.T) {
var rtc = RunTimeContext{"/context/5345674458787728/"}
testCases := []struct {