Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unused variables #222

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/shp/cmd/build/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ func TestStartBuildRunFollowLog(t *testing.T) {
// need this reactor since the Run method uses the ObjectMeta.GenerateName k8s feature to generate the random
// name for the BuildRun. However, for our purposes with unit testing, we want to control the name of the BuildRun
// to facilitate the list/selector via labels that is also employed by the Run method.
createReactorFunc := func(action fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
createReactorFunc := func(_ fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
return true, br, nil
}
shpclientset.PrependReactor("create", "buildruns", createReactorFunc)
// need this reactor to handle returning our test BuildRun with whatever updates we make based on the various
// test bools that result in spec.state or deletion timestamp updates
getReactorFunc := func(action fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
getReactorFunc := func(_ fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
return true, br, nil
}
shpclientset.PrependReactor("get", "buildruns", getReactorFunc)
Expand Down
4 changes: 2 additions & 2 deletions pkg/shp/cmd/buildrun/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ func TestStreamBuildRunFollowLogs(t *testing.T) {
// need this reactor since the Run method uses the ObjectMeta.GenerateName k8s feature to generate the random
// name for the BuildRun. However, for our purposes with unit testing, we want to control the name of the BuildRun
// to facilitate the list/selector via labels that is also employed by the Run method.
createReactorFunc := func(action fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
createReactorFunc := func(_ fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
return true, br, nil
}
shpclientset.PrependReactor("create", "buildruns", createReactorFunc)
// need this reactor to handle returning our test BuildRun with whatever updates we make based on the various
// test bools that result in spec.state or deletion timestamp updates
getReactorFunc := func(action fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
getReactorFunc := func(_ fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
return true, br, nil
}
shpclientset.PrependReactor("get", "buildruns", getReactorFunc)
Expand Down
4 changes: 2 additions & 2 deletions pkg/shp/cmd/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ func TestCMD_Runner(t *testing.T) {
genericStreams := &genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
r := NewRunner(p, genericStreams, &mockedSubCommand{})

t.Run("cmd", func(t *testing.T) {
t.Run("cmd", func(_ *testing.T) {
cmd := r.Cmd()

g.Expect(cmd.RunE).ToNot(gomega.BeNil())
})

t.Run("RunE", func(t *testing.T) {
t.Run("RunE", func(_ *testing.T) {
err := r.RunE(testCmd, []string{})

g.Expect(err).To(gomega.BeNil())
Expand Down
2 changes: 1 addition & 1 deletion pkg/shp/cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Command() *cobra.Command {
Annotations: map[string]string{
"commandType": "main",
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
if version == "" {
version = "development"
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/shp/flags/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestBuildSpecFromFlags(t *testing.T) {
flags := cmd.PersistentFlags()
spec := BuildSpecFromFlags(flags)

t.Run(".spec.source", func(t *testing.T) {
t.Run(".spec.source", func(_ *testing.T) {
err := flags.Set(SourceURLFlag, *expected.Source.URL)
g.Expect(err).To(o.BeNil())

Expand All @@ -82,7 +82,7 @@ func TestBuildSpecFromFlags(t *testing.T) {
g.Expect(expected.Source).To(o.Equal(spec.Source), "spec.source")
})

t.Run(".spec.strategy", func(t *testing.T) {
t.Run(".spec.strategy", func(_ *testing.T) {
err := flags.Set(StrategyKindFlag, string(buildv1alpha1.ClusterBuildStrategyKind))
g.Expect(err).To(o.BeNil())

Expand All @@ -92,15 +92,15 @@ func TestBuildSpecFromFlags(t *testing.T) {
g.Expect(expected.Strategy).To(o.Equal(spec.Strategy), "spec.strategy")
})

t.Run(".spec.dockerfile", func(t *testing.T) {
t.Run(".spec.dockerfile", func(_ *testing.T) {
err := flags.Set(DockerfileFlag, *expected.Dockerfile)
g.Expect(err).To(o.BeNil())

g.Expect(spec.Dockerfile).NotTo(o.BeNil())
g.Expect(*expected.Dockerfile).To(o.Equal(*spec.Dockerfile), "spec.dockerfile")
})

t.Run(".spec.builder", func(t *testing.T) {
t.Run(".spec.builder", func(_ *testing.T) {
err := flags.Set(BuilderImageFlag, expected.Builder.Image)
g.Expect(err).To(o.BeNil())

Expand All @@ -110,7 +110,7 @@ func TestBuildSpecFromFlags(t *testing.T) {
g.Expect(*expected.Builder).To(o.Equal(*spec.Builder), "spec.builder")
})

t.Run(".spec.output", func(t *testing.T) {
t.Run(".spec.output", func(_ *testing.T) {
err := flags.Set(OutputImageFlag, expected.Output.Image)
g.Expect(err).To(o.BeNil())

Expand All @@ -123,35 +123,35 @@ func TestBuildSpecFromFlags(t *testing.T) {
g.Expect(expected.Output).To(o.Equal(spec.Output), "spec.output")
})

t.Run(".spec.timeout", func(t *testing.T) {
t.Run(".spec.timeout", func(_ *testing.T) {
err := flags.Set(TimeoutFlag, expected.Timeout.Duration.String())
g.Expect(err).To(o.BeNil())

g.Expect(*expected.Timeout).To(o.Equal(*spec.Timeout), "spec.timeout")
})

t.Run(".spec.retention.failedLimit", func(t *testing.T) {
t.Run(".spec.retention.failedLimit", func(_ *testing.T) {
err := flags.Set(RetentionFailedLimitFlag, strconv.FormatUint(uint64(*expected.Retention.FailedLimit), 10))
g.Expect(err).To(o.BeNil())

g.Expect(*expected.Retention.FailedLimit).To(o.Equal(*spec.Retention.FailedLimit), "spec.retention.failedLimit")
})

t.Run(".spec.retention.succeededLimit", func(t *testing.T) {
t.Run(".spec.retention.succeededLimit", func(_ *testing.T) {
err := flags.Set(RetentionSucceededLimitFlag, strconv.FormatUint(uint64(*expected.Retention.SucceededLimit), 10))
g.Expect(err).To(o.BeNil())

g.Expect(*expected.Retention.SucceededLimit).To(o.Equal(*spec.Retention.SucceededLimit), "spec.retention.succeededLimit")
})

t.Run(".spec.retention.ttlAfterFailed", func(t *testing.T) {
t.Run(".spec.retention.ttlAfterFailed", func(_ *testing.T) {
err := flags.Set(RetentionTTLAfterFailedFlag, expected.Retention.TTLAfterFailed.Duration.String())
g.Expect(err).To(o.BeNil())

g.Expect(*expected.Retention.TTLAfterFailed).To(o.Equal(*spec.Retention.TTLAfterFailed), "spec.retention.ttlAfterFailed")
})

t.Run(".spec.retention.ttlAfterSucceeded", func(t *testing.T) {
t.Run(".spec.retention.ttlAfterSucceeded", func(_ *testing.T) {
err := flags.Set(RetentionTTLAfterSucceededFlag, expected.Retention.TTLAfterSucceeded.Duration.String())
g.Expect(err).To(o.BeNil())

Expand Down Expand Up @@ -276,7 +276,7 @@ func TestSanitizeBuildSpec(t *testing.T) {
}}

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
t.Run(tt.name, func(_ *testing.T) {
aCopy := tt.in.DeepCopy()
SanitizeBuildSpec(aCopy)
g.Expect(tt.out).To(o.Equal(*aCopy))
Expand Down
14 changes: 7 additions & 7 deletions pkg/shp/flags/buildrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ func TestBuildRunSpecFromFlags(t *testing.T) {
flags := cmd.PersistentFlags()
spec := BuildRunSpecFromFlags(flags)

t.Run(".spec.buildRef", func(t *testing.T) {
t.Run(".spec.buildRef", func(_ *testing.T) {
err := flags.Set(BuildrefNameFlag, expected.BuildRef.Name)
g.Expect(err).To(o.BeNil())

g.Expect(*expected.BuildRef).To(o.Equal(*spec.BuildRef), "spec.buildRef")
})

t.Run(".spec.serviceAccount", func(t *testing.T) {
t.Run(".spec.serviceAccount", func(_ *testing.T) {
err := flags.Set(ServiceAccountNameFlag, *expected.ServiceAccount.Name)
g.Expect(err).To(o.BeNil())

Expand All @@ -67,14 +67,14 @@ func TestBuildRunSpecFromFlags(t *testing.T) {
g.Expect(*expected.ServiceAccount).To(o.Equal(*spec.ServiceAccount), "spec.serviceAccount")
})

t.Run(".spec.timeout", func(t *testing.T) {
t.Run(".spec.timeout", func(_ *testing.T) {
err := flags.Set(TimeoutFlag, expected.Timeout.Duration.String())
g.Expect(err).To(o.BeNil())

g.Expect(*expected.Timeout).To(o.Equal(*spec.Timeout), "spec.timeout")
})

t.Run(".spec.output", func(t *testing.T) {
t.Run(".spec.output", func(_ *testing.T) {
err := flags.Set(OutputImageFlag, expected.Output.Image)
g.Expect(err).To(o.BeNil())

Expand All @@ -84,14 +84,14 @@ func TestBuildRunSpecFromFlags(t *testing.T) {
g.Expect(*expected.Output).To(o.Equal(*spec.Output), "spec.output")
})

t.Run(".spec.retention.ttlAfterFailed", func(t *testing.T) {
t.Run(".spec.retention.ttlAfterFailed", func(_ *testing.T) {
err := flags.Set(RetentionTTLAfterFailedFlag, expected.Retention.TTLAfterFailed.Duration.String())
g.Expect(err).To(o.BeNil())

g.Expect(*expected.Retention.TTLAfterFailed).To(o.Equal(*spec.Retention.TTLAfterFailed), "spec.retention.ttlAfterFailed")
})

t.Run(".spec.retention.ttlAfterSucceeded", func(t *testing.T) {
t.Run(".spec.retention.ttlAfterSucceeded", func(_ *testing.T) {
err := flags.Set(RetentionTTLAfterSucceededFlag, expected.Retention.TTLAfterSucceeded.Duration.String())
g.Expect(err).To(o.BeNil())

Expand Down Expand Up @@ -146,7 +146,7 @@ func TestSanitizeBuildRunSpec(t *testing.T) {
}}

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
t.Run(tt.name, func(_ *testing.T) {
aCopy := tt.in.DeepCopy()
SanitizeBuildRunSpec(aCopy)
g.Expect(tt.out).To(o.Equal(*aCopy))
Expand Down
2 changes: 1 addition & 1 deletion pkg/shp/params/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestParamsCreation(t *testing.T) {
g.Expect(err).To(gomega.BeNil(), "Must not be an error during client creation")
g.Expect(client).ToNot(gomega.BeNil(), "Client must not be nil")

t.Run("Namespace", func(t *testing.T) {
t.Run("Namespace", func(_ *testing.T) {
ns := shpParams.Namespace()

g.Expect(ns).To(gomega.Equal("test"))
Expand Down
16 changes: 8 additions & 8 deletions pkg/shp/reactor/pod_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_PodWatcher_RequestTimeout(t *testing.T) {
g.Expect(err).To(o.BeNil())
called := false

pw.WithTimeoutPodFn(func(msg string) {
pw.WithTimeoutPodFn(func(_ string) {
called = true
})

Expand All @@ -45,7 +45,7 @@ func Test_PodWatcher_ContextTimeout(t *testing.T) {
g.Expect(err).To(o.BeNil())
called := false

pw.WithTimeoutPodFn(func(msg string) {
pw.WithTimeoutPodFn(func(_ string) {
called = true
})

Expand All @@ -68,7 +68,7 @@ func Test_PodWatcher_NotCalledYet(t *testing.T) {
eventsDoneCh := make(chan bool, 1)

called := false
pw.WithNoPodEventsYetFn(func(podList *corev1.PodList) {
pw.WithNoPodEventsYetFn(func(_ *corev1.PodList) {
called = true
eventsCh <- true
})
Expand Down Expand Up @@ -100,7 +100,7 @@ func Test_PodWatcher_NotCalledYet_AllEventsBeforeWatchStart(t *testing.T) {
clientset := fake.NewSimpleClientset()
// set up lister that will return pod, but we don't create/update a Pod, thus we do not trigger
// events on the watch; mimics a Pod completing before the watch is established.
listReactorFunc := func(action fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
listReactorFunc := func(_ fakekubetesting.Action) (handled bool, ret kruntime.Object, err error) {
pod := corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -166,16 +166,16 @@ func Test_PodWatcherEvents(t *testing.T) {

// adding functions to be triggered on all types of events, and sending the function name over
// the events channel
pw.WithSkipPodFn(func(pod *corev1.Pod) bool {
pw.WithSkipPodFn(func(_ *corev1.Pod) bool {
eventsCh <- skipPODFn
return false
}).WithOnPodAddedFn(func(pod *corev1.Pod) error {
}).WithOnPodAddedFn(func(_ *corev1.Pod) error {
eventsCh <- onPodAddedFn
return nil
}).WithOnPodDeletedFn(func(pod *corev1.Pod) error {
}).WithOnPodDeletedFn(func(_ *corev1.Pod) error {
eventsCh <- onPodDeletedFn
return nil
}).WithOnPodModifiedFn(func(pod *corev1.Pod) error {
}).WithOnPodModifiedFn(func(_ *corev1.Pod) error {
eventsCh <- onPodModifiedFn
return nil
})
Expand Down
Loading