From 2c9bbc54409f757da8b7f87e343420b8b7306320 Mon Sep 17 00:00:00 2001 From: Dibyo Mukherjee Date: Mon, 8 Jul 2019 16:16:13 -0400 Subject: [PATCH] Format go files using go fmt --- cmd/imagedigestexporter/main.go | 2 +- cmd/pullrequest-init/github_test.go | 14 ++++----- pkg/apis/pipeline/v1alpha1/param_types.go | 2 +- .../taskrun/resources/image_exporter_test.go | 30 +++++++++---------- pkg/status/stepstatesorter.go | 8 ++--- pkg/status/stepstatesorter_test.go | 7 ++--- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/cmd/imagedigestexporter/main.go b/cmd/imagedigestexporter/main.go index 6d9b3dcea3d..757c4d03204 100644 --- a/cmd/imagedigestexporter/main.go +++ b/cmd/imagedigestexporter/main.go @@ -27,7 +27,7 @@ import ( ) var ( - images = flag.String("images", "", "List of images resources built by task in json format") + images = flag.String("images", "", "List of images resources built by task in json format") terminationMessagePath = flag.String("terminationMessagePath", "", "Location of file containing termination message") ) diff --git a/cmd/pullrequest-init/github_test.go b/cmd/pullrequest-init/github_test.go index 432bbd44306..8ee51703b23 100644 --- a/cmd/pullrequest-init/github_test.go +++ b/cmd/pullrequest-init/github_test.go @@ -62,7 +62,7 @@ func TestGitHubParseURL(t *testing.T) { wantRepo := "repo" wantPR := 1 - for _, tt := range []struct{ + for _, tt := range []struct { url string wantHost string }{ @@ -112,10 +112,10 @@ func TestGitHubParseURL_errors(t *testing.T) { func TestNewGitHubHandler(t *testing.T) { ctx := context.Background() - for _, tt := range []struct{ + for _, tt := range []struct { in string out string - } { + }{ {"https://github.com/tektoncd/pipeline/pull/1", "api.github.com"}, {"https://github.tekton.dev/tektoncd/pipeline/pull/1", "github.tekton.dev"}, } { @@ -325,16 +325,16 @@ func diffFile(t *testing.T, path string, want interface{}, got interface{}) { } func TestParseGitHubURL(t *testing.T) { - good := []struct{ - url string + good := []struct { + url string wantHost string - } { + }{ {fmt.Sprintf("https://github.com/%s/%s/pull/%d", owner, repo, prNum), "https://github.com"}, {fmt.Sprintf("https://github.com/%s/%s/foo/%d", owner, repo, prNum), "https://github.com"}, {fmt.Sprintf("http://github.com/%s/%s/pull/%d", owner, repo, prNum), "http://github.com"}, {fmt.Sprintf("tacocat://github.com/%s/%s/pull/%d", owner, repo, prNum), "tacocat://github.com"}, {fmt.Sprintf("https://example.com/%s/%s/pull/%d", owner, repo, prNum), "https://example.com"}, - {fmt.Sprintf("https://github.com/%s/%s/pull/%d/foo", owner, repo, prNum), "https://github.com"}, + {fmt.Sprintf("https://github.com/%s/%s/pull/%d/foo", owner, repo, prNum), "https://github.com"}, {fmt.Sprintf("github.com/%s/%s/pull/%d/foo", owner, repo, prNum), "://"}, } for _, u := range good { diff --git a/pkg/apis/pipeline/v1alpha1/param_types.go b/pkg/apis/pipeline/v1alpha1/param_types.go index 48c6e7b4bc9..0c30fffd52e 100644 --- a/pkg/apis/pipeline/v1alpha1/param_types.go +++ b/pkg/apis/pipeline/v1alpha1/param_types.go @@ -37,4 +37,4 @@ type ParamSpec struct { type Param struct { Name string `json:"name"` Value string `json:"value"` -} \ No newline at end of file +} diff --git a/pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go b/pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go index f117650c70b..2f5cb4a7d31 100644 --- a/pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go +++ b/pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go @@ -89,11 +89,11 @@ func TestAddOutputImageDigestExporter(t *testing.T) { Name: "step1", }, { - Name: "image-digest-exporter-step1-9l9zj", - Image: "override-with-imagedigest-exporter-image:latest", - Command: []string{"/ko-app/imagedigestexporter"}, - Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir), - "-terminationMessagePath", "/builder/home/image-outputs/termination-log"}, + Name: "image-digest-exporter-step1-9l9zj", + Image: "override-with-imagedigest-exporter-image:latest", + Command: []string{"/ko-app/imagedigestexporter"}, + Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir), + "-terminationMessagePath", "/builder/home/image-outputs/termination-log"}, TerminationMessagePath: TerminationMessagePath, TerminationMessagePolicy: "FallbackToLogsOnError", }}, @@ -154,21 +154,21 @@ func TestAddOutputImageDigestExporter(t *testing.T) { Name: "step1", }, { - Name: "image-digest-exporter-step1-9l9zj", - Image: "override-with-imagedigest-exporter-image:latest", - Command: []string{"/ko-app/imagedigestexporter"}, - Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir), - "-terminationMessagePath", "/builder/home/image-outputs/termination-log"}, + Name: "image-digest-exporter-step1-9l9zj", + Image: "override-with-imagedigest-exporter-image:latest", + Command: []string{"/ko-app/imagedigestexporter"}, + Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir), + "-terminationMessagePath", "/builder/home/image-outputs/termination-log"}, TerminationMessagePath: TerminationMessagePath, TerminationMessagePolicy: "FallbackToLogsOnError", }, { Name: "step2", }, { - Name: "image-digest-exporter-step2-mz4c7", - Image: "override-with-imagedigest-exporter-image:latest", - Command: []string{"/ko-app/imagedigestexporter"}, - Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir), - "-terminationMessagePath", "/builder/home/image-outputs/termination-log"}, + Name: "image-digest-exporter-step2-mz4c7", + Image: "override-with-imagedigest-exporter-image:latest", + Command: []string{"/ko-app/imagedigestexporter"}, + Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir), + "-terminationMessagePath", "/builder/home/image-outputs/termination-log"}, TerminationMessagePath: TerminationMessagePath, TerminationMessagePolicy: "FallbackToLogsOnError", }, diff --git a/pkg/status/stepstatesorter.go b/pkg/status/stepstatesorter.go index 73c0f50c525..5812698786e 100644 --- a/pkg/status/stepstatesorter.go +++ b/pkg/status/stepstatesorter.go @@ -14,17 +14,17 @@ package status import ( + "sort" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" corev1 "k8s.io/api/core/v1" - "sort" ) - // StepStateSorter implements a sorting mechanism to align the order of the steps in TaskRun // with the spec steps in Task. type StepStateSorter struct { taskRunSteps []v1alpha1.StepState - mapForSort map[string]int + mapForSort map[string]int } func (trt *StepStateSorter) Init(taskRunSteps []v1alpha1.StepState, taskSpecSteps []corev1.Container) { @@ -62,7 +62,7 @@ func (trt *StepStateSorter) Swap(i, j int) { trt.changeIndex(j) // The index j is unable to reach the last index. // When i reaches the end of the array, we need to check whether the last one needs a swap. - if (i == trt.Len() - 1 ) { + if i == trt.Len()-1 { trt.changeIndex(i) } } diff --git a/pkg/status/stepstatesorter_test.go b/pkg/status/stepstatesorter_test.go index 78df9e71a9c..3aee10b04a3 100644 --- a/pkg/status/stepstatesorter_test.go +++ b/pkg/status/stepstatesorter_test.go @@ -14,11 +14,12 @@ package status import ( + "testing" + "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" tb "github.com/tektoncd/pipeline/test/builder" corev1 "k8s.io/api/core/v1" - "testing" ) func TestSortTaskRunStepOrder(t *testing.T) { @@ -42,7 +43,6 @@ func TestSortTaskRunStepOrder(t *testing.T) { }, }, Name: "world", - }, { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ @@ -59,7 +59,6 @@ func TestSortTaskRunStepOrder(t *testing.T) { }, }, Name: "hello", - }, { ContainerState: corev1.ContainerState{ @@ -73,7 +72,7 @@ func TestSortTaskRunStepOrder(t *testing.T) { SortTaskRunStepOrder(taskRunStatusSteps, task.Spec.Steps) actualStepOrder := []string{} - for _, state := range(taskRunStatusSteps) { + for _, state := range taskRunStatusSteps { actualStepOrder = append(actualStepOrder, state.Name) }