mirror of
https://github.com/clearlinux/mixer-tools.git
synced 2026-08-19 03:57:28 +00:00
f6dcd44f21
Implement the logging package for mixer. A common log file can be set for all the mixer commands in the builder.conf. E.g. `mixer config set Mixer.LOG <filepath>` The log file and level can also be set for individual mixer commands using the `--log` and `--log-level` flags respectively. The various log levels are: ERROR (1), WARNING (2), INFO (3), DEBUG (4) and VERBOSE (5). Default log level is 4. Fixes #666 Signed-off-by: Ashlesha Atrey ashlesha.atrey@intel.com
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/clearlinux/mixer-tools/log"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRunCommandOutputSuccess(t *testing.T) {
|
|
const msg = "Hello, world!"
|
|
const fail = "This is not working!"
|
|
// Prints both in stdout and stderr.
|
|
out, err := RunCommandOutput(log.Mixer, "bash", "-c", fmt.Sprintf("echo -n %q; echo -n %q >&2", msg, fail))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Output contains only stdout.
|
|
if out.String() != msg {
|
|
t.Fatalf("unexpected output %q instead of %q", out.String(), msg)
|
|
}
|
|
}
|
|
|
|
func TestRunCommandOutputFailure(t *testing.T) {
|
|
// Prints both in stdout and stderr. Calling false forces failure.
|
|
out, err := RunCommandOutput(log.Mixer, "bash", "-c", "export OK=OK; export FAIL=FAIL; echo -n $OK$OK; echo -n $FAIL$FAIL >&2; false")
|
|
if err == nil {
|
|
t.Fatal("unexpected success when running command")
|
|
}
|
|
// Error should contain both errcode and stderr. Note that the strings we are
|
|
// looking at are not part of the command, to avoid matching those. Output contains the stdout string.
|
|
if !strings.Contains(out.String(), "OKOK") {
|
|
t.Errorf("error doesn't contain the stdout of the program")
|
|
}
|
|
if !strings.Contains(err.Error(), "FAILFAIL") {
|
|
t.Errorf("error doesn't contain the stderr of the program")
|
|
}
|
|
if t.Failed() {
|
|
fmt.Println(err)
|
|
}
|
|
}
|