Add pembody, mwc tests.

This commit is contained in:
Kyle 2015-09-22 10:39:27 -07:00
parent 3fd30fef69
commit 57a33bcbcc
2 changed files with 55 additions and 0 deletions

28
cmd/pembody/pembody.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"encoding/pem"
"flag"
"fmt"
"io/ioutil"
"github.com/kisom/goutils/lib"
)
func main() {
flag.Parse()
if flag.NArg() != 1 {
lib.Errx(lib.ExitFailure, "a single filename is required")
}
in, err := ioutil.ReadFile(flag.Arg(0))
if err != nil {
lib.Err(lib.ExitFailure, err, "couldn't read file")
}
p, _ := pem.Decode(in)
if p == nil {
lib.Errx(lib.ExitFailure, "%s isn't a PEM-encoded file", flag.Arg(0))
}
fmt.Printf("%s", p.Bytes)
}

27
mwc/mwc_test.go Normal file
View File

@ -0,0 +1,27 @@
package mwc
import (
"bytes"
"testing"
"github.com/kisom/testio"
)
func TestMWC(t *testing.T) {
buf1 := testio.NewBufCloser(nil)
buf2 := testio.NewBufCloser(nil)
mwc := MultiWriteCloser(buf1, buf2)
if _, err := mwc.Write([]byte("hello, world")); err != nil {
t.Fatalf("%v", err)
}
if !bytes.Equal(buf1.Bytes(), buf2.Bytes()) {
t.Fatal("write failed")
}
if !bytes.Equal(buf1.Bytes(), []byte("hello, world")) {
t.Fatal("writing failed")
}
}