Skip to content

Commit

Permalink
Small random fixes to tests and code (#2801)
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot authored Sep 4, 2019
1 parent 47cf0d5 commit b4ba29a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
14 changes: 8 additions & 6 deletions cmd/skaffold/app/cmd/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ deploy:
- k8s/deployment.yaml
`, latest.Version)

cfgFile, teardown := testutil.TempFile(t, "config", []byte(inputYaml))
defer teardown()
testutil.Run(t, "", func(t *testutil.T) {
cfgFile := t.TempFile("config", []byte(inputYaml))

var b bytes.Buffer
err := fix(&b, cfgFile, true)
var b bytes.Buffer
err := fix(&b, cfgFile, true)

output, _ := ioutil.ReadFile(cfgFile)
output, _ := ioutil.ReadFile(cfgFile)

testutil.CheckErrorAndDeepEqual(t, false, err, expectedOutput, string(output))
t.CheckNoError(err)
t.CheckDeepEqual(expectedOutput, string(output))
})
}
3 changes: 3 additions & 0 deletions pkg/skaffold/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func newMinikubeAPIClient() ([]string, client.CommonAPIClient, error) {
client.WithHost(host),
client.WithHTTPClient(httpclient),
client.WithHTTPHeaders(getUserAgentHeader()))
if err != nil {
return nil, nil, err
}

if api != nil {
api.NegotiateAPIVersion(context.Background())
Expand Down
5 changes: 1 addition & 4 deletions pkg/skaffold/docker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ DOCKER_API_VERSION=1.23`,

env, _, err := newMinikubeAPIClient()

t.CheckError(test.shouldErr, err)
if !test.shouldErr {
t.CheckDeepEqual(test.expectedEnv, env)
}
t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedEnv, env)
})
}
}
1 change: 1 addition & 0 deletions pkg/skaffold/docker/docker_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func TestCreateArtifact(t *testing.T) {
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
artifact := test.dockerfile.CreateArtifact(test.manifestImage)

t.CheckDeepEqual(test.expectedArtifact, *artifact)
})
}
Expand Down
35 changes: 13 additions & 22 deletions pkg/skaffold/docker/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,25 @@ func ParseReference(image string) (*ImageReference, error) {
return nil, err
}

baseName := image
var domain string
var path string
if n, ok := r.(reference.Named); ok {
baseName = n.Name()
domain = reference.Domain(n)
path = reference.Path(n)
parsed := &ImageReference{
BaseName: image,
}

fullyQualified := false
tag := ""
digest := ""
if n, ok := r.(reference.Named); ok {
parsed.BaseName = n.Name()
parsed.Domain = reference.Domain(n)
parsed.Path = reference.Path(n)
}

if n, ok := r.(reference.Tagged); ok {
tag = n.Tag()
fullyQualified = n.Tag() != "latest"
parsed.Tag = n.Tag()
parsed.FullyQualified = n.Tag() != "latest"
}

if n, ok := r.(reference.Digested); ok {
fullyQualified = true
digest = n.Digest().String()
parsed.Digest = n.Digest().String()
parsed.FullyQualified = true
}

return &ImageReference{
BaseName: baseName,
Domain: domain,
Path: path,
Tag: tag,
Digest: digest,
FullyQualified: fullyQualified,
}, nil
return parsed, nil
}
18 changes: 13 additions & 5 deletions pkg/skaffold/docker/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestParseReference(t *testing.T) {
expectedTag string
expectedDigest string
expectedFullyQualified bool
shoudErr bool
}{
{
description: "port and tag",
Expand Down Expand Up @@ -81,16 +82,23 @@ func TestParseReference(t *testing.T) {
expectedTag: "latest",
expectedFullyQualified: false,
},
{
description: "invalid reference",
image: "!!invalid!!",
shoudErr: true,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
parsed, err := ParseReference(test.image)

t.CheckNoError(err)
t.CheckDeepEqual(test.expectedName, parsed.BaseName)
t.CheckDeepEqual(test.expectedTag, parsed.Tag)
t.CheckDeepEqual(test.expectedDigest, parsed.Digest)
t.CheckDeepEqual(test.expectedFullyQualified, parsed.FullyQualified)
t.CheckError(test.shoudErr, err)
if !test.shoudErr {
t.CheckDeepEqual(test.expectedName, parsed.BaseName)
t.CheckDeepEqual(test.expectedTag, parsed.Tag)
t.CheckDeepEqual(test.expectedDigest, parsed.Digest)
t.CheckDeepEqual(test.expectedFullyQualified, parsed.FullyQualified)
}
})
}
}
4 changes: 2 additions & 2 deletions pkg/skaffold/kubectl/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *CLI) Run(ctx context.Context, in io.Reader, out io.Writer, command stri
return util.RunCmd(cmd)
}

// Run shells out kubectl CLI with given namespace
// RunInNamespace shells out kubectl CLI with given namespace
func (c *CLI) RunInNamespace(ctx context.Context, in io.Reader, out io.Writer, command string, namespace string, arg ...string) error {
cmd := c.CommandWithNamespaceArg(ctx, command, namespace, arg...)
cmd.Stdin = in
Expand All @@ -72,7 +72,7 @@ func (c *CLI) RunInNamespace(ctx context.Context, in io.Reader, out io.Writer, c
return util.RunCmd(cmd)
}

// Run shells out kubectl CLI.
// RunOut shells out kubectl CLI.
func (c *CLI) RunOut(ctx context.Context, command string, arg ...string) ([]byte, error) {
cmd := c.Command(ctx, command, arg...)
return util.RunCmdOut(cmd)
Expand Down

0 comments on commit b4ba29a

Please sign in to comment.