From 113cbac501847ab4b335c738ffc96cee58c497f6 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@stud.h-da.de> Date: Thu, 25 Mar 2021 18:19:43 +0100 Subject: [PATCH] refactoring for initialism linting errors --- mocks/PrincipalNetworkDomain.go | 2 +- mocks/SouthboundInterface.go | 2 +- mocks/Storable.go | 2 +- nucleus/controller.go | 2 +- nucleus/device.go | 12 +++--- nucleus/device_test.go | 14 +++---- nucleus/http.go | 4 +- nucleus/http_test.go | 4 +- nucleus/principalNetworkDomain.go | 4 +- nucleus/principalNetworkDomain_test.go | 54 +++++++++++++------------- nucleus/southbound.go | 6 +-- nucleus/southbound_test.go | 4 +- nucleus/store.go | 8 ++-- nucleus/store_test.go | 40 +++++++++---------- 14 files changed, 79 insertions(+), 79 deletions(-) diff --git a/mocks/PrincipalNetworkDomain.go b/mocks/PrincipalNetworkDomain.go index 8796a000b..38233e767 100644 --- a/mocks/PrincipalNetworkDomain.go +++ b/mocks/PrincipalNetworkDomain.go @@ -114,7 +114,7 @@ func (_m *PrincipalNetworkDomain) GetSBIs() interface{} { } // Id provides a mock function with given fields: -func (_m *PrincipalNetworkDomain) Id() uuid.UUID { +func (_m *PrincipalNetworkDomain) ID() uuid.UUID { ret := _m.Called() var r0 uuid.UUID diff --git a/mocks/SouthboundInterface.go b/mocks/SouthboundInterface.go index e4e0d4c16..6217f5a76 100644 --- a/mocks/SouthboundInterface.go +++ b/mocks/SouthboundInterface.go @@ -19,7 +19,7 @@ type SouthboundInterface struct { } // Id provides a mock function with given fields: -func (_m *SouthboundInterface) Id() uuid.UUID { +func (_m *SouthboundInterface) ID() uuid.UUID { ret := _m.Called() var r0 uuid.UUID diff --git a/mocks/Storable.go b/mocks/Storable.go index 1d2dc7d99..630f70145 100644 --- a/mocks/Storable.go +++ b/mocks/Storable.go @@ -14,7 +14,7 @@ type Storable struct { } // Id provides a mock function with given fields: -func (_m *Storable) Id() uuid.UUID { +func (_m *Storable) ID() uuid.UUID { ret := _m.Called() var r0 uuid.UUID diff --git a/nucleus/controller.go b/nucleus/controller.go index 9532f3ffb..d9fc1f14f 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -38,7 +38,7 @@ func initialize() error { } // TODO: Start grpc listener here - if err := httpApi(); err != nil { + if err := httpAPI(); err != nil { return err } diff --git a/nucleus/device.go b/nucleus/device.go index 96a6dd9ee..4318f7242 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -8,8 +8,8 @@ import ( // Device represents an Orchestrated Network Device (OND) which is managed by // nucleus type Device struct { - // Uuid represents the Devices UUID - Uuid uuid.UUID + // UUID represents the Devices UUID + UUID uuid.UUID // Device inherits properties of ygot.GoStruct ygot.GoStruct @@ -36,14 +36,14 @@ func NewDevice(sbi SouthboundInterface, opts TransportOptions) (*Device, error) } return &Device{ - Uuid: uuid.New(), + UUID: uuid.New(), GoStruct: sbi.Schema().Root, SBI: sbi, Transport: transport, }, nil } -// Id returns the uuid of the Device -func (d *Device) Id() uuid.UUID { - return d.Uuid +// ID returns the UUID of the Device +func (d *Device) ID() uuid.UUID { + return d.UUID } diff --git a/nucleus/device_test.go b/nucleus/device_test.go index d6391e830..0c6f118cc 100644 --- a/nucleus/device_test.go +++ b/nucleus/device_test.go @@ -14,7 +14,7 @@ func TestDevice_Id(t *testing.T) { GoStruct ygot.GoStruct SBI SouthboundInterface Transport Transport - Uuid uuid.UUID + UUID uuid.UUID } tests := []struct { name string @@ -24,7 +24,7 @@ func TestDevice_Id(t *testing.T) { { name: "default", fields: fields{ - Uuid: did, + UUID: did, }, want: did, }, @@ -35,10 +35,10 @@ func TestDevice_Id(t *testing.T) { GoStruct: tt.fields.GoStruct, SBI: tt.fields.SBI, Transport: tt.fields.Transport, - Uuid: tt.fields.Uuid, + UUID: tt.fields.UUID, } - if got := d.Id(); !reflect.DeepEqual(got, tt.want) { - t.Errorf("Id() = %v, want %v", got, tt.want) + if got := d.ID(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("ID() = %v, want %v", got, tt.want) } }) } @@ -71,7 +71,7 @@ func TestNewDevice(t *testing.T) { want: &Device{ GoStruct: &openconfig.Device{}, SBI: sbi, - Uuid: uuid.New(), + UUID: uuid.New(), Transport: &Gnmi{ Options: &GnmiTransportOptions{ Config: gnmi.Config{ @@ -91,7 +91,7 @@ func TestNewDevice(t *testing.T) { t.Error(err) } tt.want.Transport.(*Gnmi).client = got.Transport.(*Gnmi).client - tt.want.Uuid = got.Id() + tt.want.UUID = got.ID() if (err != nil) != tt.wantErr { t.Errorf("NewDevice() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/nucleus/http.go b/nucleus/http.go index 7693bcabd..5d8ccb2dc 100644 --- a/nucleus/http.go +++ b/nucleus/http.go @@ -13,7 +13,7 @@ import ( const basePath = "/api" // deprecated -func httpApi() (err error) { +func httpAPI() (err error) { http.HandleFunc(basePath, httpHandler) http.HandleFunc("/livez", healthCheck) http.HandleFunc("/readyz", healthCheck) @@ -89,7 +89,7 @@ func httpHandler(writer http.ResponseWriter, request *http.Request) { } writer.WriteHeader(http.StatusCreated) fmt.Fprintf(writer, "device added\n") - fmt.Fprintf(writer, "UUID: %v\n", d.Uuid) + fmt.Fprintf(writer, "UUID: %v\n", d.UUID) case "request": err = pnd.Request(id, query.Get("path")) if err != nil { diff --git a/nucleus/http_test.go b/nucleus/http_test.go index 9221ee253..b4210a6a8 100644 --- a/nucleus/http_test.go +++ b/nucleus/http_test.go @@ -18,8 +18,8 @@ func Test_httpApi(t *testing.T) { } 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) + if err := httpAPI(); (err != nil) != tt.wantErr { + t.Errorf("httpAPI() error = %v, wantErr %v", err, tt.wantErr) } }) } diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index 23e58212f..ebb372081 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -24,7 +24,7 @@ type PrincipalNetworkDomain interface { MarshalDevice(uuid.UUID) (string, error) ContainsDevice(uuid.UUID) bool GetSBIs() interface{} - Id() uuid.UUID + ID() uuid.UUID } type pndImplementation struct { @@ -50,7 +50,7 @@ func NewPND(name, description string, id uuid.UUID, sbi SouthboundInterface) (Pr return pnd, nil } -func (pnd *pndImplementation) Id() uuid.UUID { +func (pnd *pndImplementation) ID() uuid.UUID { return pnd.id } diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index cb5f3f5f7..b168f6b31 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -23,12 +23,12 @@ func testSetupPnd() { log.Fatal(err) } - defaultSbiId, err = uuid.Parse("b70c8425-68c7-4d4b-bb5e-5586572bd64b") + defaultSbiID, err = uuid.Parse("b70c8425-68c7-4d4b-bb5e-5586572bd64b") if err != nil { log.Fatal(err) } - defaultPndId, err = uuid.Parse("b4016412-eec5-45a1-aa29-f59915357bad") + defaultPndID, err = uuid.Parse("b4016412-eec5-45a1-aa29-f59915357bad") if err != nil { log.Fatal(err) } @@ -36,7 +36,7 @@ func testSetupPnd() { func mockDevice() Device { return Device{ - Uuid: mdid, + UUID: mdid, GoStruct: nil, SBI: &OpenConfig{}, Transport: &mocks.Transport{}, @@ -49,18 +49,18 @@ func newPnd() pndImplementation { description: "default test pnd", sbic: sbiStore{store{}}, devices: deviceStore{store{}}, - id: defaultPndId, + id: defaultPndID, } } var did uuid.UUID var mdid uuid.UUID -var defaultSbiId uuid.UUID -var defaultPndId uuid.UUID +var defaultSbiID uuid.UUID +var defaultPndID uuid.UUID func TestNewPND(t *testing.T) { pnd := newPnd() - if err := pnd.addSbi(&OpenConfig{id: defaultSbiId}); err != nil { + if err := pnd.addSbi(&OpenConfig{id: defaultSbiID}); err != nil { t.Error(err) } type args struct { @@ -80,8 +80,8 @@ func TestNewPND(t *testing.T) { args: args{ name: "default", description: "default test pnd", - sbi: &OpenConfig{id: defaultSbiId}, - pid: defaultPndId, + sbi: &OpenConfig{id: defaultSbiID}, + pid: defaultPndID, }, want: &pnd, wantErr: false, @@ -130,7 +130,7 @@ func Test_pndImplementation_AddDevice(t *testing.T) { name: "default", args: args{ device: &Device{ - Uuid: did, + UUID: did, }, }, wantErr: false, @@ -139,7 +139,7 @@ func Test_pndImplementation_AddDevice(t *testing.T) { name: "already exists", args: args{ device: &Device{ - Uuid: did, + UUID: did, }, }, wantErr: true, @@ -156,7 +156,7 @@ func Test_pndImplementation_AddDevice(t *testing.T) { t.Run(tt.name, func(t *testing.T) { pnd := newPnd() if tt.name == "already exists" { - pnd.devices.store[did] = &Device{Uuid: did} + pnd.devices.store[did] = &Device{UUID: did} } err := pnd.AddDevice(tt.args.device) if (err != nil) != tt.wantErr { @@ -191,7 +191,7 @@ func Test_pndImplementation_AddSbi(t *testing.T) { name: "default", args: args{ sbi: &OpenConfig{ - id: defaultSbiId, + id: defaultSbiID, }, }, wantErr: false, @@ -200,7 +200,7 @@ func Test_pndImplementation_AddSbi(t *testing.T) { name: "already exists", args: args{ sbi: &OpenConfig{ - id: defaultSbiId, + id: defaultSbiID, }, }, wantErr: true, @@ -209,7 +209,7 @@ func Test_pndImplementation_AddSbi(t *testing.T) { name: "fails wrong type", args: args{ sbi: &pndImplementation{ - id: defaultSbiId, + id: defaultSbiID, }, }, wantErr: true, @@ -219,7 +219,7 @@ func Test_pndImplementation_AddSbi(t *testing.T) { t.Run(tt.name, func(t *testing.T) { pnd := newPnd() if tt.name == "already exists" { - pnd.sbic.store[defaultSbiId] = tt.args.sbi.(*OpenConfig) + pnd.sbic.store[defaultSbiID] = tt.args.sbi.(*OpenConfig) } err := pnd.AddSbi(tt.args.sbi) if (err != nil) != tt.wantErr { @@ -227,12 +227,12 @@ func Test_pndImplementation_AddSbi(t *testing.T) { } if tt.name != "fails wrong type" { if err == nil { - _, ok := pnd.sbic.store[defaultSbiId] + _, ok := pnd.sbic.store[defaultSbiID] if !ok { t.Errorf("AddSbi() SBI %v not in device store %v", tt.args.sbi, pnd.GetSBIs()) } - if err := pnd.sbic.delete(defaultSbiId); err != nil { + if err := pnd.sbic.delete(defaultSbiID); err != nil { t.Error(err) } } @@ -253,15 +253,15 @@ func Test_pndImplementation_ContainsDevice(t *testing.T) { }{ {name: "default", args: args{ uuid: did, - device: &Device{Uuid: did}, + device: &Device{UUID: did}, }, want: true}, {name: "fails", args: args{ uuid: uuid.New(), - device: &Device{Uuid: did}, + device: &Device{UUID: did}, }, want: false}, {name: "fails empty", args: args{ uuid: uuid.New(), - device: &Device{Uuid: did}, + device: &Device{UUID: did}, }, want: false}, } for _, tt := range tests { @@ -383,7 +383,7 @@ func Test_pndImplementation_MarshalDevice(t *testing.T) { t.Run(tt.name, func(t *testing.T) { pnd := newPnd() d := &Device{ - Uuid: tt.args.uuid, + UUID: tt.args.uuid, GoStruct: &openconfig.Device{}, SBI: nil, Transport: nil, @@ -423,7 +423,7 @@ func Test_pndImplementation_RemoveDevice(t *testing.T) { t.Run(tt.name, func(t *testing.T) { pnd := newPnd() if tt.name != "fails empty" { - d := &Device{Uuid: did} + d := &Device{UUID: did} if err := pnd.addDevice(d); err != nil { t.Error(err) } @@ -447,9 +447,9 @@ func Test_pndImplementation_RemoveSbi(t *testing.T) { args args wantErr bool }{ - {name: "default", args: args{id: defaultSbiId}, wantErr: false}, + {name: "default", args: args{id: defaultSbiID}, wantErr: false}, {name: "fails", args: args{id: uuid.New()}, wantErr: true}, - {name: "fails empty", args: args{id: defaultSbiId}, wantErr: true}, + {name: "fails empty", args: args{id: defaultSbiID}, wantErr: true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -458,10 +458,10 @@ func Test_pndImplementation_RemoveSbi(t *testing.T) { description: "test-remove-sbi", sbic: sbiStore{store{}}, devices: deviceStore{store{}}, - id: defaultPndId, + id: defaultPndID, } if tt.name != "fails empty" { - if err := pnd.addSbi(&OpenConfig{id: defaultSbiId}); err != nil { + if err := pnd.addSbi(&OpenConfig{id: defaultSbiID}); err != nil { t.Error(err) } } diff --git a/nucleus/southbound.go b/nucleus/southbound.go index 4950ef495..831e5a92b 100644 --- a/nucleus/southbound.go +++ b/nucleus/southbound.go @@ -23,7 +23,7 @@ type SouthboundInterface interface { // Needed for type assertion. SetNode() func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error Schema() *ytypes.Schema - Id() uuid.UUID + ID() uuid.UUID } // Tapi is the implementation of an TAPI SBI. @@ -147,7 +147,7 @@ func iter(a ygot.GoStruct, fields []string) (b ygot.GoStruct, f string, err erro return } -// Id returns the Id of the OpenConfig SBI -func (oc *OpenConfig) Id() uuid.UUID { +// ID returns the ID of the OpenConfig SBI +func (oc *OpenConfig) ID() uuid.UUID { return oc.id } diff --git a/nucleus/southbound_test.go b/nucleus/southbound_test.go index b28ff911c..66249095c 100644 --- a/nucleus/southbound_test.go +++ b/nucleus/southbound_test.go @@ -47,8 +47,8 @@ func TestOpenConfig_Id(t *testing.T) { 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) + if got := oc.ID(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("ID() = %v, want %v", got, tt.want) } }) } diff --git a/nucleus/store.go b/nucleus/store.go index 33ca95509..14d09d335 100644 --- a/nucleus/store.go +++ b/nucleus/store.go @@ -8,7 +8,7 @@ import ( // Storable provides an interface for the controller's storage architecture. type Storable interface { - Id() uuid.UUID + ID() uuid.UUID } type store map[uuid.UUID]Storable @@ -19,13 +19,13 @@ func (s store) exists(id uuid.UUID) bool { } func (s store) add(item Storable) error { - if s.exists(item.Id()) { + if s.exists(item.ID()) { return &ErrAlreadyExists{item: item} } - s[item.Id()] = item + s[item.ID()] = item log.WithFields(log.Fields{ "type": reflect.TypeOf(item), - "uuid": item.Id(), + "uuid": item.ID(), }).Info("storable was added") return nil } diff --git a/nucleus/store_test.go b/nucleus/store_test.go index defdaa58f..1e87d49b6 100644 --- a/nucleus/store_test.go +++ b/nucleus/store_test.go @@ -51,7 +51,7 @@ func Test_store_add(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - tt.args.item.(*mocks.Storable).On("Id").Return(iid) + tt.args.item.(*mocks.Storable).On("ID").Return(iid) switch tt.name { case "already exixts": _ = tt.s.add(tt.args.item) @@ -254,18 +254,18 @@ func Test_sbiStore_get(t *testing.T) { name: "exists", fields: fields{ store: store{ - defaultSbiId: &OpenConfig{id: defaultSbiId}, + defaultSbiID: &OpenConfig{id: defaultSbiID}, }, }, - args: args{id: defaultSbiId}, - want: &OpenConfig{id: defaultSbiId}, + args: args{id: defaultSbiID}, + want: &OpenConfig{id: defaultSbiID}, wantErr: false, }, { name: "fails", fields: fields{ store: store{ - defaultSbiId: &OpenConfig{id: defaultSbiId}, + defaultSbiID: &OpenConfig{id: defaultSbiID}, }, }, args: args{id: iid}, @@ -276,7 +276,7 @@ func Test_sbiStore_get(t *testing.T) { fields: fields{ store: store{}, }, - args: args{id: defaultSbiId}, + args: args{id: defaultSbiID}, wantErr: true, }, { @@ -284,7 +284,7 @@ func Test_sbiStore_get(t *testing.T) { fields: fields{ store: store{ did: &Device{ - Uuid: did, + UUID: did, }, }, }, @@ -327,18 +327,18 @@ func Test_pndStore_get(t *testing.T) { name: "exists", fields: fields{ store: store{ - defaultPndId: &pndImplementation{id: defaultPndId}, + defaultPndID: &pndImplementation{id: defaultPndID}, }, }, - args: args{id: defaultPndId}, - want: &pndImplementation{id: defaultPndId}, + args: args{id: defaultPndID}, + want: &pndImplementation{id: defaultPndID}, wantErr: false, }, { name: "fails", fields: fields{ store: store{ - defaultPndId: &pndImplementation{id: defaultPndId}, + defaultPndID: &pndImplementation{id: defaultPndID}, }, }, args: args{id: iid}, @@ -349,7 +349,7 @@ func Test_pndStore_get(t *testing.T) { fields: fields{ store: store{}, }, - args: args{id: defaultPndId}, + args: args{id: defaultPndID}, wantErr: true, }, { @@ -357,7 +357,7 @@ func Test_pndStore_get(t *testing.T) { fields: fields{ store: store{ did: &Device{ - Uuid: did, + UUID: did, }, }, }, @@ -400,10 +400,10 @@ func Test_deviceStore_get(t *testing.T) { name: "exists", fields: fields{ store: store{ - defaultPndId: &Device{Uuid: did}}}, - args: args{id: defaultPndId}, + defaultPndID: &Device{UUID: did}}}, + args: args{id: defaultPndID}, want: &Device{ - Uuid: did, + UUID: did, }, wantErr: false, }, @@ -411,7 +411,7 @@ func Test_deviceStore_get(t *testing.T) { name: "fails", fields: fields{ store: store{ - defaultPndId: &Device{Uuid: did}}}, + defaultPndID: &Device{UUID: did}}}, args: args{id: iid}, wantErr: true, }, @@ -420,15 +420,15 @@ func Test_deviceStore_get(t *testing.T) { fields: fields{ store: store{}, }, - args: args{id: defaultPndId}, + args: args{id: defaultPndID}, wantErr: true, }, { name: "fails wrong type", fields: fields{ store: store{ - defaultPndId: &pndImplementation{id: defaultPndId}}}, - args: args{id: defaultPndId}, + defaultPndID: &pndImplementation{id: defaultPndID}}}, + args: args{id: defaultPndID}, wantErr: true, }, } -- GitLab