From 22ebf43e425ca4d2b1a0ba8a71e0060e9444ffa0 Mon Sep 17 00:00:00 2001 From: Nick Revin Date: Tue, 14 May 2019 17:19:49 +0300 Subject: [PATCH] add missing license headers, make linters happier Signed-off-by: Nick Revin --- README.md | 2 +- pkg/controller/redis/deepcontains_test.go | 38 +++++++++++++------ pkg/controller/redis/object_generator.go | 38 +++++++++++++------ pkg/controller/redis/object_generator_test.go | 14 +++++++ pkg/controller/redis/redis_controller.go | 14 +++++++ pkg/redis/redis.go | 12 +++--- 6 files changed, 87 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index d2061a74..45a09b4a 100644 --- a/README.md +++ b/README.md @@ -146,4 +146,4 @@ Once the reconfiguration has been finished all `Pod`s are labeled appropriately ### Short term -- [] add more testing +- [ ] add more testing diff --git a/pkg/controller/redis/deepcontains_test.go b/pkg/controller/redis/deepcontains_test.go index 193d4341..d9874c4e 100644 --- a/pkg/controller/redis/deepcontains_test.go +++ b/pkg/controller/redis/deepcontains_test.go @@ -1,3 +1,17 @@ +// Copyright 2019 The redis-operator Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package redis import ( @@ -44,7 +58,7 @@ func Test_deepContains(t *testing.T) { Tinterface: basic, Tpointer: &basic, Tstruct: basic, - Tmap: map[basicStruct]basicStruct{basic: basic, basicStruct{Tstring: "o"}: basic}, + Tmap: map[basicStruct]basicStruct{basic: basic, {Tstring: "o"}: basic}, } f := func() {} @@ -73,13 +87,13 @@ func Test_deepContains(t *testing.T) { // composite {"composite-empty", args{compositeStruct{}, compositeStruct{}}, true}, {"composite-equal", args{composite, composite}, true}, - {"composite-Tarray-true", args{composite, compositeStruct{Tarray: [2]basicStruct{basicStruct{Tstring: "o"}, basicStruct{}}}}, true}, - {"composite-Tslice-true", args{composite, compositeStruct{Tslice: []basicStruct{basicStruct{Tstring: "o"}}}}, true}, - {"composite-Tinterface-true", args{composite, compositeStruct{Tslice: []basicStruct{basicStruct{Tstring: "o"}}}}, true}, + {"composite-Tarray-true", args{composite, compositeStruct{Tarray: [2]basicStruct{{Tstring: "o"}, {}}}}, true}, + {"composite-Tslice-true", args{composite, compositeStruct{Tslice: []basicStruct{{Tstring: "o"}}}}, true}, + {"composite-Tinterface-true", args{composite, compositeStruct{Tslice: []basicStruct{{Tstring: "o"}}}}, true}, {"composite-Tstruct-true", args{composite, compositeStruct{Tstruct: basicStruct{Tstring: "o"}}}, true}, {"composite-Tpointer-true", args{composite, compositeStruct{Tpointer: &basicStruct{Tstring: "o"}}}, true}, {"composite-Tpointer-deep-true", args{compositeStruct{Tinterface: &[]basicStruct{basic}}, compositeStruct{Tinterface: &[]basicStruct{basic}}}, true}, - {"composite-Tmap-true", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basic: basicStruct{Tstring: "o"}}}}, true}, + {"composite-Tmap-true", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basic: {Tstring: "o"}}}}, true}, // negative tests // basic @@ -92,17 +106,17 @@ func Test_deepContains(t *testing.T) { {"basic-Tuint-false", args{basic, basicStruct{Tuint: uint(2)}}, false}, {"basic-Tfloat32-false", args{basic, basicStruct{Tfloat32: math.E}}, false}, // composite - {"composite-Tarray-false", args{composite, compositeStruct{Tarray: [2]basicStruct{basicStruct{Tstring: "oo"}, basicStruct{}}}}, false}, - {"composite-Tslice-false", args{composite, compositeStruct{Tslice: []basicStruct{basicStruct{Tstring: "oo"}, basicStruct{}, basicStruct{}, basicStruct{}}}}, false}, - {"composite-Tinterface-false", args{composite, compositeStruct{Tslice: []basicStruct{basicStruct{Tstring: "oo"}}}}, false}, + {"composite-Tarray-false", args{composite, compositeStruct{Tarray: [2]basicStruct{{Tstring: "oo"}, {}}}}, false}, + {"composite-Tslice-false", args{composite, compositeStruct{Tslice: []basicStruct{{Tstring: "oo"}, {}, {}, {}}}}, false}, + {"composite-Tinterface-false", args{composite, compositeStruct{Tslice: []basicStruct{{Tstring: "oo"}}}}, false}, {"composite-Tinterface-deepFunc-false", args{compositeStruct{Tinterface: f}, compositeStruct{Tinterface: f}}, false}, {"composite-Tstruct-false", args{composite, compositeStruct{Tstruct: basicStruct{Tstring: "oo"}}}, false}, {"composite-Tpointer-false", args{composite, compositeStruct{Tpointer: &basicStruct{Tstring: "oo"}}}, false}, - {"composite-Tpointer-deep-false", args{compositeStruct{Tinterface: &[]basicStruct{basic}}, compositeStruct{Tinterface: &[]basicStruct{basicStruct{Tstring: "oo"}}}}, false}, + {"composite-Tpointer-deep-false", args{compositeStruct{Tinterface: &[]basicStruct{basic}}, compositeStruct{Tinterface: &[]basicStruct{{Tstring: "oo"}}}}, false}, {"composite-Tpointer-deepType-false", args{compositeStruct{Tinterface: &[]basicStruct{basic}}, compositeStruct{Tinterface: &[]int{}}}, false}, - {"composite-Tmap-falseValue", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basic: basicStruct{Tstring: "oo"}}}}, false}, - {"composite-Tmap-falseKey", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basicStruct{}: basicStruct{Tstring: "o"}}}}, false}, - {"composite-Tmap-falseLen", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basicStruct{Tstring: "o"}: basicStruct{}, basicStruct{Tstring: "oo"}: basicStruct{}, basicStruct{Tstring: "ooo"}: basicStruct{}}}}, false}, + {"composite-Tmap-falseValue", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{basic: {Tstring: "oo"}}}}, false}, + {"composite-Tmap-falseKey", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{{}: {Tstring: "o"}}}}, false}, + {"composite-Tmap-falseLen", args{composite, compositeStruct{Tmap: map[basicStruct]basicStruct{{Tstring: "o"}: {}, {Tstring: "oo"}: {}, {Tstring: "ooo"}: {}}}}, false}, } for _, tt := range tests { diff --git a/pkg/controller/redis/object_generator.go b/pkg/controller/redis/object_generator.go index 31333681..a6796a65 100644 --- a/pkg/controller/redis/object_generator.go +++ b/pkg/controller/redis/object_generator.go @@ -1,3 +1,17 @@ +// Copyright 2019 The redis-operator Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package redis import ( @@ -75,18 +89,18 @@ var ( // that are not supposed to be changed or those controlled by redis-operator. // Sorted in order of appearance in https://github.com/antirez/redis/blob/5.0/redis.conf excludedConfigDirectives = map[string]struct{}{ - "include": struct{}{}, - "bind": struct{}{}, - "protected-mode": struct{}{}, - "port": struct{}{}, - "daemonize": struct{}{}, - "dir": struct{}{}, - "replica-announce-ip": struct{}{}, - "replica-announce-port": struct{}{}, - "replicaof": struct{}{}, - "masterauth": struct{}{}, - "requirepass": struct{}{}, - "rename-command": struct{}{}, + "include": {}, + "bind": {}, + "protected-mode": {}, + "port": {}, + "daemonize": {}, + "dir": {}, + "replica-announce-ip": {}, + "replica-announce-port": {}, + "replicaof": {}, + "masterauth": {}, + "requirepass": {}, + "rename-command": {}, } argonThreads = uint8(runtime.NumCPU()) ) diff --git a/pkg/controller/redis/object_generator_test.go b/pkg/controller/redis/object_generator_test.go index f134e8a8..79fa7936 100644 --- a/pkg/controller/redis/object_generator_test.go +++ b/pkg/controller/redis/object_generator_test.go @@ -1,3 +1,17 @@ +// Copyright 2019 The redis-operator Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package redis import ( diff --git a/pkg/controller/redis/redis_controller.go b/pkg/controller/redis/redis_controller.go index 3a585cd6..7602a826 100644 --- a/pkg/controller/redis/redis_controller.go +++ b/pkg/controller/redis/redis_controller.go @@ -1,3 +1,17 @@ +// Copyright 2019 The redis-operator Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package redis import ( diff --git a/pkg/redis/redis.go b/pkg/redis/redis.go index 064fa6bb..5f382d8d 100644 --- a/pkg/redis/redis.go +++ b/pkg/redis/redis.go @@ -148,15 +148,15 @@ type Redises []Redis // sort.Interface implementation for Redises. // Allows to choose an instance with a lesser priority and higher replication offset. // Note that this assumes that Redises don't have replicas with ReplicaPriority == 0 -func (a Redises) Len() int { return len(a) } -func (a Redises) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a Redises) Less(i, j int) bool { +func (instances Redises) Len() int { return len(instances) } +func (instances Redises) Swap(i, j int) { instances[i], instances[j] = instances[j], instances[i] } +func (instances Redises) Less(i, j int) bool { // choose a replica with less replica priority // choose a bigger replication offset otherwise - if a[i].ReplicaPriority == a[j].ReplicaPriority { - return a[i].ReplicationOffset > a[j].ReplicationOffset + if instances[i].ReplicaPriority == instances[j].ReplicaPriority { + return instances[i].ReplicationOffset > instances[j].ReplicationOffset } - return a[i].ReplicaPriority < a[j].ReplicaPriority + return instances[i].ReplicaPriority < instances[j].ReplicaPriority } // strict implementation check