github.com/kunnos/engine@v1.13.1/cli/compose/convert/compose_test.go (about)

     1  package convert
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/docker/api/types"
     7  	"github.com/docker/docker/api/types/network"
     8  	composetypes "github.com/docker/docker/cli/compose/types"
     9  	"github.com/docker/docker/pkg/testutil/assert"
    10  	"github.com/docker/docker/pkg/testutil/tempfile"
    11  )
    12  
    13  func TestNamespaceScope(t *testing.T) {
    14  	scoped := Namespace{name: "foo"}.Scope("bar")
    15  	assert.Equal(t, scoped, "foo_bar")
    16  }
    17  
    18  func TestAddStackLabel(t *testing.T) {
    19  	labels := map[string]string{
    20  		"something": "labeled",
    21  	}
    22  	actual := AddStackLabel(Namespace{name: "foo"}, labels)
    23  	expected := map[string]string{
    24  		"something":    "labeled",
    25  		LabelNamespace: "foo",
    26  	}
    27  	assert.DeepEqual(t, actual, expected)
    28  }
    29  
    30  func TestNetworks(t *testing.T) {
    31  	namespace := Namespace{name: "foo"}
    32  	source := networkMap{
    33  		"normal": composetypes.NetworkConfig{
    34  			Driver: "overlay",
    35  			DriverOpts: map[string]string{
    36  				"opt": "value",
    37  			},
    38  			Ipam: composetypes.IPAMConfig{
    39  				Driver: "driver",
    40  				Config: []*composetypes.IPAMPool{
    41  					{
    42  						Subnet: "10.0.0.0",
    43  					},
    44  				},
    45  			},
    46  			Labels: map[string]string{
    47  				"something": "labeled",
    48  			},
    49  		},
    50  		"outside": composetypes.NetworkConfig{
    51  			External: composetypes.External{
    52  				External: true,
    53  				Name:     "special",
    54  			},
    55  		},
    56  	}
    57  	expected := map[string]types.NetworkCreate{
    58  		"default": {
    59  			Labels: map[string]string{
    60  				LabelNamespace: "foo",
    61  			},
    62  		},
    63  		"normal": {
    64  			Driver: "overlay",
    65  			IPAM: &network.IPAM{
    66  				Driver: "driver",
    67  				Config: []network.IPAMConfig{
    68  					{
    69  						Subnet: "10.0.0.0",
    70  					},
    71  				},
    72  			},
    73  			Options: map[string]string{
    74  				"opt": "value",
    75  			},
    76  			Labels: map[string]string{
    77  				LabelNamespace: "foo",
    78  				"something":    "labeled",
    79  			},
    80  		},
    81  	}
    82  
    83  	serviceNetworks := map[string]struct{}{
    84  		"default": {},
    85  		"normal":  {},
    86  		"outside": {},
    87  	}
    88  	networks, externals := Networks(namespace, source, serviceNetworks)
    89  	assert.DeepEqual(t, networks, expected)
    90  	assert.DeepEqual(t, externals, []string{"special"})
    91  }
    92  
    93  func TestSecrets(t *testing.T) {
    94  	namespace := Namespace{name: "foo"}
    95  
    96  	secretText := "this is the first secret"
    97  	secretFile := tempfile.NewTempFile(t, "convert-secrets", secretText)
    98  	defer secretFile.Remove()
    99  
   100  	source := map[string]composetypes.SecretConfig{
   101  		"one": {
   102  			File:   secretFile.Name(),
   103  			Labels: map[string]string{"monster": "mash"},
   104  		},
   105  		"ext": {
   106  			External: composetypes.External{
   107  				External: true,
   108  			},
   109  		},
   110  	}
   111  
   112  	specs, err := Secrets(namespace, source)
   113  	assert.NilError(t, err)
   114  	assert.Equal(t, len(specs), 1)
   115  	secret := specs[0]
   116  	assert.Equal(t, secret.Name, "foo_one")
   117  	assert.DeepEqual(t, secret.Labels, map[string]string{
   118  		"monster":      "mash",
   119  		LabelNamespace: "foo",
   120  	})
   121  	assert.DeepEqual(t, secret.Data, []byte(secretText))
   122  }