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"
"testing"
"time"
"path/filepath"
)
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) {
r := realize{}
// add all flags, test with expected
@ -63,13 +51,13 @@ func TestRealize_Add(t *testing.T) {
set.Bool("run", false, "")
set.Bool("build", false, "")
set.Bool("generate", false, "")
set.String("path", "", "")
set.String("path", wdir(), "")
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)
expected := Project{
Name: "test_path",
Path: "test_path",
Name: filepath.Base(wdir()),
Path: wdir(),
Cmds: Cmds{
Fmt: Cmd{
Status: true,
@ -93,7 +81,7 @@ func TestRealize_Add(t *testing.T) {
},
Watcher: Watch{
Paths: []string{"/"},
Ignore: []string{"vendor"},
Ignore: []string{".git",".realize","vendor"},
Exts: []string{"go"},
},
}

View File

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

View File

@ -5,7 +5,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
@ -100,18 +99,6 @@ func TestSettings_Record(t *testing.T) {
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) {
s := Settings{}
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{}
name := random(8)
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)
}
s.fatal(nil,"test")
}

View File

@ -53,10 +53,13 @@ func TestInArray(t *testing.T) {
}
}
func TestGetEnvPath(t *testing.T) {
expected := filepath.SplitList(os.Getenv("GOPATH"))[0]
result := getEnvPath("GOPATH")
if expected != result {
t.Fatal("Expected", expected, "instead", result)
func TestWdir(t *testing.T) {
expected, err := os.Getwd()
if err != nil {
t.Error(err)
}
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"},
Exts: []string{"go"},
},
base: "/go/project",
Path: "/go/project",
watcher: &fileWatcherMock{},
init: true,
}