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

Conversation

nkubala
Copy link
Contributor

@nkubala nkubala commented Nov 28, 2018

This adds support for running tests during a skaffold build. Additionally, it adds a way for users to skip running tests with a CLI flag.

Fixes #1078

@codecov-io
Copy link

codecov-io commented Nov 28, 2018

Codecov Report

Merging #1326 into master will increase coverage by 0.05%.
The diff coverage is 76.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1326      +/-   ##
==========================================
+ Coverage   44.68%   44.74%   +0.05%     
==========================================
  Files         114      114              
  Lines        4883     4890       +7     
==========================================
+ Hits         2182     2188       +6     
- Misses       2477     2478       +1     
  Partials      224      224
Impacted Files Coverage Δ
pkg/skaffold/config/options.go 88.23% <ø> (ø) ⬆️
cmd/skaffold/app/cmd/cmd.go 0% <0%> (ø) ⬆️
cmd/skaffold/app/cmd/build.go 0% <0%> (ø) ⬆️
pkg/skaffold/runner/runner.go 54.95% <100%> (+1.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dbfa27f...9c31cec. Read the comment docs.

Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

A refactoring suggestion + can we write tests for this? :)

if err := r.Test(ctx, out, bRes); err != nil {
logrus.Warnln("Skipping Deploy due to failed tests:", err)
return nil
if !r.opts.SkipTests {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about pulling these out into an overriding method instead of repeating the logic?
Something like:

func (r *SkaffoldRunner) Test(ctx context.Context, out io.Writer, artifacts []build.Artifact) error {
	if r.opts.SkipTests {
		return nil
	} 
	return r.Tester.Test(ctx, out, artifacts)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact all those paths should call RunBuild()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was addressed through @dgageot's refactor (#1331)

@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

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

s/whether/Whether

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if err := r.Test(ctx, out, bRes); err != nil {
logrus.Warnln("Skipping Deploy due to failed tests:", err)
return nil
if !r.opts.SkipTests {
Copy link
Contributor

Choose a reason for hiding this comment

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

In fact all those paths should call RunBuild()

@dgageot
Copy link
Contributor

dgageot commented Nov 28, 2018

@nkubala #1331 should make your job easier by removing some of the existing duplication.

@nkubala nkubala dismissed dgageot’s stale review November 29, 2018 20:06

Addressed all comments

@nkubala nkubala dismissed balopat’s stale review November 29, 2018 20:06

Addressed all comments

}

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

@@ -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.RunBuild(ctx, buildOut, config.Build.Artifacts)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be called BuildAndTest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea

@balopat balopat merged commit f0e925d into GoogleContainerTools:master Nov 29, 2018
@nkubala nkubala deleted the test branch June 12, 2019 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants