tests updated

This commit is contained in:
asoseil 2017-10-22 23:54:02 +02:00
parent bfff06d38a
commit 968726968f
5 changed files with 19 additions and 63 deletions

View File

@ -8,6 +8,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"time" "time"
"path/filepath"
) )
type loggerT struct{} type loggerT struct{}
@ -39,19 +40,6 @@ func TestRealize_Clean(t *testing.T) {
} }
func TestRealize_Check(t *testing.T) {
r := realize{}
err := r.check()
if err == nil {
t.Error("There is no project, error expected")
}
r.Schema = append(r.Schema, Project{Name: "test0"})
err = r.check()
if err != nil {
t.Error("There is a project, error unexpected", err)
}
}
func TestRealize_Add(t *testing.T) { func TestRealize_Add(t *testing.T) {
r := realize{} r := realize{}
// add all flags, test with expected // add all flags, test with expected
@ -63,13 +51,13 @@ func TestRealize_Add(t *testing.T) {
set.Bool("run", false, "") set.Bool("run", false, "")
set.Bool("build", false, "") set.Bool("build", false, "")
set.Bool("generate", false, "") set.Bool("generate", false, "")
set.String("path", "", "") set.String("path", wdir(), "")
c := cli.NewContext(nil, set, nil) c := cli.NewContext(nil, set, nil)
set.Parse([]string{"--path=test_path", "--fmt", "--install", "--run", "--build", "--generate", "--test", "--vet"}) set.Parse([]string{"--fmt", "--install", "--run", "--build", "--generate", "--test", "--vet"})
r.add(c) r.add(c)
expected := Project{ expected := Project{
Name: "test_path", Name: filepath.Base(wdir()),
Path: "test_path", Path: wdir(),
Cmds: Cmds{ Cmds: Cmds{
Fmt: Cmd{ Fmt: Cmd{
Status: true, Status: true,
@ -93,7 +81,7 @@ func TestRealize_Add(t *testing.T) {
}, },
Watcher: Watch{ Watcher: Watch{
Paths: []string{"/"}, Paths: []string{"/"},
Ignore: []string{"vendor"}, Ignore: []string{".git",".realize","vendor"},
Exts: []string{"go"}, Exts: []string{"go"},
}, },
} }

View File

@ -9,7 +9,7 @@ import (
func TestPrefix(t *testing.T) { func TestPrefix(t *testing.T) {
input := random(10) input := random(10)
value := fmt.Sprint(yellow.bold("[")+"REALIZE"+yellow.bold("]"), input) value := fmt.Sprint(yellow.bold("["), "REALIZE", yellow.bold("]"), " : ", input)
result := prefix(input) result := prefix(input)
if result == "" { if result == "" {
t.Fatal("Expected a string") t.Fatal("Expected a string")
@ -28,7 +28,6 @@ func TestBefore(t *testing.T) {
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
r := new() r := new()
t.Log(reflect.TypeOf(r).String())
if reflect.TypeOf(r).String() != "main.realize" { if reflect.TypeOf(r).String() != "main.realize" {
t.Error("Expected a realize struct") t.Error("Expected a realize struct")
} }

View File

@ -5,7 +5,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
) )
@ -100,18 +99,6 @@ func TestSettings_Record(t *testing.T) {
s.del(filepath.Join(directory, s.file)) s.del(filepath.Join(directory, s.file))
} }
func TestSettings_Wdir(t *testing.T) {
s := Settings{}
expected, err := os.Getwd()
if err != nil {
t.Error(err)
}
result := s.wdir()
if result != filepath.Base(expected) {
t.Error("Expected", filepath.Base(expected), "instead", result)
}
}
func TestSettings_Validate(t *testing.T) { func TestSettings_Validate(t *testing.T) {
s := Settings{} s := Settings{}
input := errors.New("") input := errors.New("")
@ -121,28 +108,7 @@ func TestSettings_Validate(t *testing.T) {
} }
} }
func TestSettings_Name(t *testing.T) { func TestSettings_Fatal(t *testing.T){
s := Settings{} s := Settings{}
name := random(8) s.fatal(nil,"test")
path := random(5) }
dir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
result := s.name(name, path)
if result != dir && result != filepath.Base(path) {
t.Fatal("Expected", dir, "or", filepath.Base(path), "instead", result)
}
}
func TestSettings_Path(t *testing.T) {
s := Settings{}
path := random(5)
expected := strings.Replace(filepath.Clean(path), "\\", "/", -1)
result := s.path(path)
if result != expected {
t.Fatal("Expected", expected, "instead", result)
}
}

View File

@ -53,10 +53,13 @@ func TestInArray(t *testing.T) {
} }
} }
func TestGetEnvPath(t *testing.T) { func TestWdir(t *testing.T) {
expected := filepath.SplitList(os.Getenv("GOPATH"))[0] expected, err := os.Getwd()
result := getEnvPath("GOPATH") if err != nil {
if expected != result { t.Error(err)
t.Fatal("Expected", expected, "instead", result) }
result := wdir()
if result != expected {
t.Error("Expected", filepath.Base(expected), "instead", result)
} }
} }

View File

@ -29,7 +29,7 @@ func TestWalk(t *testing.T) {
Ignore: []string{"vendor"}, Ignore: []string{"vendor"},
Exts: []string{"go"}, Exts: []string{"go"},
}, },
base: "/go/project", Path: "/go/project",
watcher: &fileWatcherMock{}, watcher: &fileWatcherMock{},
init: true, init: true,
} }