Skip to content

Commit

Permalink
[common-go] Add test for reading psi values
Browse files Browse the repository at this point in the history
  • Loading branch information
Furisto committed Oct 14, 2022
1 parent 638f6b3 commit 337ce0c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions components/common-go/cgroups/cgroups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,56 @@ func TestReadSingleValue(t *testing.T) {
})
}
}

func TestReadPSI(t *testing.T) {
scenarios := []struct {
name string
content string
expected PSI
}{
{
name: "psi some",
content: "some avg10=61.00 avg60=64.28 avg300=29.94 total=149969752",
expected: PSI{
Some: 149969752,
Full: 0,
},
},
{
name: "psi full",
content: "full avg10=36.27 avg60=37.15 avg300=17.59 total=93027571",
expected: PSI{
Some: 0,
Full: 93027571,
},
},
{
name: "psi some and full",
content: "some avg10=61.00 avg60=64.28 avg300=29.94 total=149969752\nfull avg10=36.27 avg60=37.15 avg300=17.59 total=93027571",
expected: PSI{
Some: 149969752,
Full: 93027571,
},
},
}

for _, s := range scenarios {
t.Run(s.name, func(t *testing.T) {
f, err := os.CreateTemp("", "cgroup_test*")
if err != nil {
t.Fatal(err)
}

if _, err := f.Write([]byte(s.content)); err != nil {
t.Fatal(err)
}

v, err := ReadPSIValue(f.Name())
if err != nil {
t.Fatal(err)
}

assert.Equal(t, s.expected, v)
})
}
}

0 comments on commit 337ce0c

Please sign in to comment.