From f5d1b6f9f0d5172e22365b98a099ed972d0df72e Mon Sep 17 00:00:00 2001 From: Manuel Kieweg <manuel.kieweg@h-da.de> Date: Fri, 26 Mar 2021 10:34:50 +0000 Subject: [PATCH] Integration tests for CLI --- cli/capabilities.go | 2 +- cli/cli_test.go | 259 ----------------------------------- cli/get.go | 14 +- cli/http.go | 9 +- cli/init.go | 4 +- cli/integration_test.go | 240 ++++++++++++++++++++++++++++++++ cli/subscribe.go | 5 +- cli/ygot.go | 17 --- cmd/get.go | 5 +- cmd/getDevice.go | 2 +- cmd/gosdn/main.go | 2 +- cmd/init.go | 2 +- cmd/integration_test.go | 131 ++++++++++++++++++ cmd/legacy.go | 2 +- cmd/path.go | 2 +- cmd/request.go | 2 +- cmd/requestAll.go | 2 +- cmd/set.go | 2 +- cmd/target.go | 2 +- cmd/util.go | 2 +- cmd/ygot.go | 2 +- nucleus/controller.go | 2 +- nucleus/errors_test.go | 196 -------------------------- nucleus/http.go | 3 +- nucleus/http_test.go | 26 ---- nucleus/integration_test.go | 4 +- nucleus/southbound_test.go | 24 ++-- test/terraform/containers.tf | 11 +- 28 files changed, 434 insertions(+), 540 deletions(-) delete mode 100644 cli/cli_test.go create mode 100644 cli/integration_test.go delete mode 100644 cli/ygot.go create mode 100644 cmd/integration_test.go delete mode 100644 nucleus/errors_test.go delete mode 100644 nucleus/http_test.go diff --git a/cli/capabilities.go b/cli/capabilities.go index a972822b1..a80540d87 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 df6c6ec4d..000000000 --- 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 a0984961c..f2b2e6e80 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 1dc35dd17..4d340877e 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 44d5df8ea..d85e6bd00 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 000000000..d38003506 --- /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 4306775a9..bd126534e 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 51b12852e..000000000 --- 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 8cd17622d..fe1e2083e 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 3e5ae2730..b7e140e21 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 03815b4ec..a87c9ff0e 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 17fb0ca83..d1290a476 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 000000000..3eda98ed9 --- /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 8d589320f..968da6ded 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 0c4b45da9..41a88d9f1 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 d234bb24b..de789af65 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 2b996b0d8..d67e889cd 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 46beef8c9..5948201aa 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 2aeb616f7..f72085144 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 c97a75dd9..0d940c3b4 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 504a4f4f0..966e02e3b 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 d11781461..50ae2e128 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 09d172db9..000000000 --- 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 7693bcabd..cf808a245 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 9221ee253..000000000 --- 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 a4415afce..a31f2ac46 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 e46e992bd..b28ff911c 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 a6e381a91..f9144a450 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", ] } -- GitLab