57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"github.com/tockins/realize/settings"
|
|
"github.com/tockins/realize/style"
|
|
"github.com/tockins/realize/watcher"
|
|
"gopkg.in/urfave/cli.v2"
|
|
"testing"
|
|
)
|
|
|
|
func TestPrefix(t *testing.T) {
|
|
input := settings.Rand(10)
|
|
value := fmt.Sprint(style.Yellow.Bold("[")+"REALIZE"+style.Yellow.Bold("]"), input)
|
|
result := prefix(input)
|
|
if result == "" {
|
|
t.Fatal("Expected a string")
|
|
}
|
|
if result != value {
|
|
t.Fatal("Expected", value, "Instead", result)
|
|
}
|
|
}
|
|
|
|
func TestBefore(t *testing.T) {
|
|
context := cli.Context{}
|
|
if err := before(&context); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestPolling(t *testing.T) {
|
|
settings := settings.Legacy{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.Bool("legacy", true, "")
|
|
params := cli.NewContext(nil, set, nil)
|
|
polling(params, &settings)
|
|
if settings.Interval == 0 {
|
|
t.Fatal("Expected interval", settings.Interval, "Instead", 0)
|
|
}
|
|
}
|
|
|
|
func TestInsert(t *testing.T) {
|
|
b := watcher.Blueprint{}
|
|
b.Settings = &settings.Settings{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.String("name", settings.Rand(5), "")
|
|
set.String("path", settings.Rand(5), "")
|
|
params := cli.NewContext(nil, set, nil)
|
|
if err := insert(params, &b); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(b.Projects) == 0 {
|
|
t.Error("Expected one project")
|
|
}
|
|
}
|