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

Wrap tester in SkaffoldRunner to improve SkaffoldLogEvent labelling #6469

Merged
merged 2 commits into from
Aug 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/v1/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (r *SkaffoldRunner) Dev(ctx context.Context, out io.Writer, artifacts []*la
for i := range artifacts {
artifact := artifacts[i]
if err := r.monitor.Register(
func() ([]string, error) { return r.Tester.TestDependencies(ctx, artifact) },
func() ([]string, error) { return r.tester.TestDependencies(ctx, artifact) },
func(filemon.Events) { r.changeSet.AddRetest(artifact) },
); err != nil {
event.DevLoopFailedWithErrorCode(r.devIteration, proto.StatusCode_DEVINIT_REGISTER_TEST_DEPS, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/v1/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func NewForConfig(ctx context.Context, runCtx *runcontext.RunContext) (*Skaffold
return &SkaffoldRunner{
Builder: *rbuilder,
Pruner: runner.Pruner{Builder: builder},
Tester: tester,
tester: tester,
deployer: deployer,
monitor: monitor,
listener: runner.NewSkaffoldListener(monitor, rtrigger, sourceDependencies, intentChan),
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/v1/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
type SkaffoldRunner struct {
runner.Builder
runner.Pruner
test.Tester
tester test.Tester

deployer deploy.Deployer
monitor filemon.Monitor
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/runner/v1/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func createRunner(t *testutil.T, testBench *TestBench, monitor filemon.Monitor,

// TODO(yuwenma):builder.builder looks weird. Avoid the nested struct.
runner.Builder.Builder = testBench
runner.Tester = testBench
runner.tester = testBench
runner.deployer = testBench
runner.listener = testBench
runner.monitor = monitor
Expand Down Expand Up @@ -467,7 +467,7 @@ func TestNewForConfig(t *testing.T) {
} else {
t.CheckNoError(err)
t.CheckTypeEquality(b, cfg.Pruner.Builder)
t.CheckTypeEquality(_t, cfg.Tester)
t.CheckTypeEquality(_t, cfg.tester)
t.CheckTypeEquality(d, cfg.deployer)
}
}
Expand Down
40 changes: 40 additions & 0 deletions pkg/skaffold/runner/v1/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2021 The Skaffold Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"context"
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/output"
)

func (r *SkaffoldRunner) Test(ctx context.Context, out io.Writer, artifacts []graph.Artifact) error {
eventV2.TaskInProgress(constants.Test, "Test")
out, ctx = output.WithEventContext(ctx, out, constants.Test, constants.SubtaskIDNone)

if err := r.tester.Test(ctx, out, artifacts); err != nil {
eventV2.TaskFailed(constants.Test, err)
return err
}

eventV2.TaskSucceeded(constants.Test)
return nil
}
4 changes: 0 additions & 4 deletions pkg/skaffold/test/test_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
Expand Down Expand Up @@ -76,7 +75,6 @@ func (t FullTester) Test(ctx context.Context, out io.Writer, bRes []graph.Artifa
return nil
}

eventV2.TaskInProgress(constants.Test, "")
output.Default.Fprintln(out, "Testing images...")

if t.muted.MuteTest() {
Expand All @@ -103,11 +101,9 @@ func (t FullTester) Test(ctx context.Context, out io.Writer, bRes []graph.Artifa
}

if err := t.runTests(ctx, out, bRes); err != nil {
eventV2.TaskFailed(constants.Test, err)
return err
}

eventV2.TaskSucceeded(constants.Test)
return nil
}

Expand Down