From 1cabc1fb582dd95731f075b4c98e2204b8dcd9f4 Mon Sep 17 00:00:00 2001 From: Nick Kubala Date: Tue, 5 Mar 2019 16:37:20 -0800 Subject: [PATCH] fix tests --- docs/content/en/docs/references/cli/_index.md | 10 ++++++++++ pkg/skaffold/build/cache.go | 2 +- pkg/skaffold/build/cache_test.go | 4 ++-- pkg/skaffold/build/local/local_test.go | 2 +- pkg/skaffold/build/plugin/plugin_test.go | 4 ++++ pkg/skaffold/runner/runner.go | 2 +- pkg/skaffold/runner/runner_test.go | 3 +++ 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/content/en/docs/references/cli/_index.md b/docs/content/en/docs/references/cli/_index.md index 4aa7f270aa5..6b09644b930 100644 --- a/docs/content/en/docs/references/cli/_index.md +++ b/docs/content/en/docs/references/cli/_index.md @@ -70,6 +70,7 @@ Flags: --enable-rpc skaffold dev Enable gRPC for exposing Skaffold events (true by default for skaffold dev) -f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml") -n, --namespace string Run deployments in the specified namespace + --no-prune Skip removing images and containers built by Skaffold -o, --output *flags.TemplateFlag Format output with go-template. For full struct documentation, see https://godoc.org/github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd#BuildOutput (default {{range .Builds}}{{.ImageName}} -> {{.Tag}} {{end}}) -p, --profile stringArray Activate profiles by name @@ -93,6 +94,7 @@ Env vars: * `SKAFFOLD_ENABLE_RPC` (same as --enable-rpc) * `SKAFFOLD_FILENAME` (same as --filename) * `SKAFFOLD_NAMESPACE` (same as --namespace) +* `SKAFFOLD_NO_PRUNE` (same as --no-prune) * `SKAFFOLD_OUTPUT` (same as --output) * `SKAFFOLD_PROFILE` (same as --profile) * `SKAFFOLD_QUIET` (same as --quiet) @@ -156,6 +158,7 @@ Flags: --enable-rpc skaffold dev Enable gRPC for exposing Skaffold events (true by default for skaffold dev) -f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml") -n, --namespace string Run deployments in the specified namespace + --no-prune Skip removing images and containers built by Skaffold -p, --profile stringArray Activate profiles by name --rpc-port string tcp port to expose event API (default ":50051") --skip-tests Whether to skip the tests after building @@ -175,6 +178,7 @@ Env vars: * `SKAFFOLD_ENABLE_RPC` (same as --enable-rpc) * `SKAFFOLD_FILENAME` (same as --filename) * `SKAFFOLD_NAMESPACE` (same as --namespace) +* `SKAFFOLD_NO_PRUNE` (same as --no-prune) * `SKAFFOLD_PROFILE` (same as --profile) * `SKAFFOLD_RPC_PORT` (same as --rpc-port) * `SKAFFOLD_SKIP_TESTS` (same as --skip-tests) @@ -197,6 +201,7 @@ Flags: --images strings A list of pre-built images to deploy -l, --label stringArray Add custom labels to deployed objects. Set multiple times for multiple labels. -n, --namespace string Run deployments in the specified namespace + --no-prune Skip removing images and containers built by Skaffold -p, --profile stringArray Activate profiles by name --rpc-port string tcp port to expose event API (default ":50051") --skip-tests Whether to skip the tests after building @@ -219,6 +224,7 @@ Env vars: * `SKAFFOLD_IMAGES` (same as --images) * `SKAFFOLD_LABEL` (same as --label) * `SKAFFOLD_NAMESPACE` (same as --namespace) +* `SKAFFOLD_NO_PRUNE` (same as --no-prune) * `SKAFFOLD_PROFILE` (same as --profile) * `SKAFFOLD_RPC_PORT` (same as --rpc-port) * `SKAFFOLD_SKIP_TESTS` (same as --skip-tests) @@ -243,6 +249,7 @@ Flags: -f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml") -l, --label stringArray Add custom labels to deployed objects. Set multiple times for multiple labels -n, --namespace string Run deployments in the specified namespace + --no-prune Skip removing images and containers built by Skaffold --port-forward Port-forward exposed container ports within pods (default true) -p, --profile stringArray Activate profiles by name --rpc-port string tcp port to expose event API (default ":50051") @@ -270,6 +277,7 @@ Env vars: * `SKAFFOLD_FILENAME` (same as --filename) * `SKAFFOLD_LABEL` (same as --label) * `SKAFFOLD_NAMESPACE` (same as --namespace) +* `SKAFFOLD_NO_PRUNE` (same as --no-prune) * `SKAFFOLD_PORT_FORWARD` (same as --port-forward) * `SKAFFOLD_PROFILE` (same as --profile) * `SKAFFOLD_RPC_PORT` (same as --rpc-port) @@ -374,6 +382,7 @@ Flags: -f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml") -l, --label stringArray Add custom labels to deployed objects. Set multiple times for multiple labels. -n, --namespace string Run deployments in the specified namespace + --no-prune Skip removing images and containers built by Skaffold -p, --profile stringArray Activate profiles by name --rpc-port string tcp port to expose event API (default ":50051") --skip-tests Whether to skip the tests after building @@ -396,6 +405,7 @@ Env vars: * `SKAFFOLD_FILENAME` (same as --filename) * `SKAFFOLD_LABEL` (same as --label) * `SKAFFOLD_NAMESPACE` (same as --namespace) +* `SKAFFOLD_NO_PRUNE` (same as --no-prune) * `SKAFFOLD_PROFILE` (same as --profile) * `SKAFFOLD_RPC_PORT` (same as --rpc-port) * `SKAFFOLD_SKIP_TESTS` (same as --skip-tests) diff --git a/pkg/skaffold/build/cache.go b/pkg/skaffold/build/cache.go index b8a2d9f29be..672ecfd3560 100644 --- a/pkg/skaffold/build/cache.go +++ b/pkg/skaffold/build/cache.go @@ -143,7 +143,7 @@ func (c *Cache) RetrieveCachedArtifacts(ctx context.Context, out io.Writer, arti artifact, err := c.resolveCachedArtifact(ctx, out, a) if err != nil { logrus.Debugf("error retrieving cached artifact for %s: %v\n", a.ImageName, err) - color.Red.Fprintln(out, "Unable to retrieve %s from cache; this image will be rebuilt.", a.ImageName) + color.Red.Fprintf(out, "Unable to retrieve %s from cache; this image will be rebuilt.\n", a.ImageName) needToBuild = append(needToBuild, a) continue } diff --git a/pkg/skaffold/build/cache_test.go b/pkg/skaffold/build/cache_test.go index ae87f7dfe22..5ef7fd649b5 100644 --- a/pkg/skaffold/build/cache_test.go +++ b/pkg/skaffold/build/cache_test.go @@ -206,7 +206,7 @@ func Test_RetrieveCachedArtifacts(t *testing.T) { localCluster = originalLocal }() - test.cache.client = docker.NewLocalDaemon(&test.api, nil) + test.cache.client = docker.NewLocalDaemon(&test.api, nil, false) actualArtifacts, actualBuildResults := test.cache.RetrieveCachedArtifacts(context.Background(), os.Stdout, test.artifacts) testutil.CheckErrorAndDeepEqual(t, false, nil, test.expectedArtifacts, actualArtifacts) @@ -406,7 +406,7 @@ func TestRetrieveCachedArtifactDetails(t *testing.T) { remoteDigest = originalRemoteDigest }() - test.cache.client = docker.NewLocalDaemon(&test.api, nil) + test.cache.client = docker.NewLocalDaemon(&test.api, nil, false) actual, err := test.cache.retrieveCachedArtifactDetails(context.Background(), test.artifact) if err != nil { t.Fatalf("error retrieving artifact details: %v", err) diff --git a/pkg/skaffold/build/local/local_test.go b/pkg/skaffold/build/local/local_test.go index f3623411871..1e0824f2cad 100644 --- a/pkg/skaffold/build/local/local_test.go +++ b/pkg/skaffold/build/local/local_test.go @@ -228,7 +228,7 @@ func TestLocalRun(t *testing.T) { event.InitializeState(cfg, nil, &config.SkaffoldOptions{}) l := Builder{ cfg: &latest.LocalBuild{}, - localDocker: docker.NewLocalDaemon(&test.api, nil), + localDocker: docker.NewLocalDaemon(&test.api, nil, false), pushImages: test.pushImages, } diff --git a/pkg/skaffold/build/plugin/plugin_test.go b/pkg/skaffold/build/plugin/plugin_test.go index 5abfb8e3d1a..e5e13f3f7ef 100644 --- a/pkg/skaffold/build/plugin/plugin_test.go +++ b/pkg/skaffold/build/plugin/plugin_test.go @@ -48,6 +48,10 @@ func (b *mockBuilder) DependenciesForArtifact(ctx context.Context, artifact *lat return nil, nil } +func (b *mockBuilder) Prune(ctx context.Context, out io.Writer) error { + return nil +} + func TestPluginBuilderLabels(t *testing.T) { tests := []struct { name string diff --git a/pkg/skaffold/runner/runner.go b/pkg/skaffold/runner/runner.go index ec5b93a4b16..48ae74f5d94 100644 --- a/pkg/skaffold/runner/runner.go +++ b/pkg/skaffold/runner/runner.go @@ -60,10 +60,10 @@ type SkaffoldRunner struct { builds []build.Artifact hasDeployed bool needsPush bool + hasBuilt bool imageList *kubernetes.ImageList namespaces []string RPCServerShutdown func() error - hasBuilt bool } // NewForConfig returns a new SkaffoldRunner for a SkaffoldPipeline diff --git a/pkg/skaffold/runner/runner_test.go b/pkg/skaffold/runner/runner_test.go index b18cc3f8710..bf6ca6ad651 100644 --- a/pkg/skaffold/runner/runner_test.go +++ b/pkg/skaffold/runner/runner_test.go @@ -60,6 +60,7 @@ func (t *TestBench) Labels() map[string]string { return m func (t *TestBench) TestDependencies() ([]string, error) { return nil, nil } func (t *TestBench) Dependencies() ([]string, error) { return nil, nil } func (t *TestBench) Cleanup(ctx context.Context, out io.Writer) error { return nil } +func (t *TestBench) Prune(ctx context.Context, out io.Writer) error { return nil } func (t *TestBench) DependenciesForArtifact(ctx context.Context, artifact *latest.Artifact) ([]string, error) { return nil, nil } @@ -96,6 +97,8 @@ func (t *TestBench) Sync(ctx context.Context, item *sync.Item) error { if len(t.syncErrors) > 0 { err := t.syncErrors[0] t.syncErrors = t.syncErrors[1:] + if err != nil { + return err } }