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 <lball@redhat.com>

* fixup: remove extraneous print statements

Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
Lance Ball 2021-09-08 09:53:45 -04:00 committed by GitHub
parent eb17fb819c
commit 71368c6a1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 60 additions and 54 deletions

View File

@ -8,9 +8,9 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"sort" "sort"
"sync" "sync"
"runtime"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )

View File

@ -2,6 +2,7 @@ package cmd
import ( import (
"fmt" "fmt"
"github.com/AlecAivazis/survey/v2" "github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal" "github.com/AlecAivazis/survey/v2/terminal"
"github.com/ory/viper" "github.com/ory/viper"
@ -23,7 +24,7 @@ type functionLoaderSaver interface {
functionSaver functionSaver
} }
type standardLoaderSaver struct {} type standardLoaderSaver struct{}
func (s standardLoaderSaver) Load(path string) (fn.Function, error) { func (s standardLoaderSaver) Load(path string) (fn.Function, error) {
f, err := fn.NewFunction(path) f, err := fn.NewFunction(path)

View File

@ -4,15 +4,16 @@ package cmd
import ( import (
"context" "context"
"github.com/Netflix/go-expect"
"github.com/hinshun/vt10x"
"github.com/spf13/cobra"
fn "knative.dev/kn-plugin-func"
"os" "os"
"reflect" "reflect"
"sync" "sync"
"testing" "testing"
"time" "time"
"github.com/Netflix/go-expect"
"github.com/hinshun/vt10x"
"github.com/spf13/cobra"
fn "knative.dev/kn-plugin-func"
) )
type mockFunctionLoaderSaver struct { type mockFunctionLoaderSaver struct {
@ -49,21 +50,21 @@ func createRunFunc(cmd *cobra.Command, t *testing.T) func(subcmd string, input .
wg.Add(1) wg.Add(1)
go func() { go func() {
//defer wg.Done() //defer wg.Done()
_,_ = c.ExpectEOF() _, _ = c.ExpectEOF()
}() }()
go func() { go func() {
defer wg.Done() defer wg.Done()
time.Sleep(time.Millisecond*50) time.Sleep(time.Millisecond * 50)
for _, s := range input { for _, s := range input {
_, _ = c.Send(s) _, _ = c.Send(s)
time.Sleep(time.Millisecond*50) time.Sleep(time.Millisecond * 50)
} }
}() }()
a := []string{subcmd} a := []string{subcmd}
cmd.SetArgs(a) cmd.SetArgs(a)
func () { func() {
defer withMockedStdio(t, c)() defer withMockedStdio(t, c)()
err = cmd.ExecuteContext(ctx) err = cmd.ExecuteContext(ctx)
wg.Wait() wg.Wait()
@ -93,9 +94,9 @@ func withMockedStdio(t *testing.T, c *expect.Console) func() {
} }
const ( const (
arrowUp = "\033[A" arrowUp = "\033[A"
arrowDown = "\033[B" arrowDown = "\033[B"
enter = "\r" enter = "\r"
) )
func TestNewConfigLabelsCmd(t *testing.T) { func TestNewConfigLabelsCmd(t *testing.T) {
@ -107,33 +108,31 @@ func TestNewConfigLabelsCmd(t *testing.T) {
run := createRunFunc(cmd, 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} return fn.Label{Key: &k, Value: &v}
} }
assertLabel := func (ps fn.Labels) { assertLabel := func(ps fn.Labels) {
t.Helper() t.Helper()
assertLabelEq(t, *labels, ps) assertLabelEq(t, *labels, ps)
} }
run("add", enter, "a", enter, "b", enter) 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) 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) 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) 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) { 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} return fn.Label{Key: &k, Value: &v}
} }
@ -154,7 +153,7 @@ func TestListLabels(t *testing.T) {
cmd.SetArgs(make([]string, 0)) cmd.SetArgs(make([]string, 0))
errChan := make(chan error, 1) errChan := make(chan error, 1)
func () { func() {
var err error var err error
defer func() { defer func() {
errChan <- err errChan <- err
@ -183,7 +182,7 @@ func TestListLabels(t *testing.T) {
} }
} }
err = <- errChan err = <-errChan
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -2,10 +2,11 @@ package main
import ( import (
"context" "context"
"knative.dev/kn-plugin-func/cmd"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"knative.dev/kn-plugin-func/cmd"
) )
// Statically-populated build metadata set // Statically-populated build metadata set

View File

@ -25,9 +25,9 @@ func init() {
} }
var versionCmd = &cobra.Command{ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "Show the version", Short: "Show the version",
Long: `Show the version Long: `Show the version
Use the --verbose option to include the build date stamp and commit hash" Use the --verbose option to include the build date stamp and commit hash"
`, `,

View File

@ -590,7 +590,7 @@ func Test_validateLabels(t *testing.T) {
}, },
}, },
1, 1,
},{ }, {
"incorrect entry - missing multiple keys", "incorrect entry - missing multiple keys",
Labels{ Labels{
Label{ Label{

View File

@ -3,12 +3,13 @@ package docker
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/containers/image/v5/types"
"github.com/docker/docker-credential-helpers/client"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/containers/image/v5/types"
"github.com/docker/docker-credential-helpers/client"
) )
func GetCredentialsFromCredsStore(registry string) (types.DockerAuthConfig, error) { func GetCredentialsFromCredsStore(registry string) (types.DockerAuthConfig, error) {

View File

@ -4,9 +4,9 @@ import "testing"
func Test_to2ndLevelDomain(t *testing.T) { func Test_to2ndLevelDomain(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
rawurl string rawurl string
want string want string
}{ }{
{"2nd level", "quay.io", "quay.io"}, {"2nd level", "quay.io", "quay.io"},
{"3nd level", "sub.quay.io", "quay.io"}, {"3nd level", "sub.quay.io", "quay.io"},
@ -27,4 +27,3 @@ func Test_to2ndLevelDomain(t *testing.T) {
}) })
} }
} }

View File

@ -7,7 +7,6 @@ import (
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
) )
func NewKubernetesClientset(namespace string) (*kubernetes.Clientset, error) { func NewKubernetesClientset(namespace string) (*kubernetes.Clientset, error) {
restConfig, err := GetClientConfig().ClientConfig() restConfig, err := GetClientConfig().ClientConfig()

View File

@ -2,6 +2,7 @@ package knative
import ( import (
"context" "context"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
clientservingv1 "knative.dev/client/pkg/serving/v1" clientservingv1 "knative.dev/client/pkg/serving/v1"
"knative.dev/pkg/apis" "knative.dev/pkg/apis"

View File

@ -2,6 +2,7 @@ package mock
import ( import (
"context" "context"
fn "knative.dev/kn-plugin-func" fn "knative.dev/kn-plugin-func"
) )

View File

@ -2,6 +2,7 @@ package mock
import ( import (
"context" "context"
fn "knative.dev/kn-plugin-func" fn "knative.dev/kn-plugin-func"
) )

View File

@ -2,6 +2,7 @@ package mock
import ( import (
"context" "context"
fn "knative.dev/kn-plugin-func" fn "knative.dev/kn-plugin-func"
) )

View File

@ -6,7 +6,7 @@ import (
) )
// Build runs `func build' command for a given test project. // 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()) result := knFunc.Exec("build", "--path", project.ProjectPath, "--registry", GetRegistry())
if result.Error != nil { if result.Error != nil {

View File

@ -5,7 +5,7 @@ import (
) )
// Delete runs `func delete' command for a given test project and verifies it get deleted // 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 // Invoke delete command
result := knFunc.Exec("delete", project.FunctionName) result := knFunc.Exec("delete", project.FunctionName)
if result.Error != nil && project.IsDeployed { if result.Error != nil && project.IsDeployed {

View File

@ -8,7 +8,7 @@ import (
// Deploy runs `func deploy' command for a given test project. It collects the URL from output // 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 // 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 var result TestShellCmdResult
if project.IsBuilt { if project.IsBuilt {

View File

@ -13,7 +13,7 @@ func List(t *testing.T, knFunc *TestShellCmdRunner, project FunctionTestProject)
} }
isProjectPresent := strings.Contains(result.Stdout, project.FunctionName) isProjectPresent := strings.Contains(result.Stdout, project.FunctionName)
if project.IsDeployed && !isProjectPresent { if project.IsDeployed && !isProjectPresent {
t.Fatal("Deployed project expected") t.Fatal("Deployed project expected")
} }
if !project.IsDeployed && isProjectPresent { if !project.IsDeployed && isProjectPresent {
t.Fatal("Project is not expected to appear in list output") t.Fatal("Project is not expected to appear in list output")

View File

@ -7,7 +7,7 @@ import (
// Intended to provide setup configuration for E2E tests // Intended to provide setup configuration for E2E tests
const ( const (
defaultRegistry = "localhost:5000/user" defaultRegistry = "localhost:5000/user"
testTemplateRepository = "http://github.com/boson-project/test-templates.git" //nolint:varcheck,deadcode testTemplateRepository = "http://github.com/boson-project/test-templates.git" //nolint:varcheck,deadcode
) )

View File

@ -34,7 +34,7 @@ func TestRemoteRepository(t *testing.T) {
defer Delete(t, knFunc, &project) defer Delete(t, knFunc, &project)
ReadyCheck(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) functionRespValidator.Validate(t, project)
} }

View File

@ -13,7 +13,7 @@ import (
"testing" "testing"
) )
func TestMain (t *testing.M) { func TestMain(t *testing.M) {
if GetRegistry() == defaultRegistry { if GetRegistry() == defaultRegistry {
err := patchOrCreateDockerConfigFile() err := patchOrCreateDockerConfigFile()
@ -76,7 +76,7 @@ func updateConfigAuth(dockerConfigFile string) error {
return err return err
} }
content := string(bcontent) 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 // 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.") log.Println("Updating ./docker/config.json file with default registry authentication.")
exp := regexp.MustCompile(`"auths"[\s]*?[:][\s]*?{`) exp := regexp.MustCompile(`"auths"[\s]*?[:][\s]*?{`)
@ -86,14 +86,14 @@ func updateConfigAuth(dockerConfigFile string) error {
},`)) },`))
// Replace file content // Replace file content
_ = os.Rename(dockerConfigFile, dockerConfigFile + ".e2e") _ = os.Rename(dockerConfigFile, dockerConfigFile+".e2e")
err := createConfigAuth(dockerConfigFile, string(newContent)) err := createConfigAuth(dockerConfigFile, string(newContent))
if err != nil { if err != nil {
// rollback config file // rollback config file
_ = os.Rename(dockerConfigFile + ".e2e", dockerConfigFile) _ = os.Rename(dockerConfigFile+".e2e", dockerConfigFile)
return err return err
} }
_ = os.Remove(dockerConfigFile + ".e2e") _ = os.Remove(dockerConfigFile + ".e2e")
} }
return nil return nil
} }

View File

@ -1,16 +1,17 @@
package e2e package e2e
import ( import (
"k8s.io/apimachinery/pkg/util/wait"
"regexp" "regexp"
"testing" "testing"
"time" "time"
"k8s.io/apimachinery/pkg/util/wait"
) )
// ReadyCheck waits deployed function to report as ready. // ReadyCheck waits deployed function to report as ready.
func ReadyCheck(t *testing.T, knFunc *TestShellCmdRunner, project FunctionTestProject) { func ReadyCheck(t *testing.T, knFunc *TestShellCmdRunner, project FunctionTestProject) {
expr := regexp.MustCompile("\n" + project.FunctionName + " .*True") 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") result := knFunc.Exec("list")
return result.Error == nil && expr.Match([]byte(result.Stdout)), result.Error return result.Error == nil && expr.Match([]byte(result.Stdout)), result.Error
}) })

View File

@ -34,7 +34,7 @@ type TestShellCmdRunner struct {
type TestShellCmdResult struct { type TestShellCmdResult struct {
Stdout string Stdout string
Stderr string Stderr string
Error error Error error
} }
func (r TestShellCmdResult) Dump(t *testing.T) { func (r TestShellCmdResult) Dump(t *testing.T) {
@ -73,7 +73,6 @@ func (f *TestShellCmdRunner) FromDir(dir string) *TestShellCmdRunner {
return f return f
} }
// Exec invokes go exec library and runs a shell command combining the binary args with args from method signature // 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 { func (f *TestShellCmdRunner) Exec(args ...string) TestShellCmdResult {
finalArgs := f.BinaryArgs finalArgs := f.BinaryArgs
@ -101,7 +100,7 @@ func (f *TestShellCmdRunner) Exec(args ...string) TestShellCmdResult {
result := TestShellCmdResult{ result := TestShellCmdResult{
Stdout: stdout.String(), Stdout: stdout.String(),
Stderr: stderr.String(), Stderr: stderr.String(),
Error: err, Error: err,
} }
if err == nil && f.ShouldDumpOnSuccess { if err == nil && f.ShouldDumpOnSuccess {

View File

@ -82,11 +82,11 @@ var defaultFunctionsHttpValidators = []FunctionHttpResponsivenessValidator{
targetUrl: "%s/health/readiness", targetUrl: "%s/health/readiness",
}, },
{runtime: "typescript", {runtime: "typescript",
targetUrl: "%s", targetUrl: "%s",
method: "POST", method: "POST",
contentType: "application/json", contentType: "application/json",
bodyData: `{"message":"hello"}`, bodyData: `{"message":"hello"}`,
expects: `{"message":"hello"}`, expects: `{"message":"hello"}`,
}, },
} }

View File

@ -0,0 +1 @@
package custom

View File

@ -0,0 +1 @@
package custom