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
!138
Develop
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Develop
develop
into
master
Overview
0
Commits
196
Pipelines
446
Changes
1
Closed
Ghost User
requested to merge
develop
into
master
4 years ago
Overview
0
Commits
196
Pipelines
446
Changes
1
Expand
0
0
Merge request reports
Viewing commit
5e53f43f
Show latest version
1 file
+
1
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
5e53f43f
change test endpoint default
· 5e53f43f
Manuel Kieweg
authored
4 years ago
test/integration/cmdIntegration_test.go deleted
100644 → 0
+
0
−
180
Options
package
integration
import
(
"code.fbi.h-da.de/cocsn/gosdn/cli"
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
guuid
"github.com/google/uuid"
gpb
"github.com/openconfig/gnmi/proto/gnmi"
log
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
pb
"google.golang.org/protobuf/proto"
"os"
"testing"
)
const
unreachable
=
"203.0.113.10:6030"
var
testAddress
=
"141.100.67.238:6030"
var
testAPIEndpoint
=
"http://gosdn-latest.apps.ocp.fbi.h-da.de/api"
var
testUsername
=
"admin"
var
testPassword
=
"arista"
var
defaultPath
=
[]
string
{
"/system/config/hostname"
}
var
opt
*
nucleus
.
GnmiTransportOptions
func
TestMain
(
m
*
testing
.
M
)
{
testSetupIntegration
()
os
.
Exit
(
m
.
Run
())
}
func
testSetupIntegration
()
{
if
os
.
Getenv
(
"GOSDN_LOG"
)
==
"nolog"
{
log
.
SetLevel
(
log
.
PanicLevel
)
}
a
:=
os
.
Getenv
(
"GOSDN_TEST_ENDPOINT"
)
if
a
!=
""
{
testAddress
=
a
log
.
Infof
(
"GOSDN_TEST_ENDPOINT set to %v"
,
testAddress
)
}
api
:=
os
.
Getenv
(
"GOSDN_TEST_API_ENDPOINT"
)
if
api
!=
""
{
testAPIEndpoint
=
api
log
.
Infof
(
"GOSDN_TEST_API_ENDPOINT set to %v"
,
testAPIEndpoint
)
}
u
:=
os
.
Getenv
(
"GOSDN_TEST_USER"
)
if
u
!=
""
{
testUsername
=
u
log
.
Infof
(
"GOSDN_TEST_USER set to %v"
,
testUsername
)
}
p
:=
os
.
Getenv
(
"GOSDN_TEST_PASSWORD"
)
if
p
!=
""
{
testPassword
=
p
log
.
Infof
(
"GOSDN_TEST_PASSWORD set to %v"
,
testPassword
)
}
gnmiMessages
=
map
[
string
]
pb
.
Message
{
"../proto/cap-resp-arista-ceos"
:
&
gpb
.
CapabilityResponse
{},
"../proto/req-full-node"
:
&
gpb
.
GetRequest
{},
"../proto/req-full-node-arista-ceos"
:
&
gpb
.
GetRequest
{},
"../proto/req-interfaces-arista-ceos"
:
&
gpb
.
GetRequest
{},
"../proto/req-interfaces-interface-arista-ceos"
:
&
gpb
.
GetRequest
{},
"../proto/req-interfaces-wildcard"
:
&
gpb
.
GetRequest
{},
"../proto/resp-full-node"
:
&
gpb
.
GetResponse
{},
"../proto/resp-full-node-arista-ceos"
:
&
gpb
.
GetResponse
{},
"../proto/resp-interfaces-arista-ceos"
:
&
gpb
.
GetResponse
{},
"../proto/resp-interfaces-interface-arista-ceos"
:
&
gpb
.
GetResponse
{},
"../proto/resp-interfaces-wildcard"
:
&
gpb
.
GetResponse
{},
"../proto/resp-set-system-config-hostname"
:
&
gpb
.
SetResponse
{},
}
for
k
,
v
:=
range
gnmiMessages
{
if
err
:=
proto
.
Read
(
k
,
v
);
err
!=
nil
{
log
.
Fatalf
(
"error parsing %v: %v"
,
k
,
err
)
}
}
opt
=
&
nucleus
.
GnmiTransportOptions
{
Config
:
gnmi
.
Config
{
Addr
:
testAddress
,
Username
:
testUsername
,
Password
:
testPassword
,
Encoding
:
gpb
.
Encoding_JSON_IETF
,
},
RespChan
:
make
(
chan
*
gpb
.
SubscribeResponse
),
}
}
func
TestCliIntegration
(
t
*
testing
.
T
)
{
if
testing
.
Short
()
{
t
.
Skip
(
"skipping integration test"
)
}
tests
:=
[]
struct
{
name
string
wantErr
bool
}{
{
name
:
"default"
,
wantErr
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
defer
viper
.
Reset
()
if
err
:=
cli
.
HTTPGet
(
testAPIEndpoint
,
"init"
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
switch
err
.
(
type
)
{
case
viper
.
ConfigFileNotFoundError
:
default
:
t
.
Errorf
(
"gosdn cli init error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
}
cliPnd
:=
viper
.
GetString
(
"CLI_PND"
)
cliSbi
:=
viper
.
GetString
(
"CLI_SBI"
)
if
err
:=
cli
.
HTTPGet
(
testAPIEndpoint
,
"addDevice"
,
"address="
+
testAddress
,
"password="
+
testPassword
,
"username="
+
testUsername
,
"sbi="
+
cliSbi
,
"pnd="
+
cliPnd
,
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"gosdn cli add-device error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
did
:=
viper
.
GetString
(
"LAST_DEVICE_UUID"
)
if
err
:=
cli
.
HTTPGet
(
testAPIEndpoint
,
"request"
,
"uuid="
+
did
,
"sbi="
+
cliSbi
,
"pnd="
+
cliPnd
,
"path=/system/config/hostname"
,
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"gosdn cli request error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
err
:=
cli
.
HTTPGet
(
testAPIEndpoint
,
"getDevice"
,
"address="
+
testAddress
,
"uuid="
+
did
,
"sbi="
+
cliSbi
,
"pnd="
+
cliPnd
,
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"gosdn cli get-device error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
hostname
:=
guuid
.
New
()
.
String
()
if
err
:=
cli
.
HTTPGet
(
testAPIEndpoint
,
"set"
,
"address="
+
testAddress
,
"uuid="
+
did
,
"sbi="
+
cliSbi
,
"pnd="
+
cliPnd
,
"path=/system/config/hostname"
,
"value="
+
hostname
,
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"gosdn cli set error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
resp
,
err
:=
cli
.
Get
(
testAddress
,
testUsername
,
testPassword
,
"/system/config/hostname"
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"cli.Get() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
got
:=
resp
.
Notification
[
0
]
.
Update
[
0
]
.
Val
.
GetStringVal
()
if
got
!=
hostname
{
t
.
Errorf
(
"integration test failed = got: %v, want: %v"
,
got
,
hostname
)
}
})
}
}
Loading