From 424240c3cd8cd3158e22a1e4df7bd451cffa0bac Mon Sep 17 00:00:00 2001
From: Fabian Seidl <fabian.seidl@h-da.de>
Date: Wed, 25 Sep 2024 11:06:18 +0200
Subject: [PATCH] adjust tests becasue of breaking changes in update

---
 controller/northbound/server/auth_test.go     | 12 ++---
 controller/northbound/server/role_test.go     | 48 +++++++++----------
 .../northbound/server/test_util_test.go       |  4 ++
 controller/northbound/server/topology_test.go | 36 +++++++-------
 controller/northbound/server/user_test.go     | 30 ++++++------
 controller/northbound/server/utils_test.go    |  2 +-
 6 files changed, 68 insertions(+), 64 deletions(-)

diff --git a/controller/northbound/server/auth_test.go b/controller/northbound/server/auth_test.go
index 8ad8cb6de..e5c9e7389 100644
--- a/controller/northbound/server/auth_test.go
+++ b/controller/northbound/server/auth_test.go
@@ -89,9 +89,9 @@ func TestAuth_Login(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "username",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("username"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				}},
 		},
 	}
@@ -160,9 +160,9 @@ func TestAuth_Logout(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "username",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("username"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				}},
 		},
 	}
diff --git a/controller/northbound/server/role_test.go b/controller/northbound/server/role_test.go
index d2f3dc7e0..bb787a416 100644
--- a/controller/northbound/server/role_test.go
+++ b/controller/northbound/server/role_test.go
@@ -84,9 +84,9 @@ func TestRole_CreateRoles(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "roles[0].name",
-					ConstraintId: "string.min_len",
-					Message:      "value length must be at least 3 characters",
+					FieldPath:    stringToPointer("roles[0].name"),
+					ConstraintId: stringToPointer("string.min_len"),
+					Message:      stringToPointer("value length must be at least 3 characters"),
 				}},
 		},
 		{
@@ -105,9 +105,9 @@ func TestRole_CreateRoles(t *testing.T) {
 			want:    &apb.CreateRolesResponse{},
 			wantErr: true,
 			validationErrors: []*validate.Violation{{
-				FieldPath:    "roles[0].description",
-				ConstraintId: "string.min_len",
-				Message:      "value length must be at least 3 characters",
+				FieldPath:    stringToPointer("roles[0].description"),
+				ConstraintId: stringToPointer("string.min_len"),
+				Message:      stringToPointer("value length must be at least 3 characters"),
 			}},
 		},
 	}
@@ -181,9 +181,9 @@ func TestRole_GetRole(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "role_name",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("role_name"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 			},
 		},
@@ -355,9 +355,9 @@ func TestRole_UpdateRoles(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "roles[0].name",
-					ConstraintId: "string.min_len",
-					Message:      "value length must be at least 3 characters",
+					FieldPath:    stringToPointer("roles[0].name"),
+					ConstraintId: stringToPointer("string.min_len"),
+					Message:      stringToPointer("value length must be at least 3 characters"),
 				},
 			},
 		},
@@ -379,9 +379,9 @@ func TestRole_UpdateRoles(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "roles[0].description",
-					ConstraintId: "string.min_len",
-					Message:      "value length must be at least 3 characters",
+					FieldPath:    stringToPointer("roles[0].description"),
+					ConstraintId: stringToPointer("string.min_len"),
+					Message:      stringToPointer("value length must be at least 3 characters"),
 				},
 			},
 		},
@@ -456,14 +456,14 @@ func TestRole_DeletePermissionsForRole(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "role_name",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("role_name"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 				{
-					FieldPath:    "permissions_to_delete",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("permissions_to_delete"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 			},
 		},
@@ -537,9 +537,9 @@ func TestRole_DeleteRoles(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "role_name",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("role_name"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 			},
 		},
diff --git a/controller/northbound/server/test_util_test.go b/controller/northbound/server/test_util_test.go
index 82b68911e..5e843cac5 100644
--- a/controller/northbound/server/test_util_test.go
+++ b/controller/northbound/server/test_util_test.go
@@ -305,3 +305,7 @@ func initUUIDs(t *testing.T) {
 // 		_ = mneServer.mneService.Delete(mne)
 // 	}
 // }
+
+func stringToPointer(str string) *string {
+	return &str
+}
diff --git a/controller/northbound/server/topology_test.go b/controller/northbound/server/topology_test.go
index cc5a6f2ae..44ce77b57 100644
--- a/controller/northbound/server/topology_test.go
+++ b/controller/northbound/server/topology_test.go
@@ -285,29 +285,29 @@ func TestTopology_AddLink(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "link.name",
-					ConstraintId: "string.min_len",
-					Message:      "value length must be at least 1 characters",
+					FieldPath:    stringToPointer("link.name"),
+					ConstraintId: stringToPointer("string.min_len"),
+					Message:      stringToPointer("value length must be at least 1 characters"),
 				},
 				{
-					FieldPath:    "link.sourceNode",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("link.sourceNode"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 				{
-					FieldPath:    "link.targetNode",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("link.targetNode"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 				{
-					FieldPath:    "link.sourcePort",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("link.sourcePort"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 				{
-					FieldPath:    "link.targetPort",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("link.targetPort"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 			},
 		},
@@ -461,9 +461,9 @@ func TestTopology_DeleteLink(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "id",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("id"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				}},
 		},
 	}
diff --git a/controller/northbound/server/user_test.go b/controller/northbound/server/user_test.go
index 6d2058dee..4a1c66327 100644
--- a/controller/northbound/server/user_test.go
+++ b/controller/northbound/server/user_test.go
@@ -90,9 +90,9 @@ func TestUser_CreateUsers(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "user[0].password",
-					ConstraintId: "string.min_len",
-					Message:      "value length must be at least 5 characters",
+					FieldPath:    stringToPointer("user[0].password"),
+					ConstraintId: stringToPointer("string.min_len"),
+					Message:      stringToPointer("value length must be at least 5 characters"),
 				}},
 		},
 		{
@@ -116,9 +116,9 @@ func TestUser_CreateUsers(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "user[0].name",
-					ConstraintId: "string.min_len",
-					Message:      "value length must be at least 3 characters",
+					FieldPath:    stringToPointer("user[0].name"),
+					ConstraintId: stringToPointer("string.min_len"),
+					Message:      stringToPointer("value length must be at least 3 characters"),
 				}},
 		},
 	}
@@ -190,9 +190,9 @@ func TestUser_GetUser(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "name",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("name"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				}},
 		},
 	}
@@ -341,9 +341,9 @@ func TestUser_UpdateUsers(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "name",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("name"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 			},
 		},
@@ -402,9 +402,9 @@ func TestUser_DeleteUsers(t *testing.T) {
 			wantErr: true,
 			validationErrors: []*validate.Violation{
 				{
-					FieldPath:    "name",
-					ConstraintId: "required",
-					Message:      "value is required",
+					FieldPath:    stringToPointer("name"),
+					ConstraintId: stringToPointer("required"),
+					Message:      stringToPointer("value is required"),
 				},
 			},
 		},
diff --git a/controller/northbound/server/utils_test.go b/controller/northbound/server/utils_test.go
index cfd045897..d86de701b 100644
--- a/controller/northbound/server/utils_test.go
+++ b/controller/northbound/server/utils_test.go
@@ -9,7 +9,7 @@ import (
 
 func contains(array []*validate.Violation, err *validate.Violation) bool {
 	for _, v := range array {
-		if v.FieldPath == err.FieldPath && v.ConstraintId == err.ConstraintId && v.Message == err.Message {
+		if *v.FieldPath == *err.FieldPath && *v.ConstraintId == *err.ConstraintId && *v.Message == *err.Message {
 			return true
 		}
 	}
-- 
GitLab