From 71368c6a1dbea99e04c38aad238129d66a78c239 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Wed, 8 Sep 2021 09:53:45 -0400 Subject: [PATCH] chore: update files with goimport (#513) * chore: update files with goimport This should get https://github.com/knative-sandbox/kn-plugin-func/pull/509 happy and green. Signed-off-by: Lance Ball * fixup: remove extraneous print statements Signed-off-by: Lance Ball --- client.go | 2 +- cmd/config.go | 3 +- cmd/config_labels_test.go | 41 +++++++++---------- cmd/func/main.go | 3 +- cmd/version.go | 6 +-- config_test.go | 2 +- docker/credentials_helper.go | 5 ++- docker/credentials_helper_test.go | 5 +-- k8s/client.go | 1 - knative/lister.go | 1 + mock/builder.go | 1 + mock/lister.go | 1 + mock/runner.go | 1 + test/_e2e/cmd_build_test.go | 2 +- test/_e2e/cmd_delete_test.go | 2 +- test/_e2e/cmd_deploy_test.go | 2 +- test/_e2e/cmd_list_test.go | 2 +- test/_e2e/config.go | 2 +- test/_e2e/e2e_remote_repository_test.go | 2 +- test/_e2e/main_test.go | 10 ++--- test/_e2e/ready_check_test.go | 5 ++- test/_e2e/shell_cmd_runner.go | 5 +-- test/_e2e/trigger_http_test.go | 8 ++-- .../go/customTemplate/custom.go | 1 + .../repositoryTests/go/custom/custom.go | 1 + 25 files changed, 60 insertions(+), 54 deletions(-) diff --git a/client.go b/client.go index f34b29a3..39f0a210 100644 --- a/client.go +++ b/client.go @@ -8,9 +8,9 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "sort" "sync" - "runtime" "gopkg.in/yaml.v2" ) diff --git a/cmd/config.go b/cmd/config.go index 71857af6..84a4e96b 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/AlecAivazis/survey/v2" "github.com/AlecAivazis/survey/v2/terminal" "github.com/ory/viper" @@ -23,7 +24,7 @@ type functionLoaderSaver interface { functionSaver } -type standardLoaderSaver struct {} +type standardLoaderSaver struct{} func (s standardLoaderSaver) Load(path string) (fn.Function, error) { f, err := fn.NewFunction(path) diff --git a/cmd/config_labels_test.go b/cmd/config_labels_test.go index 4ceee9af..7680526b 100644 --- a/cmd/config_labels_test.go +++ b/cmd/config_labels_test.go @@ -4,15 +4,16 @@ package cmd import ( "context" - "github.com/Netflix/go-expect" - "github.com/hinshun/vt10x" - "github.com/spf13/cobra" - fn "knative.dev/kn-plugin-func" "os" "reflect" "sync" "testing" "time" + + "github.com/Netflix/go-expect" + "github.com/hinshun/vt10x" + "github.com/spf13/cobra" + fn "knative.dev/kn-plugin-func" ) type mockFunctionLoaderSaver struct { @@ -49,21 +50,21 @@ func createRunFunc(cmd *cobra.Command, t *testing.T) func(subcmd string, input . wg.Add(1) go func() { //defer wg.Done() - _,_ = c.ExpectEOF() + _, _ = c.ExpectEOF() }() go func() { defer wg.Done() - time.Sleep(time.Millisecond*50) + time.Sleep(time.Millisecond * 50) for _, s := range input { _, _ = c.Send(s) - time.Sleep(time.Millisecond*50) + time.Sleep(time.Millisecond * 50) } }() a := []string{subcmd} cmd.SetArgs(a) - func () { + func() { defer withMockedStdio(t, c)() err = cmd.ExecuteContext(ctx) wg.Wait() @@ -93,9 +94,9 @@ func withMockedStdio(t *testing.T, c *expect.Console) func() { } const ( - arrowUp = "\033[A" + arrowUp = "\033[A" arrowDown = "\033[B" - enter = "\r" + enter = "\r" ) func TestNewConfigLabelsCmd(t *testing.T) { @@ -107,33 +108,31 @@ func TestNewConfigLabelsCmd(t *testing.T) { run := createRunFunc(cmd, t) - - p := func (k,v string) fn.Label { + p := func(k, v string) fn.Label { return fn.Label{Key: &k, Value: &v} } - assertLabel := func (ps fn.Labels) { + assertLabel := func(ps fn.Labels) { t.Helper() assertLabelEq(t, *labels, ps) } run("add", enter, "a", enter, "b", enter) - assertLabel(fn.Labels{p("a","b")}) + assertLabel(fn.Labels{p("a", "b")}) run("add", enter, enter, "c", enter, "d", enter) - assertLabel(fn.Labels{p("a","b"), p("c", "d")}) + assertLabel(fn.Labels{p("a", "b"), p("c", "d")}) run("add", arrowUp, arrowUp, enter, enter, "e", enter, "f", enter) - assertLabel( fn.Labels{p("e","f"), p("a","b"), p("c", "d")}) + assertLabel(fn.Labels{p("e", "f"), p("a", "b"), p("c", "d")}) run("remove", arrowDown, enter) - assertLabel(fn.Labels{p("e","f"), p("c", "d")}) + assertLabel(fn.Labels{p("e", "f"), p("c", "d")}) } - func TestListLabels(t *testing.T) { - p := func (k,v string) fn.Label { + p := func(k, v string) fn.Label { return fn.Label{Key: &k, Value: &v} } @@ -154,7 +153,7 @@ func TestListLabels(t *testing.T) { cmd.SetArgs(make([]string, 0)) errChan := make(chan error, 1) - func () { + func() { var err error defer func() { errChan <- err @@ -183,7 +182,7 @@ func TestListLabels(t *testing.T) { } } - err = <- errChan + err = <-errChan if err != nil { t.Fatal(err) } diff --git a/cmd/func/main.go b/cmd/func/main.go index 4a1b6bf7..bc79adf8 100644 --- a/cmd/func/main.go +++ b/cmd/func/main.go @@ -2,10 +2,11 @@ package main import ( "context" - "knative.dev/kn-plugin-func/cmd" "os" "os/signal" "syscall" + + "knative.dev/kn-plugin-func/cmd" ) // Statically-populated build metadata set diff --git a/cmd/version.go b/cmd/version.go index 34cee3bb..e53f4e95 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -25,9 +25,9 @@ func init() { } var versionCmd = &cobra.Command{ - Use: "version", - Short: "Show the version", - Long: `Show the version + Use: "version", + Short: "Show the version", + Long: `Show the version Use the --verbose option to include the build date stamp and commit hash" `, diff --git a/config_test.go b/config_test.go index 994adb33..814b4741 100644 --- a/config_test.go +++ b/config_test.go @@ -590,7 +590,7 @@ func Test_validateLabels(t *testing.T) { }, }, 1, - },{ + }, { "incorrect entry - missing multiple keys", Labels{ Label{ diff --git a/docker/credentials_helper.go b/docker/credentials_helper.go index 32ab3be2..7f8c7259 100644 --- a/docker/credentials_helper.go +++ b/docker/credentials_helper.go @@ -3,12 +3,13 @@ package docker import ( "encoding/json" "fmt" - "github.com/containers/image/v5/types" - "github.com/docker/docker-credential-helpers/client" "net/url" "os" "path/filepath" "strings" + + "github.com/containers/image/v5/types" + "github.com/docker/docker-credential-helpers/client" ) func GetCredentialsFromCredsStore(registry string) (types.DockerAuthConfig, error) { diff --git a/docker/credentials_helper_test.go b/docker/credentials_helper_test.go index 81ec1a4c..8f50c1b9 100644 --- a/docker/credentials_helper_test.go +++ b/docker/credentials_helper_test.go @@ -4,9 +4,9 @@ import "testing" func Test_to2ndLevelDomain(t *testing.T) { tests := []struct { - name string + name string rawurl string - want string + want string }{ {"2nd level", "quay.io", "quay.io"}, {"3nd level", "sub.quay.io", "quay.io"}, @@ -27,4 +27,3 @@ func Test_to2ndLevelDomain(t *testing.T) { }) } } - diff --git a/k8s/client.go b/k8s/client.go index 6a2d2c4b..bdf35e0e 100644 --- a/k8s/client.go +++ b/k8s/client.go @@ -7,7 +7,6 @@ import ( "k8s.io/client-go/tools/clientcmd" ) - func NewKubernetesClientset(namespace string) (*kubernetes.Clientset, error) { restConfig, err := GetClientConfig().ClientConfig() diff --git a/knative/lister.go b/knative/lister.go index 85aa03fd..8447308d 100644 --- a/knative/lister.go +++ b/knative/lister.go @@ -2,6 +2,7 @@ package knative import ( "context" + corev1 "k8s.io/api/core/v1" clientservingv1 "knative.dev/client/pkg/serving/v1" "knative.dev/pkg/apis" diff --git a/mock/builder.go b/mock/builder.go index 4980de56..e0f9d965 100644 --- a/mock/builder.go +++ b/mock/builder.go @@ -2,6 +2,7 @@ package mock import ( "context" + fn "knative.dev/kn-plugin-func" ) diff --git a/mock/lister.go b/mock/lister.go index 0e17b816..76f788fa 100644 --- a/mock/lister.go +++ b/mock/lister.go @@ -2,6 +2,7 @@ package mock import ( "context" + fn "knative.dev/kn-plugin-func" ) diff --git a/mock/runner.go b/mock/runner.go index 7cf9c95c..bc906e9c 100644 --- a/mock/runner.go +++ b/mock/runner.go @@ -2,6 +2,7 @@ package mock import ( "context" + fn "knative.dev/kn-plugin-func" ) diff --git a/test/_e2e/cmd_build_test.go b/test/_e2e/cmd_build_test.go index a2819768..f4540764 100644 --- a/test/_e2e/cmd_build_test.go +++ b/test/_e2e/cmd_build_test.go @@ -6,7 +6,7 @@ import ( ) // Build runs `func build' command for a given test project. -func Build(t *testing.T, knFunc *TestShellCmdRunner, project *FunctionTestProject) { +func Build(t *testing.T, knFunc *TestShellCmdRunner, project *FunctionTestProject) { result := knFunc.Exec("build", "--path", project.ProjectPath, "--registry", GetRegistry()) if result.Error != nil { diff --git a/test/_e2e/cmd_delete_test.go b/test/_e2e/cmd_delete_test.go index 902a74e8..4e976bfe 100644 --- a/test/_e2e/cmd_delete_test.go +++ b/test/_e2e/cmd_delete_test.go @@ -5,7 +5,7 @@ import ( ) // Delete runs `func delete' command for a given test project and verifies it get deleted -func Delete(t *testing.T, knFunc *TestShellCmdRunner, project *FunctionTestProject) { +func Delete(t *testing.T, knFunc *TestShellCmdRunner, project *FunctionTestProject) { // Invoke delete command result := knFunc.Exec("delete", project.FunctionName) if result.Error != nil && project.IsDeployed { diff --git a/test/_e2e/cmd_deploy_test.go b/test/_e2e/cmd_deploy_test.go index 9fa6d78e..2977fdff 100644 --- a/test/_e2e/cmd_deploy_test.go +++ b/test/_e2e/cmd_deploy_test.go @@ -8,7 +8,7 @@ import ( // Deploy runs `func deploy' command for a given test project. It collects the URL from output // and store on test project, so it can be used later by any another test -func Deploy(t *testing.T, knFunc *TestShellCmdRunner, project *FunctionTestProject) { +func Deploy(t *testing.T, knFunc *TestShellCmdRunner, project *FunctionTestProject) { var result TestShellCmdResult if project.IsBuilt { diff --git a/test/_e2e/cmd_list_test.go b/test/_e2e/cmd_list_test.go index 55e8d79e..d2e448cb 100644 --- a/test/_e2e/cmd_list_test.go +++ b/test/_e2e/cmd_list_test.go @@ -13,7 +13,7 @@ func List(t *testing.T, knFunc *TestShellCmdRunner, project FunctionTestProject) } isProjectPresent := strings.Contains(result.Stdout, project.FunctionName) if project.IsDeployed && !isProjectPresent { - t.Fatal("Deployed project expected") + t.Fatal("Deployed project expected") } if !project.IsDeployed && isProjectPresent { t.Fatal("Project is not expected to appear in list output") diff --git a/test/_e2e/config.go b/test/_e2e/config.go index 2498e85a..ce62c1a3 100644 --- a/test/_e2e/config.go +++ b/test/_e2e/config.go @@ -7,7 +7,7 @@ import ( // Intended to provide setup configuration for E2E tests const ( - defaultRegistry = "localhost:5000/user" + defaultRegistry = "localhost:5000/user" testTemplateRepository = "http://github.com/boson-project/test-templates.git" //nolint:varcheck,deadcode ) diff --git a/test/_e2e/e2e_remote_repository_test.go b/test/_e2e/e2e_remote_repository_test.go index 0dd053eb..4654880a 100644 --- a/test/_e2e/e2e_remote_repository_test.go +++ b/test/_e2e/e2e_remote_repository_test.go @@ -34,7 +34,7 @@ func TestRemoteRepository(t *testing.T) { defer Delete(t, knFunc, &project) ReadyCheck(t, knFunc, project) - functionRespValidator := FunctionHttpResponsivenessValidator{ runtime: "go", targetUrl: "%v", expects: "REMOTE_VALID" } + functionRespValidator := FunctionHttpResponsivenessValidator{runtime: "go", targetUrl: "%v", expects: "REMOTE_VALID"} functionRespValidator.Validate(t, project) } diff --git a/test/_e2e/main_test.go b/test/_e2e/main_test.go index dac201de..97381161 100644 --- a/test/_e2e/main_test.go +++ b/test/_e2e/main_test.go @@ -13,7 +13,7 @@ import ( "testing" ) -func TestMain (t *testing.M) { +func TestMain(t *testing.M) { if GetRegistry() == defaultRegistry { err := patchOrCreateDockerConfigFile() @@ -76,7 +76,7 @@ func updateConfigAuth(dockerConfigFile string) error { return err } content := string(bcontent) - if !strings.Contains(content, strings.Split(defaultRegistry,"/")[0]) { + if !strings.Contains(content, strings.Split(defaultRegistry, "/")[0]) { // default registry is not present on .docker/config.json, so let's add it log.Println("Updating ./docker/config.json file with default registry authentication.") exp := regexp.MustCompile(`"auths"[\s]*?[:][\s]*?{`) @@ -86,14 +86,14 @@ func updateConfigAuth(dockerConfigFile string) error { },`)) // Replace file content - _ = os.Rename(dockerConfigFile, dockerConfigFile + ".e2e") + _ = os.Rename(dockerConfigFile, dockerConfigFile+".e2e") err := createConfigAuth(dockerConfigFile, string(newContent)) if err != nil { // rollback config file - _ = os.Rename(dockerConfigFile + ".e2e", dockerConfigFile) + _ = os.Rename(dockerConfigFile+".e2e", dockerConfigFile) return err } _ = os.Remove(dockerConfigFile + ".e2e") } return nil -} \ No newline at end of file +} diff --git a/test/_e2e/ready_check_test.go b/test/_e2e/ready_check_test.go index dfff1acd..9e8c34b7 100644 --- a/test/_e2e/ready_check_test.go +++ b/test/_e2e/ready_check_test.go @@ -1,16 +1,17 @@ package e2e import ( - "k8s.io/apimachinery/pkg/util/wait" "regexp" "testing" "time" + + "k8s.io/apimachinery/pkg/util/wait" ) // ReadyCheck waits deployed function to report as ready. func ReadyCheck(t *testing.T, knFunc *TestShellCmdRunner, project FunctionTestProject) { expr := regexp.MustCompile("\n" + project.FunctionName + " .*True") - err := wait.PollImmediate(5 * time.Second, 1 * time.Minute, func() (done bool, err error) { + err := wait.PollImmediate(5*time.Second, 1*time.Minute, func() (done bool, err error) { result := knFunc.Exec("list") return result.Error == nil && expr.Match([]byte(result.Stdout)), result.Error }) diff --git a/test/_e2e/shell_cmd_runner.go b/test/_e2e/shell_cmd_runner.go index 96738230..5ced584a 100644 --- a/test/_e2e/shell_cmd_runner.go +++ b/test/_e2e/shell_cmd_runner.go @@ -34,7 +34,7 @@ type TestShellCmdRunner struct { type TestShellCmdResult struct { Stdout string Stderr string - Error error + Error error } func (r TestShellCmdResult) Dump(t *testing.T) { @@ -73,7 +73,6 @@ func (f *TestShellCmdRunner) FromDir(dir string) *TestShellCmdRunner { return f } - // Exec invokes go exec library and runs a shell command combining the binary args with args from method signature func (f *TestShellCmdRunner) Exec(args ...string) TestShellCmdResult { finalArgs := f.BinaryArgs @@ -101,7 +100,7 @@ func (f *TestShellCmdRunner) Exec(args ...string) TestShellCmdResult { result := TestShellCmdResult{ Stdout: stdout.String(), Stderr: stderr.String(), - Error: err, + Error: err, } if err == nil && f.ShouldDumpOnSuccess { diff --git a/test/_e2e/trigger_http_test.go b/test/_e2e/trigger_http_test.go index 050c1bb6..714c15c1 100644 --- a/test/_e2e/trigger_http_test.go +++ b/test/_e2e/trigger_http_test.go @@ -82,11 +82,11 @@ var defaultFunctionsHttpValidators = []FunctionHttpResponsivenessValidator{ targetUrl: "%s/health/readiness", }, {runtime: "typescript", - targetUrl: "%s", - method: "POST", + targetUrl: "%s", + method: "POST", contentType: "application/json", - bodyData: `{"message":"hello"}`, - expects: `{"message":"hello"}`, + bodyData: `{"message":"hello"}`, + expects: `{"message":"hello"}`, }, } diff --git a/testdata/repositories/customProvider/go/customTemplate/custom.go b/testdata/repositories/customProvider/go/customTemplate/custom.go index e69de29b..85544860 100644 --- a/testdata/repositories/customProvider/go/customTemplate/custom.go +++ b/testdata/repositories/customProvider/go/customTemplate/custom.go @@ -0,0 +1 @@ +package custom diff --git a/testdata/repositories/repositoryTests/go/custom/custom.go b/testdata/repositories/repositoryTests/go/custom/custom.go index e69de29b..85544860 100644 --- a/testdata/repositories/repositoryTests/go/custom/custom.go +++ b/testdata/repositories/repositoryTests/go/custom/custom.go @@ -0,0 +1 @@ +package custom