Skip to content

Commit

Permalink
gofumpt the repo (#3067)
Browse files Browse the repository at this point in the history
* gofumpt the repo

* don't prefix numbers with 0 - otherwise they're octal
  • Loading branch information
dprotaso committed Jun 25, 2024
1 parent fc0720b commit 8535fcc
Show file tree
Hide file tree
Showing 119 changed files with 551 additions and 516 deletions.
87 changes: 44 additions & 43 deletions apiextensions/storageversion/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,50 +136,51 @@ func TestMigrate_Errors(t *testing.T) {
crd func(*k8stesting.Fake)
dyn func(*k8stesting.Fake)
pass bool
}{{
name: "failed to fetch CRD",
crd: func(fake *k8stesting.Fake) {
fake.PrependReactor("get", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("failed to get crd")
})
},
}, {
name: "listing fails",
dyn: func(fake *k8stesting.Fake) {
fake.PrependReactor("list", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("failed to list resources")
})
},
}, {
name: "patching resource fails",
dyn: func(fake *k8stesting.Fake) {
fake.PrependReactor("patch", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("failed to patch resources")
})
},
}, {
name: "patching definition fails",
crd: func(fake *k8stesting.Fake) {
fake.PrependReactor("patch", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("failed to patch definition")
})
},
}, {
name: "patching unexisting resource",
dyn: func(fake *k8stesting.Fake) {
fake.PrependReactor("patch", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, apierrs.NewNotFound(fakeGR, "resource-removed")
})
}{
{
name: "failed to fetch CRD",
crd: func(fake *k8stesting.Fake) {
fake.PrependReactor("get", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("failed to get crd")
})
},
}, {
name: "listing fails",
dyn: func(fake *k8stesting.Fake) {
fake.PrependReactor("list", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("failed to list resources")
})
},
}, {
name: "patching resource fails",
dyn: func(fake *k8stesting.Fake) {
fake.PrependReactor("patch", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("failed to patch resources")
})
},
}, {
name: "patching definition fails",
crd: func(fake *k8stesting.Fake) {
fake.PrependReactor("patch", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, errors.New("failed to patch definition")
})
},
}, {
name: "patching unexisting resource",
dyn: func(fake *k8stesting.Fake) {
fake.PrependReactor("patch", "*",
func(k8stesting.Action) (bool, runtime.Object, error) {
return true, nil, apierrs.NewNotFound(fakeGR, "resource-removed")
})
},
// Resouce not found error should not block the storage migration.
pass: true,
},
// Resouce not found error should not block the storage migration.
pass: true,
},
// todo paging fails
// todo paging fails
}

for _, test := range tests {
Expand Down
3 changes: 1 addition & 2 deletions apis/condition_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ limitations under the License.
package apis

import (
"fmt"
"reflect"
"sort"
"time"

"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down
8 changes: 1 addition & 7 deletions apis/condition_set_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ func (t *TestStatus) SetConditions(conditions Conditions) {
t.c = conditions
}

var (
ignoreFields = cmpopts.IgnoreFields(Condition{}, "LastTransitionTime", "Severity")
)
var ignoreFields = cmpopts.IgnoreFields(Condition{}, "LastTransitionTime", "Severity")

func TestGetCondition(t *testing.T) {
condSet := NewLivingConditionSet()
Expand Down Expand Up @@ -318,7 +316,6 @@ func TestUpdateLastTransitionTime(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {

conds := &TestStatus{c: tc.conditions}

was := condSet.Manage(conds).GetCondition(tc.condition.Type)
Expand Down Expand Up @@ -821,7 +818,6 @@ type ConditionMarkFalseTest struct {
func doTestMarkFalseAccessor(t *testing.T, cases []ConditionMarkFalseTest) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {

condSet := NewLivingConditionSet(getTypes(tc.conditions)...)
status := &TestStatus{c: tc.conditions}
condSet.Manage(status).InitializeConditions()
Expand Down Expand Up @@ -933,7 +929,6 @@ type ConditionMarkUnknownTest struct {
func doTestMarkUnknownAccessor(t *testing.T, cases []ConditionMarkUnknownTest) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {

condSet := NewLivingConditionSet(getTypes(tc.conditions)...)
status := &TestStatus{c: tc.conditions}

Expand Down Expand Up @@ -1171,5 +1166,4 @@ func TestClearConditionWithNilManager(t *testing.T) {
if err != nil {
t.Error("ClearCondition() expected to return nil if status is nil, got", err)
}

}
5 changes: 2 additions & 3 deletions apis/condition_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestJSON(t *testing.T) {
name: "LastTransitionTime",
raw: `{"lastTransitionTime":"1984-02-28T18:52:00Z"}`,
condition: &Condition{
LastTransitionTime: VolatileTime{Inner: metav1.NewTime(time.Date(1984, 02, 28, 18, 52, 00, 00, time.UTC))},
LastTransitionTime: VolatileTime{Inner: metav1.NewTime(time.Date(1984, 2, 28, 18, 52, 0, 0, time.UTC))},
},
}, {
name: "Reason",
Expand All @@ -263,7 +263,7 @@ func TestJSON(t *testing.T) {
condition: &Condition{
Type: "Foo",
Status: corev1.ConditionTrue,
LastTransitionTime: VolatileTime{Inner: metav1.NewTime(time.Date(1984, 02, 28, 18, 52, 00, 00, time.UTC))},
LastTransitionTime: VolatileTime{Inner: metav1.NewTime(time.Date(1984, 2, 28, 18, 52, 0, 0, time.UTC))},
Reason: "DatTest",
Message: "this is just a test",
},
Expand All @@ -278,7 +278,6 @@ func TestJSON(t *testing.T) {
if diff := cmp.Diff(tc.condition, cond); diff != "" {
t.Errorf("%q unexpected diff (-want +got): %s", tc.name, diff)
}

})
}
}
2 changes: 0 additions & 2 deletions apis/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func ConvertToViaProxy(
ctx context.Context,
source, proxy, sink Convertible,
) error {

if err := source.ConvertTo(ctx, proxy); err != nil {
return err
}
Expand All @@ -38,7 +37,6 @@ func ConvertFromViaProxy(
ctx context.Context,
source, proxy, sink Convertible,
) error {

if err := proxy.ConvertFrom(ctx, source); err != nil {
return err
}
Expand Down
3 changes: 0 additions & 3 deletions apis/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func TestConvertToViaProxy(t *testing.T) {
source := &testResource{proxy: proxy}

err := ConvertToViaProxy(context.Background(), source, proxy, sink)

if err != nil {
t.Error("ConvertToViaProxy returned unexpected err:", err)
}
Expand Down Expand Up @@ -81,7 +80,6 @@ func TestConvertFromViaProxy(t *testing.T) {
source := &testResource{}

err := ConvertFromViaProxy(context.Background(), source, proxy, sink)

if err != nil {
t.Error("ConvertFromViaProxy returned unexpected err:", err)
}
Expand Down Expand Up @@ -115,7 +113,6 @@ func TestConvertFromViaProxyError(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {

err := ConvertFromViaProxy(context.Background(),
nil, /* source */
&test.proxy,
Expand Down
3 changes: 0 additions & 3 deletions apis/deprecated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
)

func TestCheckDeprecated(t *testing.T) {

testCases := map[string]struct {
strict bool
obj interface{}
Expand Down Expand Up @@ -226,7 +225,6 @@ func TestCheckDeprecated(t *testing.T) {
// It comes in on obj.InlinedStruct.InlinedPtrStruct.DeprecatedField and
// obj.InlinedPtrStruct.DeprecatedField.
func TestCheckDeprecated_Dedupe(t *testing.T) {

obj := &InnerDefaultSubSpec{
InlinedStruct: InlinedStruct{
DeprecatedField: "fail",
Expand All @@ -250,7 +248,6 @@ func TestCheckDeprecated_Dedupe(t *testing.T) {
}

func TestCheckDeprecatedUpdate(t *testing.T) {

testCases := map[string]struct {
strict bool
obj interface{}
Expand Down
1 change: 1 addition & 0 deletions apis/duck/enqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (fsii *fakeSharedIndexInformer) IsStopped() bool {
fsii.t.Fatalf("NYI: IsStopped")
return false
}

func (fsii *fakeSharedIndexInformer) RemoveEventHandler(handler cache.ResourceEventHandlerRegistration) error {
fsii.t.Fatalf("NYI: RemoveEventHandler")
return nil
Expand Down
7 changes: 4 additions & 3 deletions apis/duck/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ func TestCreatePatch(t *testing.T) {
if diff := cmp.Diff(want, got); diff != "" {
t.Error("CreateBytePatch (-want, +got) =", diff)
}

})
t.Run(test.name, func(t *testing.T) {
got, err := CreatePatch(test.before, test.after)
Expand Down Expand Up @@ -398,8 +397,10 @@ type PatchSpec struct {
Patchable *Patchable `json:"patchable,omitempty"`
}

var _ Implementable = (*Patchable)(nil)
var _ Populatable = (*Patch)(nil)
var (
_ Implementable = (*Patchable)(nil)
_ Populatable = (*Patch)(nil)
)

func (*Patch) GetObjectKind() schema.ObjectKind {
return nil // not used
Expand Down
9 changes: 5 additions & 4 deletions apis/duck/unstructured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ limitations under the License.
package duck

import (
"encoding/json"
"errors"
"testing"

"encoding/json"

"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -48,7 +47,8 @@ func TestFromUnstructuredFooable(t *testing.T) {
"field2": "bar",
},
},
}},
},
},
want: FooStatus{&Fooable{
Field1: "foo",
Field2: "bar",
Expand All @@ -64,7 +64,8 @@ func TestFromUnstructuredFooable(t *testing.T) {
"status": map[string]interface{}{
"extra": "fields",
},
}},
},
},
want: FooStatus{},
wantError: nil,
}, {
Expand Down
6 changes: 2 additions & 4 deletions apis/duck/v1/addressable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ type Addressable struct {
Audience *string `json:"audience,omitempty"`
}

var (
// Addressable is a Convertible type.
_ apis.Convertible = (*Addressable)(nil)
)
// Addressable is a Convertible type.
var _ apis.Convertible = (*Addressable)(nil)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
2 changes: 1 addition & 1 deletion apis/duck/v1/kresource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (t *KResource) Populate() {
// Populate ALL fields
Type: "Birthday",
Status: corev1.ConditionTrue,
LastTransitionTime: apis.VolatileTime{Inner: metav1.NewTime(time.Date(1984, 02, 28, 18, 52, 00, 00, time.UTC))},
LastTransitionTime: apis.VolatileTime{Inner: metav1.NewTime(time.Date(1984, 2, 28, 18, 52, 0, 0, time.UTC))},
Reason: "Celebrate",
Message: "n3wScott, find your party hat :tada:",
}}
Expand Down
2 changes: 1 addition & 1 deletion apis/duck/v1/source_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *Source) Populate() {
// Populate ALL fields
Type: SourceConditionSinkProvided,
Status: corev1.ConditionTrue,
LastTransitionTime: apis.VolatileTime{Inner: metav1.NewTime(time.Date(1984, 02, 28, 18, 52, 00, 00, time.UTC))},
LastTransitionTime: apis.VolatileTime{Inner: metav1.NewTime(time.Date(1984, 2, 28, 18, 52, 0, 0, time.UTC))},
}}
s.Status.SinkURI = &apis.URL{
Scheme: "https",
Expand Down
1 change: 1 addition & 0 deletions apis/duck/v1beta1/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func validateDestinationRef(ref corev1.ObjectReference) *apis.FieldError {

return errs
}

func validateCACerts(CACert *string) *apis.FieldError {
// Check the object.
var errs *apis.FieldError
Expand Down
2 changes: 1 addition & 1 deletion apis/duck/v1beta1/source_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s *Source) Populate() {
// Populate ALL fields
Type: SourceConditionSinkProvided,
Status: corev1.ConditionTrue,
LastTransitionTime: apis.VolatileTime{Inner: metav1.NewTime(time.Date(1984, 02, 28, 18, 52, 00, 00, time.UTC))},
LastTransitionTime: apis.VolatileTime{Inner: metav1.NewTime(time.Date(1984, 2, 28, 18, 52, 0, 0, time.UTC))},
}}
s.Status.SinkURI = &apis.URL{
Scheme: "https",
Expand Down
2 changes: 1 addition & 1 deletion apis/duck/v1beta1/status_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (t *KResource) Populate() {
// Populate ALL fields
Type: "Birthday",
Status: corev1.ConditionTrue,
LastTransitionTime: apis.VolatileTime{Inner: metav1.NewTime(time.Date(1984, 02, 28, 18, 52, 00, 00, time.UTC))},
LastTransitionTime: apis.VolatileTime{Inner: metav1.NewTime(time.Date(1984, 2, 28, 18, 52, 0, 0, time.UTC))},
Reason: "Celebrate",
Message: "n3wScott, find your party hat :tada:",
}}
Expand Down
6 changes: 4 additions & 2 deletions apis/duck/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"knative.dev/pkg/kmp"
)

type Implementable = ducktypes.Implementable
type Populatable = ducktypes.Populatable
type (
Implementable = ducktypes.Implementable
Populatable = ducktypes.Populatable
)

// VerifyType verifies that a particular concrete resource properly implements
// the provided Implementable duck type. It is expected that under the resource
Expand Down
Loading

0 comments on commit 8535fcc

Please sign in to comment.