mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-09-27 14:10:17 +00:00
0bb62be303
since github.com/docker/libcompose is deprecated, unmaintained and archived. and license is the same as woodpecker's, we can just copy stuff into woodpecker directly. (we only use types of that project anyway)
143 lines
2.5 KiB
Go
143 lines
2.5 KiB
Go
package types
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMarshalVolumes(t *testing.T) {
|
|
volumes := []struct {
|
|
volumes Volumes
|
|
expected string
|
|
}{
|
|
{
|
|
volumes: Volumes{},
|
|
expected: `[]
|
|
`,
|
|
},
|
|
{
|
|
volumes: Volumes{
|
|
Volumes: []*Volume{
|
|
{
|
|
Destination: "/in/the/container",
|
|
},
|
|
},
|
|
},
|
|
expected: `- /in/the/container
|
|
`,
|
|
},
|
|
{
|
|
volumes: Volumes{
|
|
Volumes: []*Volume{
|
|
{
|
|
Source: "./a/path",
|
|
Destination: "/in/the/container",
|
|
AccessMode: "ro",
|
|
},
|
|
},
|
|
},
|
|
expected: `- ./a/path:/in/the/container:ro
|
|
`,
|
|
},
|
|
{
|
|
volumes: Volumes{
|
|
Volumes: []*Volume{
|
|
{
|
|
Source: "./a/path",
|
|
Destination: "/in/the/container",
|
|
},
|
|
},
|
|
},
|
|
expected: `- ./a/path:/in/the/container
|
|
`,
|
|
},
|
|
{
|
|
volumes: Volumes{
|
|
Volumes: []*Volume{
|
|
{
|
|
Source: "./a/path",
|
|
Destination: "/in/the/container",
|
|
},
|
|
{
|
|
Source: "named",
|
|
Destination: "/in/the/container",
|
|
},
|
|
},
|
|
},
|
|
expected: `- ./a/path:/in/the/container
|
|
- named:/in/the/container
|
|
`,
|
|
},
|
|
}
|
|
for _, volume := range volumes {
|
|
bytes, err := yaml.Marshal(volume.volumes)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, volume.expected, string(bytes), "should be equal")
|
|
}
|
|
}
|
|
|
|
func TestUnmarshalVolumes(t *testing.T) {
|
|
volumes := []struct {
|
|
yaml string
|
|
expected *Volumes
|
|
}{
|
|
{
|
|
yaml: `- ./a/path:/in/the/container`,
|
|
expected: &Volumes{
|
|
Volumes: []*Volume{
|
|
{
|
|
Source: "./a/path",
|
|
Destination: "/in/the/container",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
yaml: `- /in/the/container`,
|
|
expected: &Volumes{
|
|
Volumes: []*Volume{
|
|
{
|
|
Destination: "/in/the/container",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
yaml: `- /a/path:/in/the/container:ro`,
|
|
expected: &Volumes{
|
|
Volumes: []*Volume{
|
|
{
|
|
Source: "/a/path",
|
|
Destination: "/in/the/container",
|
|
AccessMode: "ro",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
yaml: `- /a/path:/in/the/container
|
|
- named:/somewhere/in/the/container`,
|
|
expected: &Volumes{
|
|
Volumes: []*Volume{
|
|
{
|
|
Source: "/a/path",
|
|
Destination: "/in/the/container",
|
|
},
|
|
{
|
|
Source: "named",
|
|
Destination: "/somewhere/in/the/container",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, volume := range volumes {
|
|
actual := &Volumes{}
|
|
err := yaml.Unmarshal([]byte(volume.yaml), actual)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, volume.expected, actual, "should be equal")
|
|
}
|
|
}
|