func assertCmd()

in cmd/util/testutils/cmd.go [76:102]


func assertCmd(t *testing.T, args Args, want Assertion, execErr error, track bool) {
	if execErr != nil && !assert.EqualError(t, execErr, want.Err) {
		t.Error(execErr)
	}

	if buf, ok := args.Cmd.OutOrStdout().(*bytes.Buffer); ok {
		var got = buf.String()

		// When the output contains the `--track` flag, removes the non-
		// assertable duration time.
		if track {
			got = regexp.MustCompile(durationExpr).ReplaceAllString(
				got, durationRepl,
			)
		}

		if got != want.Stdout {
			t.Errorf(`"Got stdout "%s" != want "%s"`, got, want.Stdout)
		}
	}

	if buf, ok := args.Cmd.ErrOrStderr().(*bytes.Buffer); ok {
		if got := buf.String(); got != want.Stderr {
			t.Errorf(`"Got stderr "%s" != want "%s"`, got, want.Stderr)
		}
	}
}