From 6217d50803fea52d0395d8442cf8ce80963ba7ba Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 24 May 2019 21:30:45 -0500 Subject: [PATCH] Fix test comparisons --- .../shared/executor/executor_linux_test.go | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/shared/executor/executor_linux_test.go b/drivers/shared/executor/executor_linux_test.go index c3c93c463fef..ed87a1dc7910 100644 --- a/drivers/shared/executor/executor_linux_test.go +++ b/drivers/shared/executor/executor_linux_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "regexp" "strconv" "strings" "testing" @@ -151,7 +152,8 @@ usr/ /etc/: ld.so.cache ld.so.conf -ld.so.conf.d/` +ld.so.conf.d/ +passwd` tu.WaitForResult(func() (bool, error) { output := testExecCmd.stdout.String() act := strings.TrimSpace(string(output)) @@ -251,20 +253,20 @@ func TestExecutor_Capabilities(t *testing.T) { { user: "nobody", caps: ` -CapInh: 0000000000000000 -CapPrm: 0000000000000000 -CapEff: 0000000000000000 -CapBnd: 0000003fffffffff -CapAmb: 0000000000000000`, +CapInh: 0000000000000000 +CapPrm: 0000000000000000 +CapEff: 0000000000000000 +CapBnd: 0000003fffffffff +CapAmb: 0000000000000000`, }, { user: "root", caps: ` -CapInh: 0000000000000000 -CapPrm: 0000003fffffffff -CapEff: 0000003fffffffff -CapBnd: 0000003fffffffff -CapAmb: 0000000000000000`, +CapInh: 0000000000000000 +CapPrm: 0000003fffffffff +CapEff: 0000003fffffffff +CapBnd: 0000003fffffffff +CapAmb: 0000000000000000`, }, } @@ -300,12 +302,18 @@ CapAmb: 0000000000000000`, require.Fail("timeout waiting for exec to shutdown") } - expected := strings.TrimSpace(c.caps) + canonical := func(s string) string { + s = strings.TrimSpace(s) + s = regexp.MustCompile("[ \t]+").ReplaceAllString(s, " ") + s = regexp.MustCompile("[\n\r]+").ReplaceAllString(s, "\n") + return s + } + + expected := canonical(c.caps) tu.WaitForResult(func() (bool, error) { - output := testExecCmd.stdout.String() - act := strings.TrimSpace(string(output)) - if strings.Contains(output, expected) { - return false, fmt.Errorf("capabilities didn't match: want\n%v\n; got:\n%v\n", expected, act) + output := canonical(testExecCmd.stdout.String()) + if !strings.Contains(output, expected) { + return false, fmt.Errorf("capabilities didn't match: want\n%v\n; got:\n%v\n", expected, output) } return true, nil }, func(err error) { require.NoError(err) })