From 33cb2c3924827a64041ff310df66862e122a639c Mon Sep 17 00:00:00 2001 From: Manuel Kieweg <manuel.kieweg@h-da.de> Date: Fri, 26 Mar 2021 17:17:54 +0000 Subject: [PATCH] lint lint --- cli/get.go | 4 +-- cli/integration_test.go | 52 +++++++++++++++++++-------------------- cmd/get.go | 2 +- cmd/integration_test.go | 14 +++++------ nucleus/controller.go | 12 ++++----- nucleus/gnmi_transport.go | 5 ++-- nucleus/http.go | 4 +-- nucleus/http_test.go | 2 +- nucleus/inizalize_test.go | 2 +- 9 files changed, 49 insertions(+), 48 deletions(-) diff --git a/cli/get.go b/cli/get.go index f2b2e6e80..ccd8b25a4 100644 --- a/cli/get.go +++ b/cli/get.go @@ -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 { diff --git a/cli/integration_test.go b/cli/integration_test.go index 98de27882..22794854f 100644 --- a/cli/integration_test.go +++ b/cli/integration_test.go @@ -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"}, }, diff --git a/cmd/get.go b/cmd/get.go index 46a709e6d..e2d42d80c 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -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 }, } diff --git a/cmd/integration_test.go b/cmd/integration_test.go index 5439f2cba..1281d8da4 100644 --- a/cmd/integration_test.go +++ b/cmd/integration_test.go @@ -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, diff --git a/nucleus/controller.go b/nucleus/controller.go index 362358f37..d2515b470 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -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 +} diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go index 877a0ea6a..8f15887f9 100644 --- a/nucleus/gnmi_transport.go +++ b/nucleus/gnmi_transport.go @@ -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 diff --git a/nucleus/http.go b/nucleus/http.go index 57b94ade9..dc2df371c 100644 --- a/nucleus/http.go +++ b/nucleus/http.go @@ -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) diff --git a/nucleus/http_test.go b/nucleus/http_test.go index 9da520a24..35ce78254 100644 --- a/nucleus/http_test.go +++ b/nucleus/http_test.go @@ -10,7 +10,7 @@ import ( "testing" ) -func testSetupHttp() { +func testSetupHTTP() { sbi = &OpenConfig{id: defaultSbiID} sbi.Schema() var err error diff --git a/nucleus/inizalize_test.go b/nucleus/inizalize_test.go index 06a1864a6..e551b4472 100644 --- a/nucleus/inizalize_test.go +++ b/nucleus/inizalize_test.go @@ -67,7 +67,7 @@ func TestMain(m *testing.M) { readTestUUIDs() testSetupGnmi() - testSetupHttp() + testSetupHTTP() testSetupIntegration() os.Exit(m.Run()) } -- GitLab