Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mantle/kola/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ func (t *TestCluster) AssertCmdOutputContains(m platform.Machine, cmd string, ex
}
}

// AssertCmdOutputDoesNotContain runs cmd via SSH and panics if stdout contains unexpected
func (t *TestCluster) AssertCmdOutputDoesNotContain(m platform.Machine, cmd string, unexpected string) {
t.LogJournal(m, "+ "+cmd)
outputBuf := t.MustSSH(m, cmd)
output := string(outputBuf)
if strings.Contains(output, unexpected) {
t.Fatalf("cmd %s unexpectedly contained %s", cmd, unexpected)
}
}
Comment on lines +212 to +220

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve debuggability when a test assertion fails, it is highly recommended to include the actual command output in the failure message. Additionally, using %q instead of %s for the command and unexpected string arguments is a Go best practice to clearly demarcate them (especially if they contain spaces or special characters).

func (t *TestCluster) AssertCmdOutputDoesNotContain(m platform.Machine, cmd string, unexpected string) {
	t.LogJournal(m, "+ "+cmd)
	outputBuf := t.MustSSH(m, cmd)
	output := string(outputBuf)
	if strings.Contains(output, unexpected) {
		t.Fatalf("cmd %q unexpectedly contained %q; output:\n%s", cmd, unexpected, output)
	}
}


// AssertCmdOutputContains runs cmd via SSH and panics if stdout does not contain expected
func (t *TestCluster) AssertCmdOutputMatches(m platform.Machine, cmd string, expected *regexp.Regexp) {
t.LogJournal(m, "+ "+cmd)
Expand Down
7 changes: 7 additions & 0 deletions mantle/kola/tests/fips/fips.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,11 @@ func fipsEnableTest(c cluster.TestCluster) {
m := c.Machines()[0]
c.AssertCmdOutputContains(m, `cat /proc/sys/crypto/fips_enabled`, "1")
c.AssertCmdOutputContains(m, `update-crypto-policies --show`, "FIPS")
// There should be no mounts over crypto-policies.
//
// Bind mounts are generated over /etc/crypto-policies/back-ends
// when FIPS is not setup correctly, and the FIPS dracut module
// fixes it.
// See: https://github.com/coreos/rhel-coreos-config/pull/259
c.AssertCmdOutputDoesNotContain(m, `cat /proc/self/mountinfo`, "crypto-policies")
}