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
......@@ -28,10 +28,11 @@ type User struct {
userService rbacInterfaces.UserService
}
// NewUserServer receives a JWTManager and returns a new UserServer.
func NewUserServer(jwtManager *rbac.JWTManager) *User {
// NewUserServer receives a JWTManager and a UserService and returns a new UserServer.
func NewUserServer(jwtManager *rbac.JWTManager, userService rbacInterfaces.UserService) *User {
return &User{
jwtManager: jwtManager,
jwtManager: jwtManager,
userService: userService,
}
}
......
......@@ -4,11 +4,31 @@ import (
"context"
"reflect"
"testing"
"time"
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"
)
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) {
type args struct {
ctx context.Context
......@@ -41,9 +61,7 @@ func TestUser_CreateUsers(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := User{
jwtManager: jwt,
}
s := getTestUserServer(t)
got, err := s.CreateUsers(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr {
t.Errorf("User.CreateUsers() error = %v, wantErr %v", err, tt.wantErr)
......@@ -96,7 +114,7 @@ func TestUser_GetUser(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := User{}
s := getTestUserServer(t)
got, err := s.GetUser(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr {
t.Errorf("User.GetUser() error = %v, wantErr %v", err, tt.wantErr)
......@@ -117,10 +135,6 @@ func TestUser_GetUser(t *testing.T) {
}
func TestUser_GetUsers(t *testing.T) {
err := clearAndCreateAuthTestSetup()
if err != nil {
t.Fatalf("%v", err)
}
type args struct {
ctx context.Context
request *apb.GetUsersRequest
......@@ -150,7 +164,8 @@ func TestUser_GetUsers(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := User{}
s := getTestUserServer(t)
got, err := s.GetUsers(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr {
t.Errorf("User.GetUsers() error = %v, wantErr %v", err, tt.wantErr)
......@@ -220,7 +235,7 @@ func TestUser_UpdateUsers(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := User{}
s := getTestUserServer(t)
got, err := s.UpdateUsers(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr {
t.Errorf("User.UpdateUsers() error = %v, wantErr %v", err, tt.wantErr)
......@@ -264,7 +279,7 @@ func TestUser_DeleteUsers(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := User{}
s := getTestUserServer(t)
got, err := s.DeleteUsers(tt.args.ctx, tt.args.request)
if (err != nil) != 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