Skip to content

Commit

Permalink
chore: fix golanglint, checkout prior to setup-go (#3206)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Peabody <[email protected]>
  • Loading branch information
apeabody authored Jan 6, 2024
1 parent 7cd4ba6 commit 5325522
Show file tree
Hide file tree
Showing 36 changed files with 125 additions and 126 deletions.
28 changes: 17 additions & 11 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@ jobs:
with:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: "1.21"
check-latest: true
- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

# source: https://github.com/golangci/golangci-lint-action
- name: golangci-lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
# version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.51.2
version: v1.54.2

test:
name: "Unit test"
Expand All @@ -61,13 +62,14 @@ jobs:
with:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: "1.21"
check-latest: true
- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Unit test
run: make native-test
Expand All @@ -90,7 +92,8 @@ jobs:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3.5.2
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
Expand All @@ -114,13 +117,14 @@ jobs:
with:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: "1.21"
check-latest: true
- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Download e2e dependencies
run: |
Expand All @@ -145,13 +149,14 @@ jobs:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: "1.21"
check-latest: true

- name: Bootstrap e2e
run: |
mkdir -p $GITHUB_WORKSPACE/bin
Expand Down Expand Up @@ -203,7 +208,7 @@ jobs:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Bootstrap e2e
run: |
Expand Down Expand Up @@ -265,13 +270,14 @@ jobs:
egress-policy: audit

- name: Check out code into the Go module directory
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: "1.21"
check-latest: true

- name: Bootstrap e2e
run: |
mkdir -p $GITHUB_WORKSPACE/bin
Expand Down
5 changes: 2 additions & 3 deletions apis/status/v1beta1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ func dashExtractor(val string) []string {
b.WriteRune(chr)
prevDash = false
continue
} else {
prevDash = true
continue
}
prevDash = true
continue
}
b.WriteRune(chr)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gator/expand/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func init() {
Cmd.Flags().StringVarP(&flagTempDir, flagNameTempDir, "d", "", fmt.Sprintf("Specifies the temporary directory to download and unpack images to, if using the --%s flag. Optional.", flagNameImage))
}

func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, _ []string) {
unstrucs, err := reader.ReadSources(flagFilenames, flagImages, flagTempDir)
if err != nil {
util.ErrFatalf("reading: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gator/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func init() {
Cmd.Flags().StringVarP(&flagTempDir, flagNameTempDir, "d", "", fmt.Sprintf("Specifies the temporary directory to download and unpack images to, if using the --%s flag. Optional.", flagNameImage))
}

func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, _ []string) {
unstrucs, err := reader.ReadSources(flagFilenames, flagImages, flagTempDir)
if err != nil {
cmdutils.ErrFatalf("reading: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/cachemanager/cachemanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func TestCacheManager_AddObject(t *testing.T) {
}

for _, tc := range tcs {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.cm.AddObject(context.Background(), &unstructured.Unstructured{Object: unstructuredPod})
if tc.expectedMetricStatus == metrics.ActiveStatus {
Expand Down Expand Up @@ -762,7 +763,7 @@ type fakeRegistrar struct {
generalErr error
}

func (f *fakeRegistrar) ReplaceWatch(ctx context.Context, gvks []schema.GroupVersionKind) error {
func (f *fakeRegistrar) ReplaceWatch(_ context.Context, _ []schema.GroupVersionKind) error {
err := watch.NewErrorList()
if f.generalErr != nil {
err.Err(f.generalErr)
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/expansion/expansion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func TestAddStatusError(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
setStatusError(&tc.inputStatus, tc.etErr)
if diff := cmp.Diff(tc.inputStatus, tc.wantStatus); diff != "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/expansionstatus/expansionstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type Adder struct {
WatchManager *watch.Manager
}

func (a *Adder) InjectControllerSwitch(cs *watch.ControllerSwitch) {}
func (a *Adder) InjectControllerSwitch(_ *watch.ControllerSwitch) {}

func (a *Adder) InjectTracker(t *readiness.Tracker) {}
func (a *Adder) InjectTracker(_ *readiness.Tracker) {}

// Add creates a new Constraint Status Controller and adds it to the Manager. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/externaldata/externaldata_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (a *Adder) InjectCFClient(c *constraintclient.Client) {
a.CFClient = c
}

func (a *Adder) InjectControllerSwitch(cs *watch.ControllerSwitch) {}
func (a *Adder) InjectControllerSwitch(_ *watch.ControllerSwitch) {}

func (a *Adder) InjectTracker(t *readiness.Tracker) {
a.Tracker = t
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/mutators/core/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (r *Reconciler) defaultGetPod(_ context.Context) (*corev1.Pod, error) {
panic("GetPod must be injected to Reconciler")
}

func (r *Reconciler) reportMutator(id types.ID, ingestionStatus ctrlmutators.MutatorIngestionStatus, startTime time.Time, deleted bool) {
func (r *Reconciler) reportMutator(_ types.ID, ingestionStatus ctrlmutators.MutatorIngestionStatus, startTime time.Time, deleted bool) {
if r.reporter == nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/mutators/instances/mutator_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (a *Adder) Add(mgr manager.Manager) error {
return assignMetadata.Add(mgr)
}

func (a *Adder) InjectControllerSwitch(cs *watch.ControllerSwitch) {}
func (a *Adder) InjectControllerSwitch(_ *watch.ControllerSwitch) {}

func (a *Adder) InjectTracker(t *readiness.Tracker) {
a.Tracker = t
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/mutatorstatus/mutatorstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ type Adder struct {
ControllerSwitch *watch.ControllerSwitch
}

func (a *Adder) InjectControllerSwitch(cs *watch.ControllerSwitch) {}
func (a *Adder) InjectControllerSwitch(_ *watch.ControllerSwitch) {}

func (a *Adder) InjectTracker(t *readiness.Tracker) {}
func (a *Adder) InjectTracker(_ *readiness.Tracker) {}

// Add creates a new Mutator Status Controller and adds it to the Manager. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/syncset/syncset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (a *Adder) InjectCacheManager(o *cm.CacheManager) {
a.CacheManager = o
}

func (a *Adder) InjectControllerSwitch(cs *watch.ControllerSwitch) {
func (a *Adder) InjectControllerSwitch(_ *watch.ControllerSwitch) {
}

func (a *Adder) InjectTracker(t *readiness.Tracker) {
Expand Down
1 change: 1 addition & 0 deletions pkg/expansion/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ func TestValidateTemplate(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
tc.errFn(ValidateTemplate(&tc.temp), t)
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/fakes/fakecfdataclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func KeyFor(obj interface{}) (CfDataKey, error) {
return CfDataKey{Gvk: gvk, Key: fmt.Sprintf("%s/%s", ns, o.GetName())}, nil
}

func (f *FakeCfClient) AddData(ctx context.Context, data interface{}) (*constraintTypes.Responses, error) {
func (f *FakeCfClient) AddData(_ context.Context, data interface{}) (*constraintTypes.Responses, error) {
f.mu.Lock()
defer f.mu.Unlock()

Expand All @@ -73,7 +73,7 @@ func (f *FakeCfClient) AddData(ctx context.Context, data interface{}) (*constrai
return &constraintTypes.Responses{}, nil
}

func (f *FakeCfClient) RemoveData(ctx context.Context, data interface{}) (*constraintTypes.Responses, error) {
func (f *FakeCfClient) RemoveData(_ context.Context, data interface{}) (*constraintTypes.Responses, error) {
f.mu.Lock()
defer f.mu.Unlock()

Expand Down
8 changes: 4 additions & 4 deletions pkg/gator/verify/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type Filter interface {
// MatchesTest returns true if the Test should be run.
MatchesTest(Test) bool
MatchesTest(*Test) bool
// MatchesCase returns true if Case caseName in Test testName should be run.
MatchesCase(testName, caseName string) bool
}
Expand Down Expand Up @@ -68,7 +68,7 @@ type nilFilter struct{}

var _ Filter = &nilFilter{}

func (f *nilFilter) MatchesTest(Test) bool {
func (f *nilFilter) MatchesTest(*Test) bool {
return true
}

Expand All @@ -93,7 +93,7 @@ func newOrFilter(filter string) (Filter, error) {
return &orFilter{regex: regex}, nil
}

func (f *orFilter) MatchesTest(t Test) bool {
func (f *orFilter) MatchesTest(t *Test) bool {
if f.regex.MatchString(t.Name) {
return true
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func newAndFilter(testFilter, caseFilter string) (Filter, error) {
return &andFilter{testRegex: testRegex, caseRegex: caseRegex}, nil
}

func (f *andFilter) MatchesTest(t Test) bool {
func (f *andFilter) MatchesTest(t *Test) bool {
return f.testRegex.MatchString(t.Name)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gator/verify/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestFilter_MatchesTest(t *testing.T) {
t.Fatal(err)
}

got := filter.MatchesTest(tc.test)
got := filter.MatchesTest(&tc.test)
if got != tc.want {
t.Errorf("got MatchesTest(%q) = %t, want %t", tc.test.Name, got, tc.want)
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/gator/verify/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,24 @@ func (r *Runner) runTests(ctx context.Context, filter Filter, suitePath string,

results := make([]TestResult, len(tests))
for i, t := range tests {
if t.Skip || !filter.MatchesTest(t) {
results[i] = r.skipTest(t)
t := t
if t.Skip || !filter.MatchesTest(&t) {
results[i] = r.skipTest(&t)
continue
}

results[i] = r.runTest(ctx, suiteDir, filter, t)
results[i] = r.runTest(ctx, suiteDir, filter, &t)
}

return results, nil
}

func (r *Runner) skipTest(t Test) TestResult {
func (r *Runner) skipTest(t *Test) TestResult {
return TestResult{Name: t.Name, Skipped: true}
}

// runTest runs an individual Test.
func (r *Runner) runTest(ctx context.Context, suiteDir string, filter Filter, t Test) TestResult {
func (r *Runner) runTest(ctx context.Context, suiteDir string, filter Filter, t *Test) TestResult {
start := time.Now()

err := r.tryAddConstraint(ctx, suiteDir, t)
Expand All @@ -140,7 +141,7 @@ func (r *Runner) runTest(ctx context.Context, suiteDir string, filter Filter, t
}
}

func (r *Runner) tryAddConstraint(ctx context.Context, suiteDir string, t Test) error {
func (r *Runner) tryAddConstraint(ctx context.Context, suiteDir string, t *Test) error {
client, err := r.newClient(r.includeTrace, r.useK8sCEL)
if err != nil {
return fmt.Errorf("%w: %w", gator.ErrCreatingClient, err)
Expand All @@ -167,7 +168,7 @@ func (r *Runner) tryAddConstraint(ctx context.Context, suiteDir string, t Test)

// runCases executes every Case in the Test. Returns the results for every Case,
// or an error if there was a problem executing the Test.
func (r *Runner) runCases(ctx context.Context, suiteDir string, filter Filter, t Test) ([]CaseResult, error) {
func (r *Runner) runCases(ctx context.Context, suiteDir string, filter Filter, t *Test) ([]CaseResult, error) {
newClient := func() (gator.Client, error) {
c, err := r.makeTestClient(ctx, suiteDir, t)
if err != nil {
Expand Down Expand Up @@ -195,7 +196,7 @@ func (r *Runner) skipCase(tc *Case) CaseResult {
return CaseResult{Name: tc.Name, Skipped: true}
}

func (r *Runner) makeTestClient(ctx context.Context, suiteDir string, t Test) (gator.Client, error) {
func (r *Runner) makeTestClient(ctx context.Context, suiteDir string, t *Test) (gator.Client, error) {
client, err := r.newClient(r.includeTrace, r.useK8sCEL)
if err != nil {
return nil, fmt.Errorf("%w: %w", gator.ErrCreatingClient, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ type runner struct {
}

func AddToManager(m manager.Manager) error {
mr := new(m)
mr := create(m)
return m.Add(mr)
}

func new(mgr manager.Manager) *runner {
func create(mgr manager.Manager) *runner {
mr := &runner{
mgr: mgr,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func (es *exporterSet) Set(s string) error {
splt := strings.Split(s, ",")
for _, v := range splt {
lower := strings.ToLower(v)
new, ok := es.registeredExporters[lower]
newExporter, ok := es.registeredExporters[lower]
if !ok {
return fmt.Errorf("exporter %s is not a valid exporter: %v", v, es.validExporters)
}
es.assignedExporters[lower] = new
es.assignedExporters[lower] = newExporter
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/mutation/match/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ func TestMatch(t *testing.T) {
}

for _, tc := range table {
tc := tc
t.Run(tc.name, func(t *testing.T) {
m := &Matchable{Object: tc.object, Namespace: tc.namespace, Source: tc.source}
matches, err := Matches(&tc.matcher, m)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (s *notKeyedSetter) KeyedListValue() (map[string]interface{}, error) {
panic("notKeyedSetter setter does not handle keyed lists")
}

func (s *notKeyedSetter) SetValue(obj map[string]interface{}, key string) error {
func (s *notKeyedSetter) SetValue(_ map[string]interface{}, _ string) error {
panic("NOT IMPLEMENTED")
}

Expand Down
Loading

0 comments on commit 5325522

Please sign in to comment.