Skip to content

Commit a76c7fd

Browse files
Merge pull request GoogleCloudPlatform#1264 from acpana/acpana/c6
chore:lint: second round of revive
2 parents 97b4c0a + b2ff110 commit a76c7fd

File tree

92 files changed

+334
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+334
-365
lines changed

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ linters:
3838
# - importas
3939
# - ineffassign
4040
# - misspell
41-
# - revive # replacement for golint
41+
- revive # replacement for golint
4242
# - staticcheck
4343
# - typecheck
4444
# - unconvert

config/tests/samples/create/harness.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ var httpRoundTripperKey httpRoundTripperKeyType
8282

8383
// NewHarnessWithManager builds a Harness for an existing manager.
8484
// deprecated: Prefer NewHarness, which can construct a manager and mock gcp etc.
85-
func NewHarnessWithManager(t *testing.T, ctx context.Context, mgr manager.Manager) *Harness {
85+
func NewHarnessWithManager(ctx context.Context, t *testing.T, mgr manager.Manager) *Harness {
8686
h := &Harness{
8787
T: t,
8888
Ctx: ctx,
@@ -91,7 +91,7 @@ func NewHarnessWithManager(t *testing.T, ctx context.Context, mgr manager.Manage
9191
return h
9292
}
9393

94-
func NewHarness(t *testing.T, ctx context.Context) *Harness {
94+
func NewHarness(ctx context.Context, t *testing.T) *Harness {
9595
ctx, ctxCancel := context.WithCancel(ctx)
9696
t.Cleanup(func() {
9797
ctxCancel()
@@ -117,7 +117,7 @@ func NewHarness(t *testing.T, ctx context.Context) *Harness {
117117
kccConfig.ManagerOptions.NewClient = nocache.NoCacheClientFunc
118118
kccConfig.StateIntoSpecDefaultValue = k8s.StateIntoSpecDefaultValueV1Beta1
119119

120-
var webhooks []cnrmwebhook.WebhookConfig
120+
var webhooks []cnrmwebhook.Config
121121

122122
loadCRDs := true
123123
if targetKube := os.Getenv("E2E_KUBE_TARGET"); targetKube == "envtest" {
@@ -450,14 +450,14 @@ func MaybeSkip(t *testing.T, name string, resources []*unstructured.Unstructured
450450
case schema.GroupKind{Group: "tags.cnrm.cloud.google.com", Kind: "TagsTagKey"}:
451451

452452
default:
453-
t.Skipf("gk %v not suppported by mock gcp; skipping", gvk.GroupKind())
453+
t.Skipf("gk %v not suppported by mock gcp %v; skipping", gvk.GroupKind(), name)
454454
}
455455
}
456456
}
457457
}
458458

459-
func (t *Harness) waitForCRDReady(obj client.Object) {
460-
logger := log.FromContext(t.Ctx)
459+
func (h *Harness) waitForCRDReady(obj client.Object) {
460+
logger := log.FromContext(h.Ctx)
461461

462462
apiVersion, kind := obj.GetObjectKind().GroupVersionKind().ToAPIVersionAndKind()
463463
name := obj.GetName()
@@ -469,11 +469,11 @@ func (t *Harness) waitForCRDReady(obj client.Object) {
469469
u.SetAPIVersion(apiVersion)
470470
u.SetKind(kind)
471471
logger.V(2).Info("Testing to see if resource is ready", "kind", kind, "id", id)
472-
if err := t.GetClient().Get(t.Ctx, id, u); err != nil {
472+
if err := h.GetClient().Get(h.Ctx, id, u); err != nil {
473473
logger.Info("Error getting resource", "kind", kind, "id", id, "error", err)
474474
return false, err
475475
}
476-
objectStatus := dynamic.GetObjectStatus(t.T, u)
476+
objectStatus := dynamic.GetObjectStatus(h.T, u)
477477
// CRDs do not have observedGeneration
478478
for _, condition := range objectStatus.Conditions {
479479
if condition.Type == "Established" && condition.Status == "True" {
@@ -485,7 +485,7 @@ func (t *Harness) waitForCRDReady(obj client.Object) {
485485
logger.V(2).Info("CRD is not ready", "kind", kind, "id", id, "conditions", objectStatus.Conditions)
486486
return false, nil
487487
}); err != nil {
488-
t.Errorf("error while polling for ready on %v %v: %v", kind, id, err)
488+
h.Errorf("error while polling for ready on %v %v: %v", kind, id, err)
489489
return
490490
}
491491
}

config/tests/samples/create/samples.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func networksInSampleCount(sample Sample) int {
6060
count := 0
6161
for _, r := range sample.Resources {
6262
if r.GetKind() == "ComputeNetwork" {
63-
count += 1
63+
count++
6464
}
6565
}
6666
return count
@@ -85,7 +85,7 @@ func getNamespaces(resources []*unstructured.Unstructured) []string {
8585
return namespaces.List()
8686
}
8787

88-
type CreateDeleteTestOptions struct {
88+
type CreateDeleteTestOptions struct { //nolint:revive
8989
// Create is the set of objects to create
9090
Create []*unstructured.Unstructured
9191

config/tests/samples/create/samples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func TestAll(t *testing.T) {
257257

258258
ctx := context.TODO()
259259

260-
h := NewHarnessWithManager(t, ctx, mgr)
260+
h := NewHarnessWithManager(ctx, t, mgr)
261261
SetupNamespacesAndApplyDefaults(h, s.Resources, project)
262262

263263
networkCount := int64(networksInSampleCount(s))

config/tests/servicemapping/servicemapping_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,13 @@ func TestMustHaveIDTemplateOrServerGeneratedId(t *testing.T) {
590590
rc := rc
591591
t.Run(rc.Kind, func(t *testing.T) {
592592
t.Parallel()
593-
assertIDTemplateOrServerGeneratedId(t, rc)
593+
assertIDTemplateOrServerGeneratedID(t, rc)
594594
})
595595
}
596596
}
597597
}
598598

599-
func assertIDTemplateOrServerGeneratedId(t *testing.T, rc v1alpha1.ResourceConfig) {
599+
func assertIDTemplateOrServerGeneratedID(t *testing.T, rc v1alpha1.ResourceConfig) {
600600
if rc.IDTemplate == "" && rc.ServerGeneratedIDField == "" {
601601
t.Fatalf("resource kind '%v' with name '%v' has neither id template or server generated ID defined: at least one must be present", rc.Kind, rc.Name)
602602
}
@@ -625,10 +625,10 @@ func TestIDTemplate(t *testing.T) {
625625

626626
// The idTemplate should contain either the user-specified
627627
// ID or the server-generated ID.
628-
if (IDTemplateContainsMetadataName(t, rc) &&
629-
!IDTemplateContainsServerGeneratedIDField(t, rc)) ||
630-
(!IDTemplateContainsMetadataName(t, rc) &&
631-
IDTemplateContainsServerGeneratedIDField(t, rc)) {
628+
if (IDTemplateContainsMetadataName(rc) &&
629+
!IDTemplateContainsServerGeneratedIDField(rc)) ||
630+
(!IDTemplateContainsMetadataName(rc) &&
631+
IDTemplateContainsServerGeneratedIDField(rc)) {
632632
return
633633
}
634634

@@ -642,12 +642,12 @@ func TestIDTemplate(t *testing.T) {
642642
}
643643
}
644644

645-
func IDTemplateContainsMetadataName(t *testing.T, rc v1alpha1.ResourceConfig) bool {
645+
func IDTemplateContainsMetadataName(rc v1alpha1.ResourceConfig) bool {
646646
return strings.Contains(rc.IDTemplate,
647647
fmt.Sprintf("{{%v}}", rc.MetadataMapping.Name))
648648
}
649649

650-
func IDTemplateContainsServerGeneratedIDField(t *testing.T, rc v1alpha1.ResourceConfig) bool {
650+
func IDTemplateContainsServerGeneratedIDField(rc v1alpha1.ResourceConfig) bool {
651651
return strings.Contains(rc.IDTemplate,
652652
fmt.Sprintf("{{%v}}", rc.ServerGeneratedIDField))
653653
}
@@ -1261,11 +1261,11 @@ func TestStorageVersionIsSetAndValidIFFV1alpha1ToV1beta1IsSet(t *testing.T) {
12611261
"must be %v or %v", r.Name, k8s.KCCAPIVersionV1Alpha1,
12621262
k8s.KCCAPIVersion)
12631263
continue
1264-
} else {
1265-
t.Errorf("Resource config %v has `v1alpha1ToV1beta1: "+
1266-
"true` but doesn't have a `storageVersion`", r.Name)
1267-
continue
12681264
}
1265+
1266+
t.Errorf("Resource config %v has `v1alpha1ToV1beta1: "+
1267+
"true` but doesn't have a `storageVersion`", r.Name)
1268+
continue
12691269
}
12701270
if hasStorageVersion {
12711271
t.Errorf("Resource config %v has `storageVersion` set "+

operator/pkg/controllers/configconnector/configconnector_controller_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func TestHandleConfigConnectorCreate(t *testing.T) {
280280
}
281281
}
282282

283-
if err := handleLifecycles(t, ctx, r, tc.cc, m); err != nil {
283+
if err := handleLifecycles(ctx, t, r, tc.cc, m); err != nil {
284284
t.Fatalf("unexpected error: %v", err)
285285
}
286286
expectedObjs := tc.resultsFunc(t, c)
@@ -451,7 +451,7 @@ func TestHandleConfigConnectorDelete(t *testing.T) {
451451
}
452452
if len(tc.cccs) > 0 {
453453
// Expect that the first attempt returns an error.
454-
if err := handleLifecycles(t, ctx, r, tc.cc, m); err == nil {
454+
if err := handleLifecycles(ctx, t, r, tc.cc, m); err == nil {
455455
t.Fatalf("expect to have an error because the controller manager pod per namespace is not deleted, but got nil")
456456
}
457457
// Simulate that CCC controller kicks in and deletes the controller manager pod.
@@ -463,7 +463,7 @@ func TestHandleConfigConnectorDelete(t *testing.T) {
463463
}
464464
}
465465
}
466-
if err := handleLifecycles(t, ctx, r, tc.cc, m); err != nil {
466+
if err := handleLifecycles(ctx, t, r, tc.cc, m); err != nil {
467467
t.Fatalf("unexpected error: %v", err)
468468
}
469469
expectedObjs := tc.resultsFunc(t, c)
@@ -776,7 +776,7 @@ func TestConfigConnectorUpdate(t *testing.T) {
776776

777777
m := testcontroller.ParseObjects(ctx, t, tc.manifest)
778778
if tc.cc.GetMode() == "namespaced" {
779-
if err := handleLifecycles(t, ctx, r, tc.updatedCc, m); err == nil {
779+
if err := handleLifecycles(ctx, t, r, tc.updatedCc, m); err == nil {
780780
t.Fatalf("got nil, but want to have an error because the controller manager pod per namespace is not deleted")
781781
}
782782
// Simulate that CCC controller kicks in and deletes the controller manager pod.
@@ -788,7 +788,7 @@ func TestConfigConnectorUpdate(t *testing.T) {
788788
}
789789
}
790790
}
791-
if err := handleLifecycles(t, ctx, r, tc.updatedCc, m); err != nil {
791+
if err := handleLifecycles(ctx, t, r, tc.updatedCc, m); err != nil {
792792
t.Fatalf("unexpected error: %v", err)
793793
}
794794
expectedObjs := tc.resultsFunc(t, c)
@@ -825,8 +825,7 @@ type testCaseStruct struct {
825825
resultsFunc func(t *testing.T, c client.Client) []string
826826
}
827827

828-
func handleLifecycles(t *testing.T, ctx context.Context,
829-
r *Reconciler, cc *corev1beta1.ConfigConnector, m *manifest.Objects) error {
828+
func handleLifecycles(ctx context.Context, t *testing.T, r *Reconciler, cc *corev1beta1.ConfigConnector, m *manifest.Objects) error {
830829
t.Helper()
831830

832831
fn := r.transformForClusterMode()

0 commit comments

Comments
 (0)