Skip to content

Commit

Permalink
Merge pull request #1251 from nkubala/skaffold_fix_tests
Browse files Browse the repository at this point in the history
Don't lose test configuration when running skaffold fix
  • Loading branch information
nkubala authored Nov 8, 2018
2 parents b645a36 + ab89819 commit 2dbbdce
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 8 deletions.
113 changes: 113 additions & 0 deletions cmd/skaffold/app/cmd/fix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Copyright 2018 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 cmd

import (
"bytes"
"fmt"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestFix(t *testing.T) {
tests := []struct {
name string
inputYaml string
outputYaml string
shouldErr bool
}{
{
name: "v1alpha4 to latest",
inputYaml: `apiVersion: skaffold/v1alpha4
kind: Config
build:
artifacts:
- image: docker/image
docker:
dockerfile: dockerfile.test
test:
- image: docker/image
structureTests:
- ./test/*
deploy:
kubectl:
manifests:
- k8s/deployment.yaml
`,
outputYaml: fmt.Sprintf(`apiVersion: %s
kind: Config
build:
artifacts:
- image: docker/image
docker:
dockerfile: dockerfile.test
test:
- image: docker/image
structureTests:
- ./test/*
deploy:
kubectl:
manifests:
- k8s/deployment.yaml
`, latest.Version),
},
{
name: "v1alpha1 to latest",
inputYaml: `apiVersion: skaffold/v1alpha1
kind: Config
build:
artifacts:
- imageName: docker/image
dockerfilePath: dockerfile.test
deploy:
kubectl:
manifests:
- paths:
- k8s/deployment.yaml
`,
outputYaml: fmt.Sprintf(`apiVersion: %s
kind: Config
build:
artifacts:
- image: docker/image
docker:
dockerfile: dockerfile.test
deploy:
kubectl:
manifests:
- k8s/deployment.yaml
`, latest.Version),
},
}

for _, tt := range tests {
cfgFile, teardown := testutil.TempFile(t, "config", []byte(tt.inputYaml))
defer teardown()

cfg, err := schema.ParseConfig(cfgFile, false)
if err != nil {
t.Fatalf(err.Error())
}
var b bytes.Buffer
err = runFix(&b, cfg)

testutil.CheckErrorAndDeepEqual(t, tt.shouldErr, err, tt.outputYaml, b.String())
}
}
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func getBuilder(cfg *latest.BuildConfig, kubeContext string) (build.Builder, err
}
}

func getTester(cfg *[]*latest.TestCase) (test.Tester, error) {
func getTester(cfg *latest.TestConfig) (test.Tester, error) {
return test.NewTester(cfg)
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type SkaffoldPipeline struct {
Kind string `yaml:"kind"`

Build BuildConfig `yaml:"build,omitempty"`
Test []*TestCase `yaml:"test,omitempty"`
Test TestConfig `yaml:"test,omitempty"`
Deploy DeployConfig `yaml:"deploy,omitempty"`
Profiles []Profile `yaml:"profiles,omitempty"`
}
Expand Down Expand Up @@ -133,6 +133,8 @@ type AzureContainerBuild struct {
TenantID string `yaml:"tenantId,omitempty"`
}

type TestConfig []*TestCase

// TestCase is a struct containing all the specified test
// configuration for an image.
type TestCase struct {
Expand Down Expand Up @@ -237,7 +239,7 @@ type Artifact struct {
type Profile struct {
Name string `yaml:"name,omitempty"`
Build BuildConfig `yaml:"build,omitempty"`
Test []*TestCase `yaml:"test,omitempty"`
Test TestConfig `yaml:"test,omitempty"`
Deploy DeployConfig `yaml:"deploy,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/schema/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func applyProfile(config *latest.SkaffoldPipeline, profile latest.Profile) {
Kind: config.Kind,
Build: overlayProfileField(config.Build, profile.Build).(latest.BuildConfig),
Deploy: overlayProfileField(config.Deploy, profile.Deploy).(latest.DeployConfig),
Test: overlayProfileField(config.Test, profile.Test).([]*latest.TestCase),
Test: overlayProfileField(config.Test, profile.Test).(latest.TestConfig),
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/skaffold/schema/v1alpha4/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ type SkaffoldPipeline struct {
Kind string `yaml:"kind"`

Build BuildConfig `yaml:"build,omitempty"`
Test []TestCase `yaml:"test,omitempty"`
Test TestConfig `yaml:"test,omitempty"`
Deploy DeployConfig `yaml:"deploy,omitempty"`
Profiles []Profile `yaml:"profiles,omitempty"`
}

type TestConfig []TestCase

func (c *SkaffoldPipeline) GetVersion() string {
return c.APIVersion
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/skaffold/schema/v1alpha4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,18 @@ func (config *SkaffoldPipeline) Upgrade() (util.VersionedConfig, error) {
return nil, errors.Wrap(err, "converting new build")
}

// convert Test (should be the same)
var newTest next.TestConfig
if err := convert(config.Test, &newTest); err != nil {
return nil, errors.Wrap(err, "converting new test")
}

return &next.SkaffoldPipeline{
APIVersion: next.Version,
Kind: config.Kind,
Deploy: newDeploy,
Build: newBuild,
Test: newTest,
Deploy: newDeploy,
Profiles: newProfiles,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// NewTester parses the provided test cases from the Skaffold config,
// and returns a Tester instance with all the necessary test runners
// to run all specified tests.
func NewTester(testCases *[]*latest.TestCase) (Tester, error) {
func NewTester(testCases *latest.TestConfig) (Tester, error) {
// TODO(nkubala): copied this from runner.getDeployer(), this should be moved somewhere else
cwd, err := os.Getwd()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/test/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Tester interface {
// FullTester should always be the ONLY implementation of the Tester interface;
// newly added testing implementations should implement the Runner interface.
type FullTester struct {
testCases *[]*latest.TestCase
testCases *latest.TestConfig
workingDir string
}

Expand Down

0 comments on commit 2dbbdce

Please sign in to comment.