From c286bd230dc78420beff28594742771208e51942 Mon Sep 17 00:00:00 2001 From: asoseil Date: Wed, 22 Nov 2017 15:06:10 +0100 Subject: [PATCH] prefix, write tests --- realize/cli.go | 19 +++++++++++-------- realize/cli_test.go | 31 +++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/realize/cli.go b/realize/cli.go index 5bc4c9d..1ecd51f 100644 --- a/realize/cli.go +++ b/realize/cli.go @@ -1,15 +1,15 @@ package realize import ( - "log" - "os" - "path/filepath" - "strings" - "time" - "os/signal" - "syscall" "fmt" "go/build" + "log" + "os" + "os/signal" + "path/filepath" + "strings" + "syscall" + "time" ) const ( @@ -77,5 +77,8 @@ func (r *Realize) Prefix(input string) string { // Rewrite the layout of the log timestamp func (w LogWriter) Write(bytes []byte) (int, error) { - return fmt.Fprint(Output, Yellow.Regular("["), time.Now().Format("15:04:05"), Yellow.Regular("]"), string(bytes)) + if len(bytes) > 0 { + return fmt.Fprint(Output, Yellow.Regular("["), time.Now().Format("15:04:05"), Yellow.Regular("]"), string(bytes)) + } + return 0,nil } diff --git a/realize/cli_test.go b/realize/cli_test.go index 022aa30..4b700ce 100644 --- a/realize/cli_test.go +++ b/realize/cli_test.go @@ -4,16 +4,11 @@ import ( "os" "testing" "time" + "strings" + "log" + "bytes" ) -type mockRealize struct { - Settings Settings `yaml:"settings" json:"settings"` - Server Server `yaml:"server" json:"server"` - Schema `yaml:",inline"` - sync chan string - exit chan os.Signal -} - func TestRealize_Stop(t *testing.T) { r := Realize{} r.exit = make(chan os.Signal, 2) @@ -36,3 +31,23 @@ func TestRealize_Start(t *testing.T) { }() r.Start() } + +func TestRealize_Prefix(t *testing.T) { + r := Realize{} + input := "test" + result := r.Prefix(input) + if len(result) <= 0 && !strings.Contains(result,input){ + t.Error("Unexpected error") + } +} + +func TestSettings_Read(t *testing.T) { + var buf bytes.Buffer + log.SetOutput(&buf) + w := LogWriter{} + input := "" + int, err := w.Write([]byte(input)) + if err != nil || int > 0{ + t.Error("Unexpected error", err, "string lenght should be 0 instead",int) + } +} \ No newline at end of file