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

Add the test command to the dev loop #5190

Merged
merged 4 commits into from
Jan 7, 2021
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
6 changes: 0 additions & 6 deletions pkg/skaffold/runner/build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ func (r *SkaffoldRunner) Build(ctx context.Context, out io.Writer, artifacts []*
return nil, err
}

if !r.runCtx.SkipTests() {
if err = r.tester.Test(ctx, out, bRes); err != nil {
return nil, err
}
}

// Update which images are logged.
r.addTagsToPodSelector(bRes)

Expand Down
5 changes: 4 additions & 1 deletion pkg/skaffold/runner/build_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ func TestBuildTestDeploy(t *testing.T) {
runner := createRunner(t, test.testBench, nil, artifacts)
bRes, err := runner.Build(ctx, ioutil.Discard, artifacts)
if err == nil {
err = runner.DeployAndLog(ctx, ioutil.Discard, bRes)
err = runner.Test(ctx, ioutil.Discard, bRes)
if err == nil {
err = runner.DeployAndLog(ctx, ioutil.Discard, bRes)
}
}

t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedActions, test.testBench.Actions())
Expand Down
21 changes: 18 additions & 3 deletions pkg/skaffold/runner/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,20 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer, logger *kuber
instrumentation.AddDevIteration("build")
meterUpdated = true
}
if _, err := r.Build(ctx, out, r.changeSet.needsRebuild); err != nil {
logrus.Warnln("Skipping deploy due to error:", err)
bRes, err := r.Build(ctx, out, r.changeSet.needsRebuild)
if err != nil {
logrus.Warnln("Skipping test and deploy due to build error:", err)
event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err)
return nil
}
// TODO(modali): Add skipTest boolean to Tester itself to avoid this check.
if !r.runCtx.SkipTests() {
if err = r.Test(ctx, out, bRes); err != nil {
logrus.Warnln("Skipping deploy due to test error:", err)
event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err)
return nil
}
}
}

if needsDeploy {
Expand Down Expand Up @@ -134,7 +143,7 @@ func (r *SkaffoldRunner) doDev(ctx context.Context, out io.Writer, logger *kuber
return nil
}

// Dev watches for changes and runs the skaffold build and deploy
// Dev watches for changes and runs the skaffold build, test and deploy
// config until interrupted by the user.
func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) error {
event.DevLoopInProgress(r.devIteration)
Expand Down Expand Up @@ -219,6 +228,12 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la
event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err)
return fmt.Errorf("exiting dev mode because first build failed: %w", err)
}
if !r.runCtx.SkipTests() {
if err = r.Test(ctx, out, bRes); err != nil {
event.DevLoopFailedInPhase(r.devIteration, sErrors.Build, err)
return fmt.Errorf("exiting dev mode because test failed after first build: %w", err)
}
}

logger := r.createLogger(out, bRes)
defer logger.Stop()
Expand Down