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
!343
Add basic application framework and example application to show interaction between events an NBI
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add basic application framework and example application to show interaction between events an NBI
istaester/init-application-framework
into
develop
Overview
16
Commits
225
Pipelines
57
Changes
1
Merged
Ghost User
requested to merge
istaester/init-application-framework
into
develop
2 years ago
Overview
16
Commits
225
Pipelines
57
Changes
1
Expand
Depends on:
!340 (merged)
!344 (merged)
!349 (merged)
!342 (merged)
Edited
2 years ago
by
Ghost User
0
0
Merge request reports
Viewing commit
f0f71bad
Show latest version
1 file
+
321
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
f0f71bad
Add tests for port service
· f0f71bad
André Sterba
authored
2 years ago
controller/topology/ports/portService_test.go
0 → 100644
+
321
−
0
Options
package
ports
import
(
"reflect"
"testing"
"code.fbi.h-da.de/danet/gosdn/controller/topology/store"
"github.com/google/uuid"
)
func
getTestPort
()
Port
{
return
Port
{
ID
:
uuid
.
MustParse
(
"44fb4aa4-c53c-4cf9-a081-5aabc61c7610"
),
Name
:
"Test-Port"
,
}
}
func
getEmptyPort
()
Port
{
return
Port
{
ID
:
uuid
.
Nil
,
Name
:
""
,
}
}
func
getTestStoreWithPorts
(
t
*
testing
.
T
,
ports
[]
Port
)
Store
{
store
:=
store
.
NewGenericStore
[
Port
]()
for
_
,
port
:=
range
ports
{
err
:=
store
.
Add
(
port
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to prepare test store while adding port: %v"
,
err
)
}
}
return
store
}
func
TestNewPortService
(
t
*
testing
.
T
)
{
type
args
struct
{
store
Store
}
tests
:=
[]
struct
{
name
string
args
args
want
Service
}{
{
name
:
"should create a new port service"
,
args
:
args
{
store
:
getTestStoreWithPorts
(
t
,
[]
Port
{}),
},
want
:
NewPortService
(
getTestStoreWithPorts
(
t
,
[]
Port
{})),
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
got
:=
NewPortService
(
tt
.
args
.
store
);
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"NewPortService() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
}
func
TestPortService_EnsureExists
(
t
*
testing
.
T
)
{
type
fields
struct
{
store
Store
}
type
args
struct
{
port
Port
}
tests
:=
[]
struct
{
name
string
fields
fields
args
args
want
Port
wantErr
bool
}{
// {
// name: "should add not existing port",
// fields: fields{
// store: store.NewGenericStore[Port](),
// },
// args: args{
// port: Port{
// ID: uuid.Nil,
// Name: "Test-Port",
// },
// },
// want: Port{
// Name: "Test-Port",
// },
// wantErr: false,
// },
{
name
:
"should error if port with uuid is not in store"
,
fields
:
fields
{
store
:
store
.
NewGenericStore
[
Port
](),
},
args
:
args
{
port
:
getTestPort
(),
},
want
:
getEmptyPort
(),
wantErr
:
true
,
},
{
name
:
"should return port that is in the store"
,
fields
:
fields
{
store
:
getTestStoreWithPorts
(
t
,
[]
Port
{
getTestPort
()}),
},
args
:
args
{
port
:
getTestPort
(),
},
want
:
getTestPort
(),
wantErr
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
p
:=
&
PortService
{
store
:
tt
.
fields
.
store
,
}
got
,
err
:=
p
.
EnsureExists
(
tt
.
args
.
port
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"PortService.EnsureExists() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"PortService.EnsureExists() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
}
func
TestPortService_Update
(
t
*
testing
.
T
)
{
type
fields
struct
{
store
Store
}
type
args
struct
{
port
Port
}
tests
:=
[]
struct
{
name
string
fields
fields
args
args
want
Port
wantErr
bool
}{
{
name
:
"should update an existing port"
,
fields
:
fields
{
store
:
store
.
NewGenericStore
[
Port
](),
},
args
:
args
{
port
:
getTestPort
(),
},
want
:
getTestPort
(),
wantErr
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
p
:=
&
PortService
{
store
:
tt
.
fields
.
store
,
}
if
err
:=
p
.
Update
(
tt
.
args
.
port
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"PortService.Update() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
updatedPort
,
err
:=
p
.
Get
(
store
.
Query
(
tt
.
args
.
port
))
if
err
!=
nil
{
t
.
Errorf
(
"PortService.Get() failed %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
updatedPort
,
tt
.
want
)
{
t
.
Errorf
(
"Got updated port = %v, want %v"
,
updatedPort
,
tt
.
want
)
}
})
}
}
func
TestPortService_Delete
(
t
*
testing
.
T
)
{
type
fields
struct
{
store
Store
}
type
args
struct
{
port
Port
}
tests
:=
[]
struct
{
name
string
fields
fields
args
args
wantErr
bool
}{
{
name
:
"should delete an existing port"
,
fields
:
fields
{
store
:
store
.
NewGenericStore
[
Port
](),
},
args
:
args
{
port
:
getTestPort
(),
},
wantErr
:
false
,
},
{
name
:
"should fail if a port does not exists"
,
fields
:
fields
{
store
:
store
.
NewGenericStore
[
Port
](),
},
args
:
args
{
port
:
getTestPort
(),
},
wantErr
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
p
:=
&
PortService
{
store
:
tt
.
fields
.
store
,
}
if
err
:=
p
.
Delete
(
tt
.
args
.
port
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"PortService.Delete() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
})
}
}
func
TestPortService_Get
(
t
*
testing
.
T
)
{
type
fields
struct
{
store
Store
}
type
args
struct
{
query
store
.
Query
}
tests
:=
[]
struct
{
name
string
fields
fields
args
args
want
Port
wantErr
bool
}{
{
name
:
"should error if port with uuid is not in store"
,
fields
:
fields
{
store
:
store
.
NewGenericStore
[
Port
](),
},
args
:
args
{
query
:
store
.
Query
{
ID
:
getTestPort
()
.
ID
,
Name
:
getTestPort
()
.
Name
,
},
},
want
:
getEmptyPort
(),
wantErr
:
true
,
},
{
name
:
"should return port that is in the store"
,
fields
:
fields
{
store
:
getTestStoreWithPorts
(
t
,
[]
Port
{
getTestPort
()}),
},
args
:
args
{
query
:
store
.
Query
{
ID
:
getTestPort
()
.
ID
,
Name
:
getTestPort
()
.
Name
,
},
},
want
:
getTestPort
(),
wantErr
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
p
:=
&
PortService
{
store
:
tt
.
fields
.
store
,
}
got
,
err
:=
p
.
Get
(
tt
.
args
.
query
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"PortService.Get() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"PortService.Get() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
}
func
TestPortService_GetAll
(
t
*
testing
.
T
)
{
type
fields
struct
{
store
Store
}
tests
:=
[]
struct
{
name
string
fields
fields
want
[]
Port
wantErr
bool
}{
{
name
:
"should fail if a port does not exists"
,
fields
:
fields
{
store
:
getTestStoreWithPorts
(
t
,
[]
Port
{
getTestPort
()}),
},
want
:
[]
Port
{
getTestPort
()},
wantErr
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
p
:=
&
PortService
{
store
:
tt
.
fields
.
store
,
}
got
,
err
:=
p
.
GetAll
()
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"PortService.GetAll() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"PortService.GetAll() = %v, want %v"
,
got
,
tt
.
want
)
}
})
}
}
Loading