mirror of https://github.com/docker/cli.git
Add unit tests for some convert/service
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
a68c940f1a
commit
f1cc679618
|
@ -1,6 +1,7 @@
|
||||||
package convert
|
package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -9,7 +10,9 @@ import (
|
||||||
composetypes "github.com/docker/cli/cli/compose/types"
|
composetypes "github.com/docker/cli/cli/compose/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromNone(t *testing.T) {
|
func TestConvertRestartPolicyFromNone(t *testing.T) {
|
||||||
|
@ -372,3 +375,52 @@ func TestConvertUpdateConfigOrder(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.Equal(t, updateConfig.Order, "stop-first")
|
assert.Equal(t, updateConfig.Order, "stop-first")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertFileObject(t *testing.T) {
|
||||||
|
namespace := NewNamespace("testing")
|
||||||
|
config := composetypes.FileReferenceConfig{
|
||||||
|
Source: "source",
|
||||||
|
Target: "target",
|
||||||
|
UID: "user",
|
||||||
|
GID: "group",
|
||||||
|
Mode: uint32Ptr(0644),
|
||||||
|
}
|
||||||
|
swarmRef, err := convertFileObject(namespace, config, lookupConfig)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
expected := swarmReferenceObject{
|
||||||
|
Name: "testing_source",
|
||||||
|
File: swarmReferenceTarget{
|
||||||
|
Name: config.Target,
|
||||||
|
UID: config.UID,
|
||||||
|
GID: config.GID,
|
||||||
|
Mode: os.FileMode(0644),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, swarmRef)
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookupConfig(key string) (composetypes.FileObjectConfig, error) {
|
||||||
|
if key != "source" {
|
||||||
|
return composetypes.FileObjectConfig{}, errors.New("bad key")
|
||||||
|
}
|
||||||
|
return composetypes.FileObjectConfig{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConvertFileObjectDefaults(t *testing.T) {
|
||||||
|
namespace := NewNamespace("testing")
|
||||||
|
config := composetypes.FileReferenceConfig{Source: "source"}
|
||||||
|
swarmRef, err := convertFileObject(namespace, config, lookupConfig)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
expected := swarmReferenceObject{
|
||||||
|
Name: "testing_source",
|
||||||
|
File: swarmReferenceTarget{
|
||||||
|
Name: config.Source,
|
||||||
|
UID: "0",
|
||||||
|
GID: "0",
|
||||||
|
Mode: os.FileMode(0444),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, swarmRef)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue