Skip to content
Snippets Groups Projects
Commit 33cb2c39 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

lint lint

parent 72939fb8
No related branches found
No related tags found
2 merge requests!120Resolve "Code Quality",!90Develop
Pipeline #67280 failed
......@@ -9,7 +9,7 @@ import (
)
// Get sends a gNMI Get request to the specified target and prints the response to stdout
func Get(a, u, p string, args ...string) (*gpb.GetResponse,error) {
func Get(a, u, p string, args ...string) (*gpb.GetResponse, error) {
sbi := &nucleus.OpenConfig{}
opts := &nucleus.GnmiTransportOptions{
Config: gnmi.Config{
......@@ -22,7 +22,7 @@ func Get(a, u, p string, args ...string) (*gpb.GetResponse,error) {
}
t, err := nucleus.NewGnmiTransport(opts)
if err != nil {
return nil,err
return nil, err
}
resp, err := t.Get(context.Background(), args...)
if err != nil {
......
......@@ -7,20 +7,20 @@ import (
const unreachable = "203.0.113.10:6030"
var address = "141.100.70.171:6030"
var apiEndpoint = "http://141.100.70.171:8080"
var username = "admin"
var password = "arista"
var testAddress = "141.100.70.171:6030"
var testAPIEndpoint = "http://141.100.70.171:8080"
var testUsername = "admin"
var testPassword = "arista"
var defaultPath = []string{"/system/config/hostname"}
func testSetupIntegration() {
a := os.Getenv("GOSDN_TEST_ENDPOINT")
if a != "" {
address = a
testAddress = a
}
api := os.Getenv("GOSDN_TEST_API_ENDPOINT")
if api != "" {
apiEndpoint = api
testAPIEndpoint = api
}
}
......@@ -46,9 +46,9 @@ func TestCapabilities(t *testing.T) {
{
name: "default",
args: args{
a: address,
u: username,
p: password,
a: testAddress,
u: testUsername,
p: testPassword,
},
wantErr: false,
},
......@@ -56,8 +56,8 @@ func TestCapabilities(t *testing.T) {
name: "destination unreachable",
args: args{
a: unreachable,
u: username,
p: password,
u: testUsername,
p: testPassword,
},
wantErr: true,
},
......@@ -89,9 +89,9 @@ func TestGet(t *testing.T) {
{
name: "default",
args: args{
a: address,
u: username,
p: password,
a: testAddress,
u: testUsername,
p: testPassword,
args: defaultPath,
},
wantErr: false,
......@@ -100,8 +100,8 @@ func TestGet(t *testing.T) {
name: "destination unreachable",
args: args{
a: unreachable,
u: username,
p: password,
u: testUsername,
p: testPassword,
args: defaultPath,
},
wantErr: true,
......@@ -109,7 +109,7 @@ func TestGet(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if _,err := Get(tt.args.a, tt.args.u, tt.args.p, tt.args.args...); (err != nil) != tt.wantErr {
if _, err := Get(tt.args.a, tt.args.u, tt.args.p, tt.args.args...); (err != nil) != tt.wantErr {
t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr)
}
})
......@@ -133,7 +133,7 @@ func TestHttpGet(t *testing.T) {
{
name: "default",
args: args{
apiEndpoint: apiEndpoint,
apiEndpoint: testAPIEndpoint,
f: "init",
args: nil,
},
......@@ -177,9 +177,9 @@ func TestSet(t *testing.T) {
{
name: "default",
args: args{
a: address,
u: username,
p: password,
a: testAddress,
u: testUsername,
p: testPassword,
typ: "update",
args: []string{"/system/config/hostname", "ceos3000"},
},
......@@ -189,8 +189,8 @@ func TestSet(t *testing.T) {
name: "destination unreachable",
args: args{
a: unreachable,
u: username,
p: password,
u: testUsername,
p: testPassword,
typ: "update",
args: []string{"/system/config/hostname", "ceos3000"},
},
......@@ -199,9 +199,9 @@ func TestSet(t *testing.T) {
{
name: "invalid path",
args: args{
a: address,
u: username,
p: password,
a: testAddress,
u: testUsername,
p: testPassword,
typ: "update",
args: []string{"invalid/path", "ceos3000"},
},
......
......@@ -42,7 +42,7 @@ var getCmd = &cobra.Command{
Short: "get request",
Long: `Sends a gNMI Get request to the specified target and prints the response to stdout`,
RunE: func(cmd *cobra.Command, args []string) error {
_,err := cli.Get(address, username, password, args...)
_, err := cli.Get(address, username, password, args...)
return err
},
}
......
......@@ -9,7 +9,7 @@ import (
)
var testAddress = "141.100.70.171:6030"
var testApiEndpoint = "http://141.100.70.171:8080"
var testAPIEndpoint = "http://141.100.70.171:8080"
var testUsername = "admin"
var testPassword = "arista"
......@@ -20,7 +20,7 @@ func testSetupIntegration() {
}
api := os.Getenv("GOSDN_TEST_API_ENDPOINT")
if api != "" {
testApiEndpoint = api
testAPIEndpoint = api
}
u := os.Getenv("GOSDN_TEST_USER")
if u != "" {
......@@ -53,7 +53,7 @@ func TestCliIntegration(t *testing.T) {
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 {
if err := cli.HTTPGet(testAPIEndpoint, "init"); (err != nil) != tt.wantErr {
switch err.(type) {
case viper.ConfigFileNotFoundError:
default:
......@@ -65,7 +65,7 @@ func TestCliIntegration(t *testing.T) {
cliSbi = viper.GetString("CLI_SBI")
if err := cli.HTTPGet(
testApiEndpoint,
testAPIEndpoint,
"addDevice",
"address="+testAddress,
"password="+testPassword,
......@@ -79,7 +79,7 @@ func TestCliIntegration(t *testing.T) {
did := viper.GetString("LAST_DEVICE_UUID")
if err := cli.HTTPGet(
testApiEndpoint,
testAPIEndpoint,
"request",
"uuid="+did,
"sbi="+cliSbi,
......@@ -91,7 +91,7 @@ func TestCliIntegration(t *testing.T) {
}
if err := cli.HTTPGet(
testApiEndpoint,
testAPIEndpoint,
"getDevice",
"address="+testAddress,
"uuid="+did,
......@@ -104,7 +104,7 @@ func TestCliIntegration(t *testing.T) {
hostname := guuid.New().String()
if err := cli.HTTPGet(
testApiEndpoint,
testAPIEndpoint,
"set",
"address="+testAddress,
"uuid="+did,
......
......@@ -26,10 +26,10 @@ var c *Core
func init() {
c = &Core{
database: database.Database{},
pndc: pndStore{store{}},
sbic: sbiStore{store{}},
stopChan: make(chan os.Signal, 1),
database: database.Database{},
pndc: pndStore{store{}},
sbic: sbiStore{store{}},
stopChan: make(chan os.Signal, 1),
}
// Setting up signal capturing
......@@ -99,7 +99,7 @@ func Run(ctx context.Context) error {
}
}
func shutdown()error{
func shutdown() error {
log.Info("shutting down controller")
return stopHttpServer()
}
\ No newline at end of file
}
......@@ -12,9 +12,10 @@ import (
)
type CtxKeyType string
const (
CtxKeyOpts CtxKeyType = "opts"
CtxKeyConfig = "config"
CtxKeyOpts CtxKeyType = "opts"
CtxKeyConfig = "config"
)
// Gnmi implements the Transport interface and provides an SBI with the
......
......@@ -19,7 +19,7 @@ func stopHttpServer() error {
return c.httpServer.Shutdown(ctx)
}
func registerHttpHandler(){
func registerHttpHandler() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r)
......@@ -92,7 +92,7 @@ func httpHandler(writer http.ResponseWriter, request *http.Request) {
sbi, err = sbic.(*sbiStore).get(sid)
if err != nil {
log.WithFields(log.Fields{
"requested uuid": sid,
"requested uuid": sid,
"available uuids": sbic.(*sbiStore).UUIDs(),
}).Error(err)
writer.WriteHeader(http.StatusInternalServerError)
......
......@@ -10,7 +10,7 @@ import (
"testing"
)
func testSetupHttp() {
func testSetupHTTP() {
sbi = &OpenConfig{id: defaultSbiID}
sbi.Schema()
var err error
......
......@@ -67,7 +67,7 @@ func TestMain(m *testing.M) {
readTestUUIDs()
testSetupGnmi()
testSetupHttp()
testSetupHTTP()
testSetupIntegration()
os.Exit(m.Run())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment