From f316d84267fc7d5863c38e1dc904cd233682e3ca Mon Sep 17 00:00:00 2001
From: Manuel Kieweg <manuel.kieweg@h-da.de>
Date: Thu, 29 Apr 2021 17:50:30 +0200
Subject: [PATCH] more error handling

---
 nucleus/gnmi_transport.go                   |  5 +++++
 test/integration/cmdIntegration_test.go     |  2 +-
 test/integration/nucleusIntegration_test.go | 11 ++++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go
index 870af9eae..58ecadda3 100644
--- a/nucleus/gnmi_transport.go
+++ b/nucleus/gnmi_transport.go
@@ -113,6 +113,11 @@ func (g *Gnmi) Set(ctx context.Context, args ...interface{}) error {
 				v: o,
 				t: reflect.TypeOf("placeholder"),
 			}
+		} else if attrs == nil || len(attrs) == 0 {
+			return &ErrInvalidParameters{
+				f: "gnmi.Set()",
+				r: "no parameters provided",
+			}
 		}
 		opts = append(opts, &gnmi.Operation{
 			// Hardcoded TransportUpdate until multiple operations are supported
diff --git a/test/integration/cmdIntegration_test.go b/test/integration/cmdIntegration_test.go
index 65b3670d4..03048c8ea 100644
--- a/test/integration/cmdIntegration_test.go
+++ b/test/integration/cmdIntegration_test.go
@@ -85,7 +85,7 @@ func testSetupIntegration() {
 	}
 }
 
-func TestCliIntegration(t *testing.T) {
+func TestCmdIntegration(t *testing.T) {
 	if testing.Short() {
 		t.Skip("skipping integration test")
 	}
diff --git a/test/integration/nucleusIntegration_test.go b/test/integration/nucleusIntegration_test.go
index 54f310491..ed6d78fd9 100644
--- a/test/integration/nucleusIntegration_test.go
+++ b/test/integration/nucleusIntegration_test.go
@@ -41,7 +41,7 @@ func TestGnmi_SetIntegration(t *testing.T) {
 			},
 			args: args{
 				ctx:    context.Background(),
-				params: []string{},
+				params: []string{"/system/config/hostname", "ceos3000"},
 			},
 			wantErr: true,
 		},
@@ -54,6 +54,15 @@ func TestGnmi_SetIntegration(t *testing.T) {
 			},
 			wantErr: false,
 		},
+		{
+			name:   "invalid update",
+			fields: fields{opt: opt},
+			args: args{
+				ctx:    context.Background(),
+				params: nil,
+			},
+			wantErr: true,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-- 
GitLab