From d9e61f710aacd5aa1772a325cda8ed66393cfce9 Mon Sep 17 00:00:00 2001 From: Andre Sterba <andre.sterba@stud.h-da.de> Date: Wed, 3 Nov 2021 11:12:43 +0000 Subject: [PATCH] Use fixed linter version v1.42 and update rules --- .gitignore | 3 +++ api/api_test.go | 1 - api/initialise_test.go | 1 - build/ci/.code-quality-ci.yml | 2 +- build/ci/.golangci-config/.golangci.yml | 6 +++++- controller.go | 3 +++ http_test.go | 1 - northbound/server/pnd.go | 7 ------- nucleus/change.go | 1 - nucleus/gnmi_transport.go | 6 ------ nucleus/principalNetworkDomain.go | 1 + nucleus/principalNetworkDomain_test.go | 2 -- nucleus/southbound_test.go | 7 ++----- nucleus/transport.go | 1 - nucleus/util/path/traverse.go | 5 ++--- 15 files changed, 17 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 83d7fcf53..2dcac5e10 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ test/.terraform.local/ configs/gosdn.toml api/api_test.toml debug.test + +# Binary +gosdn diff --git a/api/api_test.go b/api/api_test.go index a55113c1a..a3f722da0 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -72,7 +72,6 @@ func Test_CommitConfirm(t *testing.T) { return } log.Info(resp) - } func Test_AddDevice(t *testing.T) { diff --git a/api/initialise_test.go b/api/initialise_test.go index 7a7429a96..c6a00cc27 100644 --- a/api/initialise_test.go +++ b/api/initialise_test.go @@ -112,7 +112,6 @@ func bufDialer(context.Context, string) (net.Conn, error) { return lis.Dial() } -const unreachable = "203.0.113.10:6030" const testPath = "/system/config/hostname" var testAddress = "141.100.70.170:6030" diff --git a/build/ci/.code-quality-ci.yml b/build/ci/.code-quality-ci.yml index a608dd15e..3e5c205d9 100644 --- a/build/ci/.code-quality-ci.yml +++ b/build/ci/.code-quality-ci.yml @@ -1,5 +1,5 @@ code-quality: - image: golangci/golangci-lint:latest-alpine + image: golangci/golangci-lint:v1.42-alpine stage: test rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" diff --git a/build/ci/.golangci-config/.golangci.yml b/build/ci/.golangci-config/.golangci.yml index 1a2b91837..e9ea64def 100644 --- a/build/ci/.golangci-config/.golangci.yml +++ b/build/ci/.golangci-config/.golangci.yml @@ -27,9 +27,13 @@ linters: enable: - gofmt - goimports - - revive - gocyclo - govet + - unused + - staticcheck + - typecheck + - revive + - whitespace issues: exclude-use-default: false max-issues-per-linter: 0 diff --git a/controller.go b/controller.go index ed28c31be..d668c1753 100644 --- a/controller.go +++ b/controller.go @@ -90,6 +90,9 @@ func startGrpc() error { orchestrator := viper.GetString("csbi-orchestrator") conn, err := grpc.Dial(orchestrator, grpc.WithInsecure()) + if err != nil { + log.Fatal(err) + } c.csbiClient = cpb.NewCsbiClient(conn) return nil } diff --git a/http_test.go b/http_test.go index 7b4926e16..94092e1ca 100644 --- a/http_test.go +++ b/http_test.go @@ -6,7 +6,6 @@ import ( ) func Test_httpApi(t *testing.T) { - tests := []struct { name string request string diff --git a/northbound/server/pnd.go b/northbound/server/pnd.go index 3e06a5780..a25aefc09 100644 --- a/northbound/server/pnd.go +++ b/northbound/server/pnd.go @@ -349,13 +349,6 @@ func handleSetOnd(pnd networkdomain.NetworkDomain, req []*ppb.SetOnd) (*ppb.SetR }, nil } -func handleSetSbi(pnd networkdomain.NetworkDomain, req []*ppb.SetSbi) (*ppb.SetResponse, error) { - return &ppb.SetResponse{ - Timestamp: time.Now().UnixNano(), - Status: ppb.SetResponse_ERROR, - }, nil -} - func handleSetChange(pnd networkdomain.NetworkDomain, req []*ppb.SetChange) (*ppb.SetResponse, error) { for _, r := range req { cuid, err := uuid.Parse(r.Cuid) diff --git a/nucleus/change.go b/nucleus/change.go index f64a99eab..5340cfca1 100644 --- a/nucleus/change.go +++ b/nucleus/change.go @@ -132,7 +132,6 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, < errChan <- err } errChan <- fmt.Errorf("change %v timed out", ch.cuid) - break case s := <-stateIn: switch s { case ppb.Change_COMMITTED: diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go index fb5b3016d..e98faa28d 100644 --- a/nucleus/gnmi_transport.go +++ b/nucleus/gnmi_transport.go @@ -9,8 +9,6 @@ import ( "code.fbi.h-da.de/danet/gosdn/interfaces/southbound" - "google.golang.org/grpc" - ppb "code.fbi.h-da.de/danet/api/go/gosdn/pnd" "code.fbi.h-da.de/danet/forks/goarista/gnmi" @@ -71,10 +69,6 @@ func newGnmiTransport(opts *tpb.TransportOption, sbi southbound.SouthboundInterf }, nil } -func parseDialOptions(opts map[string]string) []grpc.DialOption { - return nil -} - // Get takes a slice of gnmi paths, splits them and calls get for each one of them. func (g *Gnmi) Get(ctx context.Context, params ...string) (interface{}, error) { if g.client == nil { diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index b0238a095..f64e7c0da 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -320,6 +320,7 @@ func (pnd *pndImplementation) ChangeOND(duid uuid.UUID, operation ppb.ApiOperati return ch.cuid, nil } +// nolint will be implemented in the near future func handleRollbackError(id uuid.UUID, err error) { log.Error(err) // TODO: Notion of invalid state needed. diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index d14fd7f76..3a9c23f25 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -693,7 +693,6 @@ func Test_pndImplementation_GetDevice(t *testing.T) { t.Errorf("GetDevice() got = %v, want %v", foundDevice.(device.Device).Model(), tt.want) } } - }) } } @@ -744,7 +743,6 @@ func Test_pndImplementation_GetDeviceByName(t *testing.T) { t.Errorf("GetDeviceByName() got = %v, want %v", foundDevice.(device.Device).Model(), tt.want) } } - }) } } diff --git a/nucleus/southbound_test.go b/nucleus/southbound_test.go index 2f92d24a1..1994cf71d 100644 --- a/nucleus/southbound_test.go +++ b/nucleus/southbound_test.go @@ -6,8 +6,6 @@ import ( spb "code.fbi.h-da.de/danet/api/go/gosdn/southbound" - "code.fbi.h-da.de/danet/gosdn/interfaces/transport" - "code.fbi.h-da.de/danet/gosdn/nucleus/util/path" "code.fbi.h-da.de/danet/gosdn/nucleus/util/proto" "code.fbi.h-da.de/danet/yang-models/generated/openconfig" @@ -19,9 +17,8 @@ import ( func TestOpenConfig_Id(t *testing.T) { type fields struct { - transport transport.Transport - schema *ytypes.Schema - id uuid.UUID + schema *ytypes.Schema + id uuid.UUID } tests := []struct { name string diff --git a/nucleus/transport.go b/nucleus/transport.go index abeeeca74..49d74e1c2 100644 --- a/nucleus/transport.go +++ b/nucleus/transport.go @@ -29,7 +29,6 @@ func NewTransport(opts *tpb.TransportOption, sbi southbound.SouthboundInterface) return newGnmiTransport(opts, sbi) default: return nil, &errors.ErrInvalidTransportOptions{Opt: o} - } } diff --git a/nucleus/util/path/traverse.go b/nucleus/util/path/traverse.go index c246ebddf..403ffc5e4 100644 --- a/nucleus/util/path/traverse.go +++ b/nucleus/util/path/traverse.go @@ -71,7 +71,6 @@ func processEntry(e *yang.Entry) *Element { // Strings constructs a slice containg all possible root to leaf paths. // Calls stringBuilder internally func Strings(paths map[string]*Element) []string { - p := make([]string, 0) ch := make(chan string) stop := make(chan bool) val := make(chan []string) @@ -81,7 +80,8 @@ func Strings(paths map[string]*Element) []string { stringBuilder(ch, &b, v) } stop <- true - p = <-val + p := <-val + return p } @@ -95,7 +95,6 @@ func appendix(c chan string, stop chan bool, pathChan chan []string) { log.Debug(path) case sig = <-stop: log.Debugf("Signal received: %v", sig) - } if sig { break -- GitLab