woodpecker/pipeline/frontend/yaml/types/ulimit_test.go
Harikesh00 36e42914fa
Renamed procs/jobs to steps in code (#1331)
Renamed `procs` to `steps` in code for the issue #1288

Co-authored-by: Harikesh Prajapati <harikesh.prajapati@druva.com>
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2022-10-28 17:38:53 +02:00

127 lines
1.9 KiB
Go

package types
import (
"testing"
"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: "nstep",
},
},
},
expected: `nstep: 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: "nstep: 65535",
expected: &Ulimits{
Elements: []Ulimit{
{
Name: "nstep",
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: `nstep: 65535
nofile:
soft: 20000
hard: 40000`,
expected: &Ulimits{
Elements: []Ulimit{
{
Name: "nofile",
ulimitValues: ulimitValues{
Soft: 20000,
Hard: 40000,
},
},
{
Name: "nstep",
ulimitValues: ulimitValues{
Soft: 65535,
Hard: 65535,
},
},
},
},
},
}
for _, ulimit := range ulimits {
actual := &Ulimits{}
err := yaml.Unmarshal([]byte(ulimit.yaml), actual)
assert.Nil(t, err)
assert.Equal(t, ulimit.expected, actual, "should be equal")
}
}