diff --git a/pkg/cmd/pipeline/logs.go b/pkg/cmd/pipeline/logs.go index dcde92acb..09cff2dd3 100644 --- a/pkg/cmd/pipeline/logs.go +++ b/pkg/cmd/pipeline/logs.go @@ -20,14 +20,13 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" + "github.com/AlecAivazis/survey/v2/terminal" "github.com/spf13/cobra" "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/cmd/pipelinerun" "github.com/tektoncd/cli/pkg/formatted" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/AlecAivazis/survey/v2/terminal" - ) type logOptions struct { @@ -59,10 +58,10 @@ func logCommand(p cli.Params) *cobra.Command { ` c := &cobra.Command{ - Use: "logs", + Use: "logs", DisableFlagsInUseLine: true, - Short: "Show the logs of latest pipelinerun of given pipeline ", - Example: eg, + Short: "Show the logs of latest pipelinerun of given pipeline ", + Example: eg, RunE: func(cmd *cobra.Command, args []string) error { opts.stream = &cli.Stream{ Out: cmd.OutOrStdout(), @@ -114,8 +113,8 @@ func (opts *logOptions) init(args []string) error { opts.runName = args[1] default: - fmt.Fprintln(opts.stream.Err,"too many arguments") - return nil + fmt.Fprintln(opts.stream.Err, "too many arguments") + return nil } return nil @@ -175,6 +174,9 @@ func (opts *logOptions) initLastRunName() error { return err } lastrun, err := lastRun(cs, opts.params.Namespace(), opts.pipelineName) + if err != nil { + return err + } opts.runName = lastrun return nil } diff --git a/pkg/cmd/pipeline/logs_test.go b/pkg/cmd/pipeline/logs_test.go index 8d09dd505..a9276c3b6 100644 --- a/pkg/cmd/pipeline/logs_test.go +++ b/pkg/cmd/pipeline/logs_test.go @@ -41,18 +41,10 @@ func init() { } var ( - answer = "" pipelineName = "output-pipeline" prName = "output-pipeline-run" prName2 = "output-pipeline-run-2" - prstart = clockwork.NewFakeClock() ns = "namespace" - - task1Name = "output-task" - tr1Name = "output-task-run" - tr1StartTime = prstart.Now().Add(20 * time.Second) - tr1Pod = "output-task-pod-123456" - tr1Step1Name = "writefile-step" ) func TestInteractiveAskPAndPR(t *testing.T) { diff --git a/pkg/cmd/pipeline/logs_testutil.go b/pkg/cmd/pipeline/logs_testutil.go index 09dd0e6f9..d370c76c9 100644 --- a/pkg/cmd/pipeline/logs_testutil.go +++ b/pkg/cmd/pipeline/logs_testutil.go @@ -18,8 +18,6 @@ import ( "bytes" "testing" - "github.com/tektoncd/cli/pkg/cli" - "github.com/hinshun/vt10x" "github.com/AlecAivazis/survey/v2" @@ -31,7 +29,6 @@ import ( type promptTest struct { name string cmdArgs []string - clientset *cli.Params procedure func(*expect.Console) error } @@ -50,7 +47,7 @@ func (opts *logOptions) RunPromptTest(t *testing.T, test promptTest) { } func stdio(c *expect.Console) terminal.Stdio { - return terminal.Stdio{c.Tty(), c.Tty(), c.Tty()} + return terminal.Stdio{In: c.Tty(), Out: c.Tty(), Err: c.Tty()} } func (pt *promptTest) runTest(t *testing.T, procedure func(*expect.Console) error, test func(terminal.Stdio) error) { @@ -65,7 +62,9 @@ func (pt *promptTest) runTest(t *testing.T, procedure func(*expect.Console) erro donec := make(chan struct{}) go func() { defer close(donec) - procedure(c) + if err := procedure(c); err != nil { + t.Logf("procedure failed: %v", err) + } }() err = test(stdio(c)) diff --git a/pkg/cmd/pipelinerun/log_writer.go b/pkg/cmd/pipelinerun/log_writer.go index 4f5406e92..cabb5f31f 100644 --- a/pkg/cmd/pipelinerun/log_writer.go +++ b/pkg/cmd/pipelinerun/log_writer.go @@ -16,6 +16,7 @@ package pipelinerun import ( "fmt" + "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/formatted" ) diff --git a/pkg/cmd/pipelinerun/logs.go b/pkg/cmd/pipelinerun/logs.go index fb4c4d589..f84d83ee5 100644 --- a/pkg/cmd/pipelinerun/logs.go +++ b/pkg/cmd/pipelinerun/logs.go @@ -17,11 +17,10 @@ package pipelinerun import ( "fmt" - "github.com/tektoncd/cli/pkg/helper/pods/stream" - "github.com/spf13/cobra" "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/helper/pods" + "github.com/tektoncd/cli/pkg/helper/pods/stream" ) const ( @@ -56,11 +55,11 @@ func logCommand(p cli.Params) *cobra.Command { ` c := &cobra.Command{ - Use: "logs", + Use: "logs", DisableFlagsInUseLine: true, - Short: "Show the logs of PipelineRun", - Example: eg, - Args: cobra.ExactArgs(1), + Short: "Show the logs of PipelineRun", + Example: eg, + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.PipelineRunName = args[0] opts.Stream = &cli.Stream{ diff --git a/test/presubmit-tests.sh b/test/presubmit-tests.sh index 5d7c37c7d..73095c72f 100755 --- a/test/presubmit-tests.sh +++ b/test/presubmit-tests.sh @@ -31,6 +31,10 @@ function pre_build_tests() { go get -u github.com/knative/test-infra/tools/dep-collector } +function post_build_tests() { + golangci-lint run +} + # We use the default build, unit and integration test runners. main $@