Skip to content
Snippets Groups Projects
Commit 202be968 authored by André Sterba's avatar André Sterba
Browse files

Adjust user and tests

parent 3bb4d35c
Branches
No related tags found
6 merge requests!376Add additional example application hostname-checker,!349Northbound refactoring to implement NIB concept for devices,!343Add basic application framework and example application to show interaction between events an NBI,!339Create basic venv-manager for use with arista,!327Remove NBI package global services and refactor NBI servers,!324Provide prototype implementation for topology handling
This commit is part of merge request !343. Comments created here will be created in the context of that merge request.
...@@ -28,10 +28,11 @@ type User struct { ...@@ -28,10 +28,11 @@ type User struct {
userService rbacInterfaces.UserService userService rbacInterfaces.UserService
} }
// NewUserServer receives a JWTManager and returns a new UserServer. // NewUserServer receives a JWTManager and a UserService and returns a new UserServer.
func NewUserServer(jwtManager *rbac.JWTManager) *User { func NewUserServer(jwtManager *rbac.JWTManager, userService rbacInterfaces.UserService) *User {
return &User{ return &User{
jwtManager: jwtManager, jwtManager: jwtManager,
userService: userService,
} }
} }
......
...@@ -4,11 +4,31 @@ import ( ...@@ -4,11 +4,31 @@ import (
"context" "context"
"reflect" "reflect"
"testing" "testing"
"time"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
"code.fbi.h-da.de/danet/gosdn/controller/rbac"
"github.com/google/uuid" "github.com/google/uuid"
) )
func getTestUserServer(t *testing.T) *User {
jwtManager := rbac.NewJWTManager("test", time.Second)
userStore := rbac.NewMemoryUserStore()
userService := rbac.NewUserService(userStore)
roleStore := rbac.NewMemoryRoleStore()
roleService := rbac.NewRoleService(roleStore)
s := NewUserServer(jwtManager, userService)
err := clearAndCreateAuthTestSetup(s.userService, roleService)
if err != nil {
t.Fatalf("%v", err)
}
return s
}
func TestUser_CreateUsers(t *testing.T) { func TestUser_CreateUsers(t *testing.T) {
type args struct { type args struct {
ctx context.Context ctx context.Context
...@@ -41,9 +61,7 @@ func TestUser_CreateUsers(t *testing.T) { ...@@ -41,9 +61,7 @@ func TestUser_CreateUsers(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := User{ s := getTestUserServer(t)
jwtManager: jwt,
}
got, err := s.CreateUsers(tt.args.ctx, tt.args.request) got, err := s.CreateUsers(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("User.CreateUsers() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("User.CreateUsers() error = %v, wantErr %v", err, tt.wantErr)
...@@ -96,7 +114,7 @@ func TestUser_GetUser(t *testing.T) { ...@@ -96,7 +114,7 @@ func TestUser_GetUser(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := User{} s := getTestUserServer(t)
got, err := s.GetUser(tt.args.ctx, tt.args.request) got, err := s.GetUser(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("User.GetUser() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("User.GetUser() error = %v, wantErr %v", err, tt.wantErr)
...@@ -117,10 +135,6 @@ func TestUser_GetUser(t *testing.T) { ...@@ -117,10 +135,6 @@ func TestUser_GetUser(t *testing.T) {
} }
func TestUser_GetUsers(t *testing.T) { func TestUser_GetUsers(t *testing.T) {
err := clearAndCreateAuthTestSetup()
if err != nil {
t.Fatalf("%v", err)
}
type args struct { type args struct {
ctx context.Context ctx context.Context
request *apb.GetUsersRequest request *apb.GetUsersRequest
...@@ -150,7 +164,8 @@ func TestUser_GetUsers(t *testing.T) { ...@@ -150,7 +164,8 @@ func TestUser_GetUsers(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := User{} s := getTestUserServer(t)
got, err := s.GetUsers(tt.args.ctx, tt.args.request) got, err := s.GetUsers(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("User.GetUsers() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("User.GetUsers() error = %v, wantErr %v", err, tt.wantErr)
...@@ -220,7 +235,7 @@ func TestUser_UpdateUsers(t *testing.T) { ...@@ -220,7 +235,7 @@ func TestUser_UpdateUsers(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := User{} s := getTestUserServer(t)
got, err := s.UpdateUsers(tt.args.ctx, tt.args.request) got, err := s.UpdateUsers(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("User.UpdateUsers() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("User.UpdateUsers() error = %v, wantErr %v", err, tt.wantErr)
...@@ -264,7 +279,7 @@ func TestUser_DeleteUsers(t *testing.T) { ...@@ -264,7 +279,7 @@ func TestUser_DeleteUsers(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := User{} s := getTestUserServer(t)
got, err := s.DeleteUsers(tt.args.ctx, tt.args.request) got, err := s.DeleteUsers(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("User.DeleteUsers() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("User.DeleteUsers() error = %v, wantErr %v", err, tt.wantErr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment