Skip to content

Commit

Permalink
Run TestGetconf test cases in subtests
Browse files Browse the repository at this point in the history
  • Loading branch information
tklauser committed May 5, 2023
1 parent 5abe452 commit 39dc243
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions sysconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,26 @@ func TestGetconf(t *testing.T) {
}

for _, tc := range testCases {
cmd := exec.Command(getconf, tc.name)
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
// Ignore getconf errors and skip the test
t.Skipf("failed to invoke getconf: %v", err)
break
}
want, err := strconv.ParseInt(strings.TrimSpace(out.String()), 10, 64)
if err != nil {
t.Errorf("strconv.ParseInt: %v", err)
}
t.Run(tc.name, func(t *testing.T) {
cmd := exec.Command(getconf, tc.name)
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
// Ignore getconf errors and skip the test
t.Skipf("failed to invoke getconf: %v", err)
}
want, err := strconv.ParseInt(strings.TrimSpace(out.String()), 10, 64)
if err != nil {
t.Errorf("strconv.ParseInt: %v", err)
}

got, err := sysconf.Sysconf(tc.goVar)
if err != nil {
t.Errorf("Sysconf(%s/%d): %v", tc.name, tc.goVar, err)
}

if got != want {
t.Errorf("Sysconf(%v/%d) returned %v, want %v", tc.name, tc.goVar, got, want)
}
got, err := sysconf.Sysconf(tc.goVar)
if err != nil {
t.Errorf("Sysconf(%s/%d): %v", tc.name, tc.goVar, err)
}
if got != want {
t.Errorf("Sysconf(%v/%d) returned %v, want %v", tc.name, tc.goVar, got, want)
}
})
}
}

0 comments on commit 39dc243

Please sign in to comment.