Skip to content

Commit

Permalink
fix go vet warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
  • Loading branch information
kaovilai committed Apr 16, 2023
1 parent 65f99c1 commit 66c980f
Show file tree
Hide file tree
Showing 37 changed files with 179 additions and 107 deletions.
17 changes: 17 additions & 0 deletions hack/verify-vet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#
# Copyright 2023 the Velero contributors.
#
# 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.

go vet -mod=mod ./... || (echo "go vet is not happy, fix the errors above" && exit 1)
72 changes: 36 additions & 36 deletions internal/hook/item_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ func TestGetPodExecRestoreHookFromAnnotations(t *testing.T) {
expected: &velerov1api.ExecRestoreHook{
Command: []string{"/usr/bin/foo"},
Container: "my-app",
ExecTimeout: metav1.Duration{0},
ExecTimeout: metav1.Duration{Duration: 0},
},
},
{
Expand All @@ -805,7 +805,7 @@ func TestGetPodExecRestoreHookFromAnnotations(t *testing.T) {
expected: &velerov1api.ExecRestoreHook{
Command: []string{"/usr/bin/foo"},
Container: "my-app",
ExecTimeout: metav1.Duration{0},
ExecTimeout: metav1.Duration{Duration: 0},
},
},
}
Expand Down Expand Up @@ -856,8 +856,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand Down Expand Up @@ -886,8 +886,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -905,8 +905,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -926,8 +926,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -944,8 +944,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Exec: &velerov1api.ExecRestoreHook{
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -965,8 +965,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -984,8 +984,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container2",
Command: []string{"/usr/bin/bar"},
OnError: velerov1api.HookErrorModeFail,
ExecTimeout: metav1.Duration{time.Hour},
WaitTimeout: metav1.Duration{time.Hour},
ExecTimeout: metav1.Duration{Duration: time.Hour},
WaitTimeout: metav1.Duration{Duration: time.Hour},
},
},
},
Expand All @@ -1012,8 +1012,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand Down Expand Up @@ -1053,8 +1053,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -1075,26 +1075,26 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeFail,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
{
Exec: &velerov1api.ExecRestoreHook{
Container: "container2",
Command: []string{"/usr/bin/baz"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second * 3},
WaitTimeout: metav1.Duration{time.Second * 3},
ExecTimeout: metav1.Duration{Duration: time.Second * 3},
WaitTimeout: metav1.Duration{Duration: time.Second * 3},
},
},
{
Exec: &velerov1api.ExecRestoreHook{
Container: "container1",
Command: []string{"/usr/bin/bar"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second * 2},
WaitTimeout: metav1.Duration{time.Minute * 2},
ExecTimeout: metav1.Duration{Duration: time.Second * 2},
WaitTimeout: metav1.Duration{Duration: time.Minute * 2},
},
},
},
Expand All @@ -1108,8 +1108,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/aaa"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second * 4},
WaitTimeout: metav1.Duration{time.Minute * 4},
ExecTimeout: metav1.Duration{Duration: time.Second * 4},
WaitTimeout: metav1.Duration{Duration: time.Minute * 4},
},
},
},
Expand All @@ -1129,8 +1129,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeFail,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
{
Expand All @@ -1140,8 +1140,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/bar"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second * 2},
WaitTimeout: metav1.Duration{time.Minute * 2},
ExecTimeout: metav1.Duration{Duration: time.Second * 2},
WaitTimeout: metav1.Duration{Duration: time.Minute * 2},
},
},
{
Expand All @@ -1151,8 +1151,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/aaa"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second * 4},
WaitTimeout: metav1.Duration{time.Minute * 4},
ExecTimeout: metav1.Duration{Duration: time.Second * 4},
WaitTimeout: metav1.Duration{Duration: time.Minute * 4},
},
},
},
Expand All @@ -1164,8 +1164,8 @@ func TestGroupRestoreExecHooks(t *testing.T) {
Container: "container2",
Command: []string{"/usr/bin/baz"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second * 3},
WaitTimeout: metav1.Duration{time.Second * 3},
ExecTimeout: metav1.Duration{Duration: time.Second * 3},
WaitTimeout: metav1.Duration{Duration: time.Second * 3},
},
},
},
Expand Down
52 changes: 27 additions & 25 deletions internal/hook/wait_exec_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -115,7 +115,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
Timeout: metav1.Duration{time.Second},
Timeout: metav1.Duration{Duration: time.Second},
},
error: nil,
pod: builder.ForPod("default", "my-pod").
Expand Down Expand Up @@ -171,8 +171,8 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeFail,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -184,7 +184,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeFail,
Timeout: metav1.Duration{time.Second},
Timeout: metav1.Duration{Duration: time.Second},
},
error: errors.New("pod hook error"),
pod: builder.ForPod("default", "my-pod").
Expand Down Expand Up @@ -240,8 +240,8 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -253,7 +253,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
Timeout: metav1.Duration{time.Second},
Timeout: metav1.Duration{Duration: time.Second},
},
error: errors.New("pod hook error"),
pod: builder.ForPod("default", "my-pod").
Expand Down Expand Up @@ -309,8 +309,8 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Minute},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -322,7 +322,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
Timeout: metav1.Duration{time.Second},
Timeout: metav1.Duration{Duration: time.Second},
},
error: nil,
pod: builder.ForPod("default", "my-pod").
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeContinue,
WaitTimeout: metav1.Duration{time.Millisecond},
WaitTimeout: metav1.Duration{Duration: time.Millisecond},
},
},
},
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
Container: "container1",
Command: []string{"/usr/bin/foo"},
OnError: velerov1api.HookErrorModeFail,
WaitTimeout: metav1.Duration{time.Millisecond},
WaitTimeout: metav1.Duration{Duration: time.Millisecond},
},
},
},
Expand Down Expand Up @@ -737,8 +737,10 @@ func TestWaitExecHandleHooks(t *testing.T) {
}

ctx := context.Background()
var ctxCancel context.CancelFunc
if test.sharedHooksContextTimeout > 0 {
ctx, _ = context.WithTimeout(ctx, test.sharedHooksContextTimeout)
ctx, ctxCancel = context.WithTimeout(ctx, test.sharedHooksContextTimeout)
defer ctxCancel()
}

errs := h.HandleHooks(ctx, velerotest.NewLogger(), test.initialPod, test.byContainer)
Expand Down Expand Up @@ -878,13 +880,13 @@ func TestMaxHookWait(t *testing.T) {
"container1": {
{
Hook: velerov1api.ExecRestoreHook{
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{0},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: 0},
},
},
{
Hook: velerov1api.ExecRestoreHook{
WaitTimeout: metav1.Duration{-1},
WaitTimeout: metav1.Duration{Duration: -1},
},
},
},
Expand All @@ -897,24 +899,24 @@ func TestMaxHookWait(t *testing.T) {
"container1": {
{
Hook: velerov1api.ExecRestoreHook{
WaitTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{Duration: time.Second},
},
},
{
Hook: velerov1api.ExecRestoreHook{
WaitTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{Duration: time.Second},
},
},
},
"container2": {
{
Hook: velerov1api.ExecRestoreHook{
WaitTimeout: metav1.Duration{time.Hour},
WaitTimeout: metav1.Duration{Duration: time.Hour},
},
},
{
Hook: velerov1api.ExecRestoreHook{
WaitTimeout: metav1.Duration{time.Minute},
WaitTimeout: metav1.Duration{Duration: time.Minute},
},
},
},
Expand All @@ -927,13 +929,13 @@ func TestMaxHookWait(t *testing.T) {
"container1": {
{
Hook: velerov1api.ExecRestoreHook{
ExecTimeout: metav1.Duration{time.Second},
WaitTimeout: metav1.Duration{time.Second},
ExecTimeout: metav1.Duration{Duration: time.Second},
WaitTimeout: metav1.Duration{Duration: time.Second},
},
},
{
Hook: velerov1api.ExecRestoreHook{
WaitTimeout: metav1.Duration{0},
WaitTimeout: metav1.Duration{Duration: 0},
},
},
},
Expand Down
Loading

0 comments on commit 66c980f

Please sign in to comment.