mirror of
https://github.com/clearlinux/mixer-tools.git
synced 2026-09-05 21:21:44 +00:00
Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
74 lines
1.3 KiB
Go
74 lines
1.3 KiB
Go
package swupd
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestExternalWriter(t *testing.T) {
|
|
tr, err := exec.LookPath("tr")
|
|
if err != nil {
|
|
if err == exec.ErrNotFound {
|
|
t.Skip("couldn't find tr program used for test")
|
|
}
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var output bytes.Buffer
|
|
w, err := NewExternalWriter(&output, tr, "e", "a")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
input := "Hello, world!"
|
|
expected := strings.Replace(input, "e", "a", -1)
|
|
|
|
_, err = w.Write([]byte(input))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = w.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if output.String() != expected {
|
|
t.Fatalf("got %q, but want %q", output.String(), expected)
|
|
}
|
|
}
|
|
|
|
func TestExternalReader(t *testing.T) {
|
|
tr, err := exec.LookPath("tr")
|
|
if err != nil {
|
|
if err == exec.ErrNotFound {
|
|
t.Skip("couldn't find tr program used for test")
|
|
}
|
|
t.Fatal(err)
|
|
}
|
|
|
|
input := "Hello, world!"
|
|
expected := strings.Replace(input, "e", "a", -1)
|
|
|
|
r, err := NewExternalReader(strings.NewReader(input), tr, "e", "a")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
output, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if string(output) != expected {
|
|
t.Fatalf("got %q, but want %q", string(output), expected)
|
|
}
|
|
|
|
err = r.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|