mirror of https://github.com/docker/cli.git
Update some assertions.
and fix some tests Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
c26f37c0cc
commit
93615dd967
|
@ -47,7 +47,6 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
|
|||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
outputRegex string
|
||||
imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error)
|
||||
}{
|
||||
{
|
||||
|
@ -64,16 +63,17 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
|
|||
name: "quiet",
|
||||
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",
|
||||
args: []string{"--human=false", "image:tag"},
|
||||
outputRegex: "CREATED\\sAT",
|
||||
name: "non-human",
|
||||
args: []string{"--human=false", "image:tag"},
|
||||
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",
|
||||
|
@ -94,10 +94,6 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
|
|||
err := cmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
actual := cli.OutBuffer().String()
|
||||
if tc.outputRegex == "" {
|
||||
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
|
||||
} else {
|
||||
assert.Regexp(t, tc.outputRegex, actual)
|
||||
}
|
||||
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
IMAGE CREATED AT CREATED BY SIZE COMMENT
|
||||
abcdef 2017-01-01T12:00:03Z rose 0 new history item!
|
|
@ -48,8 +48,8 @@ func TestRemoveStackVersion124DoesNotRemoveConfigsOrSecrets(t *testing.T) {
|
|||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
|
||||
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
|
||||
assert.Nil(t, client.removedSecrets)
|
||||
assert.Nil(t, client.removedConfigs)
|
||||
assert.Len(t, client.removedSecrets, 0)
|
||||
assert.Len(t, client.removedConfigs, 0)
|
||||
}
|
||||
|
||||
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.networks), client.removedNetworks)
|
||||
assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets)
|
||||
assert.Nil(t, client.removedConfigs)
|
||||
assert.Len(t, client.removedConfigs, 0)
|
||||
}
|
||||
|
||||
func TestRemoveStackVersion130RemovesEverything(t *testing.T) {
|
||||
|
|
|
@ -7,9 +7,15 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPrunePromptPre131(t *testing.T) {
|
||||
func TestPrunePromptPre131DoesNotIncludeBuildCache(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{version: "1.30"})
|
||||
cmd := newPruneCommand(cli)
|
||||
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())
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package loader
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
|
@ -738,13 +737,13 @@ services:
|
|||
`)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.IsType(t, &ForbiddenPropertiesError{}, err)
|
||||
fmt.Println(err)
|
||||
forbidden := err.(*ForbiddenPropertiesError).Properties
|
||||
forbidden, ok := err.(*ForbiddenPropertiesError)
|
||||
assert.True(t, ok, "error type is %T instead of ForbiddenPropertiesError", err)
|
||||
|
||||
assert.Len(t, forbidden, 2)
|
||||
assert.Contains(t, forbidden, "volume_driver")
|
||||
assert.Contains(t, forbidden, "extends")
|
||||
props := forbidden.Properties
|
||||
assert.Len(t, props, 2)
|
||||
assert.Contains(t, props, "volume_driver")
|
||||
assert.Contains(t, props, "extends")
|
||||
}
|
||||
|
||||
func TestInvalidResource(t *testing.T) {
|
||||
|
|
|
@ -20,7 +20,7 @@ func defaultMapping(name string) (string, bool) {
|
|||
|
||||
func TestEscaped(t *testing.T) {
|
||||
result, err := Substitute("$${foo}", defaultMapping)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "${foo}", result)
|
||||
}
|
||||
|
||||
|
@ -44,14 +44,14 @@ func TestInvalid(t *testing.T) {
|
|||
for _, template := range invalidTemplates {
|
||||
_, err := Substitute(template, defaultMapping)
|
||||
assert.Error(t, err)
|
||||
assert.IsType(t, &InvalidTemplateError{}, err)
|
||||
assert.Contains(t, err.Error(), "Invalid template")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoValueNoDefault(t *testing.T) {
|
||||
for _, template := range []string{"This ${missing} var", "This ${BAR} var"} {
|
||||
result, err := Substitute(template, defaultMapping)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "This var", result)
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func TestNoValueNoDefault(t *testing.T) {
|
|||
func TestValueNoDefault(t *testing.T) {
|
||||
for _, template := range []string{"This $FOO var", "This ${FOO} var"} {
|
||||
result, err := Substitute(template, defaultMapping)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "This first var", result)
|
||||
}
|
||||
}
|
||||
|
@ -67,26 +67,26 @@ func TestValueNoDefault(t *testing.T) {
|
|||
func TestNoValueWithDefault(t *testing.T) {
|
||||
for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} {
|
||||
result, err := Substitute(template, defaultMapping)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "ok def", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyValueWithSoftDefault(t *testing.T) {
|
||||
result, err := Substitute("ok ${BAR:-def}", defaultMapping)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "ok def", result)
|
||||
}
|
||||
|
||||
func TestEmptyValueWithHardDefault(t *testing.T) {
|
||||
result, err := Substitute("ok ${BAR-def}", defaultMapping)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "ok ", result)
|
||||
}
|
||||
|
||||
func TestNonAlphanumericDefault(t *testing.T) {
|
||||
result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping)
|
||||
assert.Nil(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "ok /non:-alphanumeric", result)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue