prefix, write tests
This commit is contained in:
parent
cf7b9bd0cc
commit
c286bd230d
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue