Update some assertions.

and fix some tests

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-12-20 17:54:31 -05:00
parent c26f37c0cc
commit 93615dd967
6 changed files with 38 additions and 35 deletions

View File

@ -47,7 +47,6 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
args []string args []string
outputRegex string
imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error) imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error)
}{ }{
{ {
@ -64,16 +63,17 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
name: "quiet", name: "quiet",
args: []string{"--quiet", "image:tag"}, args: []string{"--quiet", "image:tag"},
}, },
// TODO: This test is failing since the output does not contain an RFC3339 date
//{
// name: "non-human",
// args: []string{"--human=false", "image:tag"},
// outputRegex: "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}", // RFC3339 date format match
//},
{ {
name: "non-human-header", name: "non-human",
args: []string{"--human=false", "image:tag"}, args: []string{"--human=false", "image:tag"},
outputRegex: "CREATED\\sAT", imageHistoryFunc: func(img string) ([]image.HistoryResponseItem, error) {
return []image.HistoryResponseItem{{
ID: "abcdef",
Created: time.Date(2017, 1, 1, 12, 0, 3, 0, time.UTC).Unix(),
CreatedBy: "rose",
Comment: "new history item!",
}}, nil
},
}, },
{ {
name: "quiet-no-trunc", name: "quiet-no-trunc",
@ -94,10 +94,6 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
err := cmd.Execute() err := cmd.Execute()
assert.NoError(t, err) assert.NoError(t, err)
actual := cli.OutBuffer().String() actual := cli.OutBuffer().String()
if tc.outputRegex == "" {
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name)) golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
} else {
assert.Regexp(t, tc.outputRegex, actual)
}
} }
} }

View File

@ -0,0 +1,2 @@
IMAGE CREATED AT CREATED BY SIZE COMMENT
abcdef 2017-01-01T12:00:03Z rose 0 new history item!

View File

@ -48,8 +48,8 @@ func TestRemoveStackVersion124DoesNotRemoveConfigsOrSecrets(t *testing.T) {
assert.NoError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Equal(t, buildObjectIDs(client.services), client.removedServices) assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks) assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
assert.Nil(t, client.removedSecrets) assert.Len(t, client.removedSecrets, 0)
assert.Nil(t, client.removedConfigs) assert.Len(t, client.removedConfigs, 0)
} }
func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) { func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) {
@ -61,7 +61,7 @@ func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) {
assert.Equal(t, buildObjectIDs(client.services), client.removedServices) assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks) assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets) assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets)
assert.Nil(t, client.removedConfigs) assert.Len(t, client.removedConfigs, 0)
} }
func TestRemoveStackVersion130RemovesEverything(t *testing.T) { func TestRemoveStackVersion130RemovesEverything(t *testing.T) {

View File

@ -7,9 +7,15 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestPrunePromptPre131(t *testing.T) { func TestPrunePromptPre131DoesNotIncludeBuildCache(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{version: "1.30"}) cli := test.NewFakeCli(&fakeClient{version: "1.30"})
cmd := newPruneCommand(cli) cmd := newPruneCommand(cli)
assert.NoError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.NotContains(t, cli.OutBuffer().String(), "all build cache") expected := `WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
Are you sure you want to continue? [y/N] `
assert.Equal(t, expected, cli.OutBuffer().String())
} }

View File

@ -2,7 +2,6 @@ package loader
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"sort" "sort"
@ -738,13 +737,13 @@ services:
`) `)
require.Error(t, err) require.Error(t, err)
assert.IsType(t, &ForbiddenPropertiesError{}, err) forbidden, ok := err.(*ForbiddenPropertiesError)
fmt.Println(err) assert.True(t, ok, "error type is %T instead of ForbiddenPropertiesError", err)
forbidden := err.(*ForbiddenPropertiesError).Properties
assert.Len(t, forbidden, 2) props := forbidden.Properties
assert.Contains(t, forbidden, "volume_driver") assert.Len(t, props, 2)
assert.Contains(t, forbidden, "extends") assert.Contains(t, props, "volume_driver")
assert.Contains(t, props, "extends")
} }
func TestInvalidResource(t *testing.T) { func TestInvalidResource(t *testing.T) {

View File

@ -20,7 +20,7 @@ func defaultMapping(name string) (string, bool) {
func TestEscaped(t *testing.T) { func TestEscaped(t *testing.T) {
result, err := Substitute("$${foo}", defaultMapping) result, err := Substitute("$${foo}", defaultMapping)
assert.Nil(t, err) assert.NoError(t, err)
assert.Equal(t, "${foo}", result) assert.Equal(t, "${foo}", result)
} }
@ -44,14 +44,14 @@ func TestInvalid(t *testing.T) {
for _, template := range invalidTemplates { for _, template := range invalidTemplates {
_, err := Substitute(template, defaultMapping) _, err := Substitute(template, defaultMapping)
assert.Error(t, err) assert.Error(t, err)
assert.IsType(t, &InvalidTemplateError{}, err) assert.Contains(t, err.Error(), "Invalid template")
} }
} }
func TestNoValueNoDefault(t *testing.T) { func TestNoValueNoDefault(t *testing.T) {
for _, template := range []string{"This ${missing} var", "This ${BAR} var"} { for _, template := range []string{"This ${missing} var", "This ${BAR} var"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.Nil(t, err) assert.NoError(t, err)
assert.Equal(t, "This var", result) assert.Equal(t, "This var", result)
} }
} }
@ -59,7 +59,7 @@ func TestNoValueNoDefault(t *testing.T) {
func TestValueNoDefault(t *testing.T) { func TestValueNoDefault(t *testing.T) {
for _, template := range []string{"This $FOO var", "This ${FOO} var"} { for _, template := range []string{"This $FOO var", "This ${FOO} var"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.Nil(t, err) assert.NoError(t, err)
assert.Equal(t, "This first var", result) assert.Equal(t, "This first var", result)
} }
} }
@ -67,26 +67,26 @@ func TestValueNoDefault(t *testing.T) {
func TestNoValueWithDefault(t *testing.T) { func TestNoValueWithDefault(t *testing.T) {
for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} { for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.Nil(t, err) assert.NoError(t, err)
assert.Equal(t, "ok def", result) assert.Equal(t, "ok def", result)
} }
} }
func TestEmptyValueWithSoftDefault(t *testing.T) { func TestEmptyValueWithSoftDefault(t *testing.T) {
result, err := Substitute("ok ${BAR:-def}", defaultMapping) result, err := Substitute("ok ${BAR:-def}", defaultMapping)
assert.Nil(t, err) assert.NoError(t, err)
assert.Equal(t, "ok def", result) assert.Equal(t, "ok def", result)
} }
func TestEmptyValueWithHardDefault(t *testing.T) { func TestEmptyValueWithHardDefault(t *testing.T) {
result, err := Substitute("ok ${BAR-def}", defaultMapping) result, err := Substitute("ok ${BAR-def}", defaultMapping)
assert.Nil(t, err) assert.NoError(t, err)
assert.Equal(t, "ok ", result) assert.Equal(t, "ok ", result)
} }
func TestNonAlphanumericDefault(t *testing.T) { func TestNonAlphanumericDefault(t *testing.T) {
result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping) result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping)
assert.Nil(t, err) assert.NoError(t, err)
assert.Equal(t, "ok /non:-alphanumeric", result) assert.Equal(t, "ok /non:-alphanumeric", result)
} }