prefix, write tests

This commit is contained in:
asoseil 2017-11-22 15:06:10 +01:00
parent cf7b9bd0cc
commit c286bd230d
2 changed files with 34 additions and 16 deletions

View File

@ -1,15 +1,15 @@
package realize package realize
import ( import (
"log"
"os"
"path/filepath"
"strings"
"time"
"os/signal"
"syscall"
"fmt" "fmt"
"go/build" "go/build"
"log"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
) )
const ( const (
@ -77,5 +77,8 @@ func (r *Realize) Prefix(input string) string {
// Rewrite the layout of the log timestamp // Rewrite the layout of the log timestamp
func (w LogWriter) Write(bytes []byte) (int, error) { 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
} }

View File

@ -4,16 +4,11 @@ import (
"os" "os"
"testing" "testing"
"time" "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) { func TestRealize_Stop(t *testing.T) {
r := Realize{} r := Realize{}
r.exit = make(chan os.Signal, 2) r.exit = make(chan os.Signal, 2)
@ -36,3 +31,23 @@ func TestRealize_Start(t *testing.T) {
}() }()
r.Start() 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)
}
}