From 57a33bcbcc23430aa7fc2b81e4441034fc8afa86 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 22 Sep 2015 10:39:27 -0700 Subject: [PATCH] Add pembody, mwc tests. --- cmd/pembody/pembody.go | 28 ++++++++++++++++++++++++++++ mwc/mwc_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 cmd/pembody/pembody.go create mode 100644 mwc/mwc_test.go diff --git a/cmd/pembody/pembody.go b/cmd/pembody/pembody.go new file mode 100644 index 0000000..e8ed7e4 --- /dev/null +++ b/cmd/pembody/pembody.go @@ -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) +} diff --git a/mwc/mwc_test.go b/mwc/mwc_test.go new file mode 100644 index 0000000..c9af36c --- /dev/null +++ b/mwc/mwc_test.go @@ -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") + } +}