realize/realize/cli_test.go

62 lines
1.2 KiB
Go
Raw Normal View History

2017-11-20 15:36:48 +00:00
package realize
import (
2017-11-22 14:31:34 +00:00
"bytes"
"log"
2017-11-20 15:36:48 +00:00
"os"
2017-11-22 14:31:34 +00:00
"strings"
2017-11-22 13:05:16 +00:00
"testing"
"time"
2017-11-20 15:36:48 +00:00
)
func TestRealize_Stop(t *testing.T) {
2017-11-22 13:05:16 +00:00
r := Realize{}
2017-12-04 22:39:27 +00:00
r.Projects = append(r.Schema.Projects, Project{exit: make(chan os.Signal, 1)})
2017-11-22 13:05:16 +00:00
r.Stop()
2017-12-04 22:39:27 +00:00
_, ok := <-r.Projects[0].exit
2017-11-20 16:01:56 +00:00
if ok != false {
2017-11-20 15:36:48 +00:00
t.Error("Unexpected error", "channel should be closed")
}
}
2017-11-22 13:05:16 +00:00
func TestRealize_Start(t *testing.T) {
r := Realize{}
2017-12-03 14:44:38 +00:00
err := r.Start()
2017-12-04 14:53:59 +00:00
if err == nil {
2017-12-03 14:44:38 +00:00
t.Error("Error expected")
}
2017-12-04 22:39:27 +00:00
r.Projects = append(r.Projects, Project{Name: "test", exit: make(chan os.Signal, 1)})
2017-11-22 14:31:34 +00:00
go func() {
2017-11-22 13:05:16 +00:00
time.Sleep(100)
2017-12-04 22:39:27 +00:00
close(r.Projects[0].exit)
_, ok := <-r.Projects[0].exit
2017-11-22 13:05:16 +00:00
if ok != false {
t.Error("Unexpected error", "channel should be closed")
}
}()
2017-12-03 14:44:38 +00:00
err = r.Start()
2017-12-04 14:53:59 +00:00
if err != nil {
2017-12-03 14:44:38 +00:00
t.Error("Unexpected error", err)
}
2017-11-22 13:05:16 +00:00
}
2017-11-22 14:06:10 +00:00
func TestRealize_Prefix(t *testing.T) {
r := Realize{}
input := "test"
result := r.Prefix(input)
2017-11-22 14:31:34 +00:00
if len(result) <= 0 && !strings.Contains(result, input) {
2017-11-22 14:06:10 +00:00
t.Error("Unexpected error")
}
}
2017-12-03 18:42:46 +00:00
func TestLogWriter_Write(t *testing.T) {
2017-11-22 14:06:10 +00:00
var buf bytes.Buffer
log.SetOutput(&buf)
w := LogWriter{}
input := ""
int, err := w.Write([]byte(input))
2017-11-22 14:31:34 +00:00
if err != nil || int > 0 {
t.Error("Unexpected error", err, "string lenght should be 0 instead", int)
2017-11-22 14:06:10 +00:00
}
2017-11-22 14:31:34 +00:00
}