Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests in skaffold build, add flag to skip tests #1326

Merged
merged 4 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/skaffold/app/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func runBuild(out io.Writer) error {
buildOut = ioutil.Discard
}

bRes, err := runner.Build(ctx, buildOut, runner.Tagger, config.Build.Artifacts)
bRes, err := runner.BuildAndTest(ctx, buildOut, config.Build.Artifacts)
if err != nil {
return errors.Wrap(err, "build step")
return err
}

cmdOut := BuildOutput{Builds: bRes}
Expand Down
1 change: 1 addition & 0 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func AddRunDevFlags(cmd *cobra.Command) {
cmd.Flags().StringArrayVarP(&opts.Profiles, "profile", "p", nil, "Activate profiles by name")
cmd.Flags().StringVarP(&opts.Namespace, "namespace", "n", "", "Run deployments in the specified namespace")
cmd.Flags().StringVarP(&opts.DefaultRepo, "default-repo", "d", "", "Default repository value (overrides global config)")
cmd.Flags().BoolVar(&opts.SkipTests, "skip-tests", false, "Whether to skip the tests after building")
}

func SetUpLogs(out io.Writer, level string) error {
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type SkaffoldOptions struct {
Tail bool
TailDev bool
PortForward bool
SkipTests bool
Profiles []string
CustomTag string
Namespace string
Expand Down
23 changes: 17 additions & 6 deletions pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,9 @@ func (r *SkaffoldRunner) newLogger(out io.Writer, artifacts []*latest.Artifact)
}

func (r *SkaffoldRunner) buildTestDeploy(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) error {
bRes, err := r.Build(ctx, out, r.Tagger, artifacts)
bRes, err := r.BuildAndTest(ctx, out, artifacts)
if err != nil {
return errors.Wrap(err, "build failed")
}

if err := r.Test(ctx, out, bRes); err != nil {
return errors.Wrap(err, "test failed")
return err
}

// Update which images are logged.
Expand Down Expand Up @@ -249,6 +245,21 @@ func (r *SkaffoldRunner) Run(ctx context.Context, out io.Writer, artifacts []*la
return nil
}

// BuildAndTest builds artifacts and runs tests on built artifacts
func (r *SkaffoldRunner) BuildAndTest(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) ([]build.Artifact, error) {
bRes, err := r.Build(ctx, out, r.Tagger, artifacts)
if err != nil {
return nil, errors.Wrap(err, "build failed")
}

if !r.opts.SkipTests {
if err = r.Test(ctx, out, bRes); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err :=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have an err defined a few lines above, so this just avoids creating another one and just overwrites the previously instantiated one

return nil, errors.Wrap(err, "test failed")
}
}
return bRes, err
}

// TailLogs prints the logs for deployed artifacts.
func (r *SkaffoldRunner) TailLogs(ctx context.Context, out io.Writer, artifacts []*latest.Artifact, bRes []build.Artifact) error {
if !r.opts.Tail {
Expand Down