mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-06-07 07:59:36 +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)
129 lines
2 KiB
Go
129 lines
2 KiB
Go
package types
|
|
|
|
import (
|
|
"testing"
|
|
|
|
todo_yaml "gopkg.in/yaml.v2"
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMarshalUlimit(t *testing.T) {
|
|
ulimits := []struct {
|
|
ulimits *Ulimits
|
|
expected string
|
|
}{
|
|
{
|
|
ulimits: &Ulimits{
|
|
Elements: []Ulimit{
|
|
{
|
|
ulimitValues: ulimitValues{
|
|
Soft: 65535,
|
|
Hard: 65535,
|
|
},
|
|
Name: "nproc",
|
|
},
|
|
},
|
|
},
|
|
expected: `nproc: 65535
|
|
`,
|
|
},
|
|
{
|
|
ulimits: &Ulimits{
|
|
Elements: []Ulimit{
|
|
{
|
|
Name: "nofile",
|
|
ulimitValues: ulimitValues{
|
|
Soft: 20000,
|
|
Hard: 40000,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: `nofile:
|
|
soft: 20000
|
|
hard: 40000
|
|
`,
|
|
},
|
|
}
|
|
|
|
for _, ulimit := range ulimits {
|
|
|
|
bytes, err := yaml.Marshal(ulimit.ulimits)
|
|
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, ulimit.expected, string(bytes), "should be equal")
|
|
}
|
|
}
|
|
|
|
func TestUnmarshalUlimits(t *testing.T) {
|
|
ulimits := []struct {
|
|
yaml string
|
|
expected *Ulimits
|
|
}{
|
|
{
|
|
yaml: "nproc: 65535",
|
|
expected: &Ulimits{
|
|
Elements: []Ulimit{
|
|
{
|
|
Name: "nproc",
|
|
ulimitValues: ulimitValues{
|
|
Soft: 65535,
|
|
Hard: 65535,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
yaml: `nofile:
|
|
soft: 20000
|
|
hard: 40000`,
|
|
expected: &Ulimits{
|
|
Elements: []Ulimit{
|
|
{
|
|
Name: "nofile",
|
|
ulimitValues: ulimitValues{
|
|
Soft: 20000,
|
|
Hard: 40000,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
yaml: `nproc: 65535
|
|
nofile:
|
|
soft: 20000
|
|
hard: 40000`,
|
|
expected: &Ulimits{
|
|
Elements: []Ulimit{
|
|
{
|
|
Name: "nofile",
|
|
ulimitValues: ulimitValues{
|
|
Soft: 20000,
|
|
Hard: 40000,
|
|
},
|
|
},
|
|
{
|
|
Name: "nproc",
|
|
ulimitValues: ulimitValues{
|
|
Soft: 65535,
|
|
Hard: 65535,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, ulimit := range ulimits {
|
|
actual := &Ulimits{}
|
|
err := todo_yaml.Unmarshal([]byte(ulimit.yaml), actual)
|
|
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, ulimit.expected, actual, "should be equal")
|
|
}
|
|
}
|