Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Merge requests
!308
Improve test coverage of rbac stuff
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Improve test coverage of rbac stuff
207-improve-test-coverage-of-rbac-stuff
into
develop
Overview
7
Commits
15
Pipelines
18
Changes
2
Merged
Ghost User
requested to merge
207-improve-test-coverage-of-rbac-stuff
into
develop
3 years ago
Overview
3
Commits
15
Pipelines
18
Changes
2
Expand
Description
Trying to improve coverage. 🥴
Related Issue
#207 (closed)
Edited
3 years ago
by
Ghost User
0
0
Merge request reports
Viewing commit
b74931d0
Show latest version
2 files
+
96
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
b74931d0
added test for api/login
· b74931d0
Fabian Seidl
authored
3 years ago
controller/api/auth_test.go
0 → 100644
+
88
−
0
Options
package
api
import
(
"context"
"reflect"
"testing"
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
TestLogin
(
t
*
testing
.
T
)
{
type
args
struct
{
ctx
context
.
Context
addr
string
username
string
pwd
string
}
tests
:=
[]
struct
{
name
string
args
args
want
*
apb
.
LoginResponse
wantErr
bool
}{
{
name
:
"default"
,
args
:
args
{
ctx
:
context
.
TODO
(),
addr
:
testAPIEndpoint
,
username
:
"admin"
,
pwd
:
"admin"
,
},
want
:
&
apb
.
LoginResponse
{
Status
:
apb
.
Status_STATUS_OK
,
},
wantErr
:
false
,
},
}
err
:=
userService
.
Add
(
&
rbac
.
User
{
UserID
:
uuid
.
New
(),
UserName
:
"admin"
,
Roles
:
map
[
string
]
string
{
pndID
:
"admin"
},
Password
:
"admin"
})
if
err
!=
nil
{
t
.
Errorf
(
"Login() error = %v"
,
err
)
return
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
got
,
err
:=
Login
(
tt
.
args
.
ctx
,
tt
.
args
.
addr
,
tt
.
args
.
username
,
tt
.
args
.
pwd
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"Login() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
got
.
Status
!=
apb
.
Status_STATUS_OK
||
got
.
Token
==
""
{
t
.
Errorf
(
"Login() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
}
func
TestLogout
(
t
*
testing
.
T
)
{
type
args
struct
{
ctx
context
.
Context
addr
string
username
string
}
tests
:=
[]
struct
{
name
string
args
args
want
*
apb
.
LogoutResponse
wantErr
bool
}{
// TODO: Add test cases.
// Not implemented yet!
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
got
,
err
:=
Logout
(
tt
.
args
.
ctx
,
tt
.
args
.
addr
,
tt
.
args
.
username
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"Logout() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"Logout() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
}
Loading