diff --git a/cli/capabilities.go b/cli/capabilities.go index a972822b1ab086bd3f7ed0c81104c07a861fc526..a80540d873fd52dc582ee6ec124649f64e9ad6b5 100644 --- a/cli/capabilities.go +++ b/cli/capabilities.go @@ -11,7 +11,7 @@ import ( // Capabilities sends a gNMI Capabilities request to the specified target // and prints the supported models to stdout -func Capabilities(a, u , p string) error { +func Capabilities(a, u, p string) error { cfg := gnmi.Config{ Addr: a, Username: u, diff --git a/cli/cli_test.go b/cli/cli_test.go deleted file mode 100644 index df6c6ec4d09668c3cf7996599a03bf129441ccf4..0000000000000000000000000000000000000000 --- a/cli/cli_test.go +++ /dev/null @@ -1,259 +0,0 @@ -package cli - -import ( - "code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi" - "context" - gpb "github.com/openconfig/gnmi/proto/gnmi" - "github.com/openconfig/ygot/ygot" - "reflect" - "testing" -) - -func TestCapabilities(t *testing.T) { - type args struct { - a string - u string - p string - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := Capabilities(tt.args.a, tt.args.u, tt.args.p); (err != nil) != tt.wantErr { - t.Errorf("Capabilities() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestGet(t *testing.T) { - type args struct { - a string - u string - p string - args []string - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - 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 { - t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestHttpGet(t *testing.T) { - type args struct { - apiEndpoint string - f string - args []string - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := HttpGet(tt.args.apiEndpoint, tt.args.f, tt.args.args...); (err != nil) != tt.wantErr { - t.Errorf("HttpGet() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestLeafPaths(t *testing.T) { - tests := []struct { - name string - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := LeafPaths(); (err != nil) != tt.wantErr { - t.Errorf("LeafPaths() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestPathTraversal(t *testing.T) { - tests := []struct { - name string - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := PathTraversal(); (err != nil) != tt.wantErr { - t.Errorf("PathTraversal() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestSet(t *testing.T) { - type args struct { - a string - u string - p string - typ string - args []string - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := Set(tt.args.a, tt.args.u, tt.args.p, tt.args.typ, tt.args.args...); (err != nil) != tt.wantErr { - t.Errorf("Set() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestSubscribe(t *testing.T) { - type args struct { - a string - u string - p string - sample int64 - heartbeat int64 - args []string - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := Subscribe(tt.args.a, tt.args.u, tt.args.p, tt.args.sample, tt.args.heartbeat, tt.args.args...); (err != nil) != tt.wantErr { - t.Errorf("Subscribe() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestTarget(t *testing.T) { - type args struct { - bindAddr string - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := Target(tt.args.bindAddr); (err != nil) != tt.wantErr { - t.Errorf("Target() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func Test_callback(t *testing.T) { - type args struct { - newConfig ygot.ValidatedGoStruct - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := callback(tt.args.newConfig); (err != nil) != tt.wantErr { - t.Errorf("callback() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func Test_newServer(t *testing.T) { - type args struct { - model *gnmi.Model - config []byte - } - tests := []struct { - name string - args args - want *server - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := newServer(tt.args.model, tt.args.config) - if (err != nil) != tt.wantErr { - t.Errorf("newServer() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("newServer() got = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_server_Get(t *testing.T) { - type fields struct { - Server *gnmi.Server - } - type args struct { - ctx context.Context - req *gpb.GetRequest - } - tests := []struct { - name string - fields fields - args args - want *gpb.GetResponse - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s := &server{ - Server: tt.fields.Server, - } - got, err := s.Get(tt.args.ctx, tt.args.req) - if (err != nil) != tt.wantErr { - t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Get() got = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/cli/get.go b/cli/get.go index a0984961c5acd325f8bdefb010ee62c3c224ca41..f2b2e6e80aff4e1e8a53b2d61e2d339524df0bdd 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) error { +func Get(a, u, p string, args ...string) (*gpb.GetResponse,error) { sbi := &nucleus.OpenConfig{} opts := &nucleus.GnmiTransportOptions{ Config: gnmi.Config{ @@ -22,12 +22,16 @@ func Get(a, u, p string, args...string) error { } t, err := nucleus.NewGnmiTransport(opts) if err != nil { - return err + return nil,err } resp, err := t.Get(context.Background(), args...) if err != nil { - return err + return nil, err } - log.Info(resp) - return nil + log.Debug(resp) + r, ok := resp.(*gpb.GetResponse) + if !ok { + return nil, &nucleus.ErrInvalidTypeAssertion{} + } + return r, nil } diff --git a/cli/http.go b/cli/http.go index 1dc35dd178006d65a8813a8e92bfb95d0d216f79..4d340877ecb436dde33d7474df7517b782ac9cd4 100644 --- a/cli/http.go +++ b/cli/http.go @@ -1,6 +1,7 @@ package cli import ( + "errors" "fmt" log "github.com/sirupsen/logrus" "github.com/spf13/viper" @@ -34,13 +35,14 @@ func HttpGet(apiEndpoint, f string, args ...string) error { if err != nil { return err } - if f == "init" { + switch f { + case "init": pnd := string(bytes[:36]) sbi := string(bytes[36:]) viper.Set("CLI_PND", pnd) viper.Set("CLI_SBI", sbi) return viper.WriteConfig() - } else { + default: fmt.Println(string(bytes)) } case http.StatusCreated: @@ -49,11 +51,14 @@ func HttpGet(apiEndpoint, f string, args ...string) error { if err != nil { return err } + uuid := string(bytes[19:55]) + viper.Set("LAST_DEVICE_UUID", uuid) fmt.Println(string(bytes)) default: log.WithFields(log.Fields{ "status code": resp.StatusCode, }).Error("operation unsuccessful") + return errors.New(resp.Status) } return nil } diff --git a/cli/init.go b/cli/init.go index 44d5df8ea052f9c138a895dae446259c87024b8f..d85e6bd00885a1c4aefea4b6766da349ccd5b8cd 100644 --- a/cli/init.go +++ b/cli/init.go @@ -8,10 +8,10 @@ import ( var testSchema *ytypes.Schema -func init(){ +func init() { var err error testSchema, err = model.Schema() if err != nil { log.Fatal(err) } -} \ No newline at end of file +} diff --git a/cli/integration_test.go b/cli/integration_test.go new file mode 100644 index 0000000000000000000000000000000000000000..d38003506d0ae2519c1f16a891d0c58b9cb9243c --- /dev/null +++ b/cli/integration_test.go @@ -0,0 +1,240 @@ +package cli + +import ( + "os" + "testing" +) + +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 defaultPath = []string{"/system/config/hostname"} + +func testSetupIntegration() { + a := os.Getenv("GOSDN_TEST_ENDPOINT") + if a != "" { + address = a + } + api := os.Getenv("GOSDN_TEST_API_ENDPOINT") + if api != "" { + apiEndpoint = api + } +} + +func TestMain(m *testing.M) { + testSetupIntegration() + os.Exit(m.Run()) +} + +func TestCapabilities(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + type args struct { + a string + u string + p string + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "default", + args: args{ + a: address, + u: username, + p: password, + }, + wantErr: false, + }, + { + name: "destination unreachable", + args: args{ + a: unreachable, + u: username, + p: password, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := Capabilities(tt.args.a, tt.args.u, tt.args.p); (err != nil) != tt.wantErr { + t.Errorf("Capabilities() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestGet(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + type args struct { + a string + u string + p string + args []string + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "default", + args: args{ + a: address, + u: username, + p: password, + args: defaultPath, + }, + wantErr: false, + }, + { + name: "destination unreachable", + args: args{ + a: unreachable, + u: username, + p: password, + args: defaultPath, + }, + wantErr: false, + }, + } + 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 { + t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestHttpGet(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + type args struct { + apiEndpoint string + f string + args []string + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "default", + args: args{ + apiEndpoint: apiEndpoint, + f: "init", + args: nil, + }, + wantErr: false, + }, + { + name: "destination unreachable", + args: args{ + apiEndpoint: "http://" + unreachable, + f: "init", + args: nil, + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := HttpGet(tt.args.apiEndpoint, tt.args.f, tt.args.args...); (err != nil) != tt.wantErr { + t.Errorf("HttpGet() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestPathTraversal(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) { + if err := PathTraversal(); (err != nil) != tt.wantErr { + t.Errorf("PathTraversal() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestSet(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + type args struct { + a string + u string + p string + typ string + args []string + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "default", + args: args{ + a: address, + u: username, + p: password, + typ: "update", + args: []string{"/system/config/hostname", "ceos3000"}, + }, + wantErr: false, + }, + { + name: "destination unreachable", + args: args{ + a: unreachable, + u: username, + p: password, + typ: "update", + args: []string{"/system/config/hostname", "ceos3000"}, + }, + wantErr: true, + }, + { + name: "invalid path", + args: args{ + a: address, + u: username, + p: password, + typ: "update", + args: []string{"invalid/path", "ceos3000"}, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := Set(tt.args.a, tt.args.u, tt.args.p, tt.args.typ, tt.args.args...); (err != nil) != tt.wantErr { + t.Errorf("Set() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/cli/subscribe.go b/cli/subscribe.go index 4306775a9d9614134376c4a8b09915a7d8b947df..bd126534e042cfef33c1ee9dfbf68431a33c7d09 100644 --- a/cli/subscribe.go +++ b/cli/subscribe.go @@ -12,9 +12,10 @@ import ( "syscall" "time" ) + // Subscribe starts a gNMI subscriber requersting the specified paths on the target and // logs the response to stdout. Only 'stream' mode with 'sample' operation supported. -func Subscribe(a, u, p string, sample, heartbeat int64, args...string) error{ +func Subscribe(a, u, p string, sample, heartbeat int64, args ...string) error { sbi := &nucleus.OpenConfig{} tOpts := &nucleus.GnmiTransportOptions{ Config: gnmi.Config{ @@ -27,7 +28,7 @@ func Subscribe(a, u, p string, sample, heartbeat int64, args...string) error{ RespChan: make(chan *gpb.SubscribeResponse), } - device, err := nucleus.NewDevice(sbi,tOpts) + device, err := nucleus.NewDevice(sbi, tOpts) if err != nil { return err } diff --git a/cli/ygot.go b/cli/ygot.go deleted file mode 100644 index 51b12852e6274d94279972793333ea3be3131657..0000000000000000000000000000000000000000 --- a/cli/ygot.go +++ /dev/null @@ -1,17 +0,0 @@ -package cli - -import ( - "github.com/openconfig/ygot/util" - log "github.com/sirupsen/logrus" -) - -func LeafPaths() error { - for _, v := range testSchema.SchemaTree { - entry, err := util.FindLeafRefSchema(v, "/interface/") - if err != nil { - log.Error(err) - } - log.Info(entry) - } - return nil -} diff --git a/cmd/get.go b/cmd/get.go index 8cd17622d5c5c62ec7aeaba21932536eac260544..fe1e2083efb6a31af3ed77da7e1c7947a5d889ce 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -39,9 +39,10 @@ import ( var getCmd = &cobra.Command{ Use: "gosdn get", Short: "get request", - Long: `Sends a gNMI Get request to the specified target and prints the response to stdout`, + Long: `Sends a gNMI Get request to the specified target and prints the response to stdout`, RunE: func(cmd *cobra.Command, args []string) error { - return cli.Get(address, username, password, args...) + _,err := cli.Get(address, username, password, args...) + return err }, } diff --git a/cmd/getDevice.go b/cmd/getDevice.go index 3e5ae2730e881737b0b153ec96b83a09ab346f56..b7e140e21aa5c2d24b8515effbe43e0001737c1e 100644 --- a/cmd/getDevice.go +++ b/cmd/getDevice.go @@ -47,7 +47,7 @@ var getDeviceCmd = &cobra.Command{ "uuid="+uuid, "sbi="+cliSbi, "pnd="+cliPnd, - ) + ) }, } diff --git a/cmd/gosdn/main.go b/cmd/gosdn/main.go index 03815b4ec592e36599bf2d4bf92aa9f99f91e387..a87c9ff0e98464b7a0c8b1ede5808946d954ca4a 100644 --- a/cmd/gosdn/main.go +++ b/cmd/gosdn/main.go @@ -33,5 +33,5 @@ package main import "code.fbi.h-da.de/cocsn/gosdn/cmd" func main() { - cmd.Execute() + cmd.Execute() } diff --git a/cmd/init.go b/cmd/init.go index 17fb0ca83c6fbc2ca0c8f2e3e0de0823edebc437..d1290a476c8e76cc9bc813076f508a8752b0f11d 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -41,7 +41,7 @@ var initCmd = &cobra.Command{ Short: "initialise SBI and PND", Long: ``, RunE: func(cmd *cobra.Command, args []string) error { - return cli.HttpGet(apiEndpoint, "init" ) + return cli.HttpGet(apiEndpoint, "init") }, } diff --git a/cmd/integration_test.go b/cmd/integration_test.go new file mode 100644 index 0000000000000000000000000000000000000000..3eda98ed9d98a5d558d4084e32a02bb2426d9198 --- /dev/null +++ b/cmd/integration_test.go @@ -0,0 +1,131 @@ +package cmd + +import ( + "code.fbi.h-da.de/cocsn/gosdn/cli" + guuid "github.com/google/uuid" + "github.com/spf13/viper" + "os" + "testing" +) + +var testAddress = "141.100.70.171:6030" +var testApiEndpoint = "http://141.100.70.171:8080" +var testUsername = "admin" +var testPassword = "arista" + +func testSetupIntegration() { + a := os.Getenv("GOSDN_TEST_ENDPOINT") + if a != "" { + testAddress = a + } + api := os.Getenv("GOSDN_TEST_API_ENDPOINT") + if api != "" { + testApiEndpoint = api + } + u := os.Getenv("GOSDN_TEST_USER") + if u != "" { + testUsername = u + } + p := os.Getenv("GOSDN_TEST_PASSWORD") + if p != "" { + testPassword = p + } +} + +func TestMain(m *testing.M) { + testSetupIntegration() + os.Exit(m.Run()) +} + +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) + } + }) + } +} diff --git a/cmd/legacy.go b/cmd/legacy.go index 8d589320f5c19e6df9c6a5df3e8ae6289ecde719..968da6deddd0023f346f267516a6c21d8ccd9556 100644 --- a/cmd/legacy.go +++ b/cmd/legacy.go @@ -39,7 +39,7 @@ import ( var legacyCmd = &cobra.Command{ Use: "legacy", Short: "multiple ygot utils - not yet implemented", - Long: ``, + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { return errors.New("not implemented") }, diff --git a/cmd/path.go b/cmd/path.go index 0c4b45da9790f81c3574f8410bb32abf7af698c4..41a88d9f1bb8ccf33b0565072390e2ed0656f24c 100644 --- a/cmd/path.go +++ b/cmd/path.go @@ -39,7 +39,7 @@ import ( var pathCmd = &cobra.Command{ Use: "path", Short: "multiple ygot utils - not yet implemented", - Long: ``, + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { return errors.New("not implemented") }, diff --git a/cmd/request.go b/cmd/request.go index d234bb24b69f8491d1e5c707e0d02a58a68c4887..de789af65e13ad874003a7233dc9785e050662df 100644 --- a/cmd/request.go +++ b/cmd/request.go @@ -48,7 +48,7 @@ var requestCmd = &cobra.Command{ "sbi="+cliSbi, "pnd="+cliPnd, "path="+args[0], - ) + ) }, } diff --git a/cmd/requestAll.go b/cmd/requestAll.go index 2b996b0d8e7014d5a98468254c008203fdbff47b..d67e889cdbc5732640f051896250545f5dd41c5a 100644 --- a/cmd/requestAll.go +++ b/cmd/requestAll.go @@ -47,7 +47,7 @@ var requestAllCmd = &cobra.Command{ "sbi="+cliSbi, "pnd="+cliPnd, "path="+args[0], - ) + ) }, } diff --git a/cmd/set.go b/cmd/set.go index 46beef8c98a0fe3bc8647139619036c9a89314d9..5948201aac3887f1c5d0752842bcdad3d6cc2959 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -51,6 +51,6 @@ var setCmd = &cobra.Command{ func init() { rootCmd.AddCommand(setCmd) - setCmd.Flags().StringVarP(&typ, "type", "t", "update", "Type of the set request. " + + setCmd.Flags().StringVarP(&typ, "type", "t", "update", "Type of the set request. "+ "Possible values: 'update', 'replace', and 'delete'") } diff --git a/cmd/target.go b/cmd/target.go index 2aeb616f72a0c3da13f335301851e3c9d405d22e..f72085144fcae25ff872859e1c32621139079279 100644 --- a/cmd/target.go +++ b/cmd/target.go @@ -42,7 +42,7 @@ var bindAddr string var targetCmd = &cobra.Command{ Use: "target", Short: "start gnmi target", - Long: `Starts a gNMI target listening on the specified port.`, + Long: `Starts a gNMI target listening on the specified port.`, RunE: func(cmd *cobra.Command, args []string) error { return cli.Target(bindAddr) }, diff --git a/cmd/util.go b/cmd/util.go index c97a75dd988eba3cadc58e020880e57a966bb183..0d940c3b4bc09182a95533bea9f8efbc61550862 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -39,7 +39,7 @@ import ( var utilCmd = &cobra.Command{ Use: "util", Short: "multiple ygot utils - not yet implemented", - Long: ``, + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { return errors.New("not implemented") }, diff --git a/cmd/ygot.go b/cmd/ygot.go index 504a4f4f0ef465efd0bdc6e78b5b6fbe6c881657..966e02e3bb9e1b8082d9399771975ee757684cc2 100644 --- a/cmd/ygot.go +++ b/cmd/ygot.go @@ -40,7 +40,7 @@ import ( var ygotCmd = &cobra.Command{ Use: "ygot", Short: "multiple ygot utils - not yet implemented", - Long: ``, + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { return errors.New("not implemented") }, diff --git a/nucleus/controller.go b/nucleus/controller.go index d11781461112cf87a6da752f87d09076099f22b2..50ae2e12872de103bf24a6ef66889235cfec6e02 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -63,7 +63,7 @@ func createSouthboundInterfaces() error { } // createPrincipalNetworkDomain initializes the controller with an initial PND -func createPrincipalNetworkDomain(sbi SouthboundInterface) error{ +func createPrincipalNetworkDomain(sbi SouthboundInterface) error { pnd, err := NewPND("base", "gosdn base pnd", uuid.New(), sbi) if err != nil { return err diff --git a/nucleus/errors_test.go b/nucleus/errors_test.go deleted file mode 100644 index 09d172db926b14465fb4e16f641017a4f6d430ae..0000000000000000000000000000000000000000 --- a/nucleus/errors_test.go +++ /dev/null @@ -1,196 +0,0 @@ -package nucleus - -import "testing" - -func TestErrAlreadyExists_Error(t *testing.T) { - type fields struct { - item interface{} - } - tests := []struct { - name string - fields fields - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := &ErrAlreadyExists{ - item: tt.fields.item, - } - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestErrInvalidParameters_Error(t *testing.T) { - type fields struct { - f interface{} - r interface{} - } - tests := []struct { - name string - fields fields - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := ErrInvalidParameters{ - f: tt.fields.f, - r: tt.fields.r, - } - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestErrInvalidTransportOptions_Error(t *testing.T) { - type fields struct { - t interface{} - } - tests := []struct { - name string - fields fields - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := ErrInvalidTransportOptions{ - t: tt.fields.t, - } - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestErrInvalidTypeAssertion_Error(t *testing.T) { - type fields struct { - v interface{} - t interface{} - } - tests := []struct { - name string - fields fields - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := ErrInvalidTypeAssertion{ - v: tt.fields.v, - t: tt.fields.t, - } - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestErrNilClient_Error(t *testing.T) { - tests := []struct { - name string - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := &ErrNilClient{} - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestErrNil_Error(t *testing.T) { - tests := []struct { - name string - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := &ErrNil{} - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestErrNotFound_Error(t *testing.T) { - type fields struct { - id interface{} - } - tests := []struct { - name string - fields fields - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := &ErrNotFound{ - id: tt.fields.id, - } - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestErrNotYetImplemented_Error(t *testing.T) { - tests := []struct { - name string - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := ErrNotYetImplemented{} - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestErrUnsupportedPath_Error(t *testing.T) { - type fields struct { - p interface{} - } - tests := []struct { - name string - fields fields - want string - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := ErrUnsupportedPath{ - p: tt.fields.p, - } - if got := e.Error(); got != tt.want { - t.Errorf("Error() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/nucleus/http.go b/nucleus/http.go index 7693bcabd845652c9f0cb81cae78a0dbd1edfae6..cf808a245815be38935c20f70f51de9212c661b1 100644 --- a/nucleus/http.go +++ b/nucleus/http.go @@ -31,6 +31,7 @@ func healthCheck(writer http.ResponseWriter, request *http.Request) { writer.WriteHeader(http.StatusOK) } +// nolint func httpHandler(writer http.ResponseWriter, request *http.Request) { log.WithFields(log.Fields{ "request": request, @@ -162,4 +163,4 @@ func httpHandler(writer http.ResponseWriter, request *http.Request) { default: writer.WriteHeader(http.StatusBadRequest) } -} \ No newline at end of file +} diff --git a/nucleus/http_test.go b/nucleus/http_test.go deleted file mode 100644 index 9221ee253c7b7d4890e472d98dcf9122f59d164c..0000000000000000000000000000000000000000 --- a/nucleus/http_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package nucleus - -import ( - "context" - "testing" -) - -func Test_httpApi(t *testing.T) { - type args struct { - ctx context.Context - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := httpApi(tt.args.ctx); (err != nil) != tt.wantErr { - t.Errorf("httpApi() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} diff --git a/nucleus/integration_test.go b/nucleus/integration_test.go index a4415afceab6db2abba979a0cece8f3c828a3f9c..a31f2ac4622f855dcb1f616361ce045b2d5762a7 100644 --- a/nucleus/integration_test.go +++ b/nucleus/integration_test.go @@ -273,8 +273,8 @@ func TestGnmi_SubscribeIntegration(t *testing.T) { go func() { err = g.Subscribe(ctx) if (err != nil) != tt.wantErr { - if !tt.wantErr{ - if err.Error() != "rpc error: code = Canceled desc = context canceled"{ + if !tt.wantErr { + if err.Error() != "rpc error: code = Canceled desc = context canceled" { t.Errorf("Subscribe() error = %v, wantErr %v", err, tt.wantErr) } } diff --git a/nucleus/southbound_test.go b/nucleus/southbound_test.go index e46e992bd6c0537168f5d6c8403a80e65d561b58..b28ff911c4e92ca75e3f9cb28908880b78dbf220 100644 --- a/nucleus/southbound_test.go +++ b/nucleus/southbound_test.go @@ -35,8 +35,8 @@ func TestOpenConfig_Id(t *testing.T) { { name: "default", fields: fields{ - schema: nil, - id: ocUUID, + schema: nil, + id: ocUUID, }, want: ocUUID, }, @@ -44,8 +44,8 @@ func TestOpenConfig_Id(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { oc := &OpenConfig{ - schema: tt.fields.schema, - id: tt.fields.id, + schema: tt.fields.schema, + id: tt.fields.id, } if got := oc.Id(); !reflect.DeepEqual(got, tt.want) { t.Errorf("Id() = %v, want %v", got, tt.want) @@ -56,8 +56,8 @@ func TestOpenConfig_Id(t *testing.T) { func TestOpenConfig_SbiIdentifier(t *testing.T) { type fields struct { - schema *ytypes.Schema - id uuid.UUID + schema *ytypes.Schema + id uuid.UUID } tests := []struct { name string @@ -69,8 +69,8 @@ func TestOpenConfig_SbiIdentifier(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { oc := &OpenConfig{ - schema: tt.fields.schema, - id: tt.fields.id, + schema: tt.fields.schema, + id: tt.fields.id, } if got := oc.SbiIdentifier(); got != tt.want { t.Errorf("SbiIdentifier() = %v, want %v", got, tt.want) @@ -85,8 +85,8 @@ func TestOpenConfig_Schema(t *testing.T) { t.Error(err) } type fields struct { - schema *ytypes.Schema - id uuid.UUID + schema *ytypes.Schema + id uuid.UUID } tests := []struct { name string @@ -98,8 +98,8 @@ func TestOpenConfig_Schema(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { oc := &OpenConfig{ - schema: tt.fields.schema, - id: tt.fields.id, + schema: tt.fields.schema, + id: tt.fields.id, } got := oc.Schema().SchemaTree if !reflect.DeepEqual(got, tt.want.SchemaTree) { diff --git a/test/terraform/containers.tf b/test/terraform/containers.tf index a6e381a9169eef45337aaf0b843bc1c89ddebef0..f9144a450c0691daef380b918ccbbb90f311a0c2 100644 --- a/test/terraform/containers.tf +++ b/test/terraform/containers.tf @@ -5,13 +5,22 @@ resource "docker_container" "gosdn" { image = docker_image.gosdn.name restart = "always" + networks_advanced { + name = "bridge" + } + ports { internal = 55055 external = 5555 } + ports { + internal = 8080 + external = 8080 + } + env = [ - "GOSDN_DEBUG=", + "GOSDN_LOG=debug", ] }