mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-06-05 06:59:23 +00:00
128 lines
2 KiB
Go
128 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")
|
||
|
}
|
||
|
}
|