Skip to content

Commit

Permalink
Run tests in skaffold build, add skip-tests flag to skip tests (#1326)
Browse files Browse the repository at this point in the history
* run tests in skaffold build (SkaffoldRunner.BuildAndTest())
* added `skip-tests` flag to skip tests
  • Loading branch information
nkubala authored and balopat committed Nov 29, 2018
1 parent dbfa27f commit f0e925d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
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 {
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

0 comments on commit f0e925d

Please sign in to comment.