diff --git a/cli/get.go b/cli/get.go index f2b2e6e80aff4e1e8a53b2d61e2d339524df0bdd..ccd8b25a464dab88bb3e9b57ce921524de2f16b7 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 98de27882a8ca6cb6100c2c72d402c8d2a7de897..22794854fc682666c4755c9a591d43ae3519cb3d 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 46a709e6d1d87e7497942ab3a902ccdac029c1bb..e2d42d80cd7697fef0d59c24615cc696d8e9f266 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 5439f2cbadb55fb5f832d99a95ac6cb51ebc2578..1281d8da401866f9a08e52a137b1d13d8c3d9e25 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 362358f37162438a5e120e9623a3d4937e2dc651..d2515b470190b920cc2516e138ca675063824bb6 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 877a0ea6a211e28a5c3a7737ca88d2eef55c9eb8..8f15887f928d538ad5f8631dc5e9c9e0a306ec41 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 57b94ade9e5bafc855c7dc285408565079df5b6f..dc2df371c62f1392cbab26516b4d47662152c087 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 9da520a2466c57f5442cc7fc63a056db3a567654..35ce78254d7ddd76f322f136988c460c913d9128 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 06a1864a62104b42c8d67f84ef2b5704ab0212ba..e551b4472352413e8af3cadb6dcabcef7ba9a3e5 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()) }