realize/settings/utils_test.go

57 lines
1.1 KiB
Go
Raw Normal View History

2017-08-12 17:48:06 +00:00
package settings
import (
"errors"
"os"
"path/filepath"
"strings"
"testing"
)
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("")
input = nil
if err := s.Validate(input); err != nil {
t.Error("Expected", input, "instead", err)
}
}
func TestSettings_Name(t *testing.T) {
s := Settings{}
2017-08-27 11:45:46 +00:00
name := Rand(8)
path := Rand(5)
2017-08-12 17:48:06 +00:00
dir, err := os.Getwd()
if err != nil {
2017-08-12 22:29:46 +00:00
t.Fatal(err)
2017-08-12 17:48:06 +00:00
}
result := s.Name(name, path)
if result != dir && result != filepath.Base(path) {
2017-08-12 22:29:46 +00:00
t.Fatal("Expected", dir, "or", filepath.Base(path), "instead", result)
2017-08-12 17:48:06 +00:00
}
}
func TestSettings_Path(t *testing.T) {
s := Settings{}
2017-08-27 11:45:46 +00:00
path := Rand(5)
2017-08-12 17:48:06 +00:00
expected := strings.Replace(filepath.Clean(path), "\\", "/", -1)
result := s.Path(path)
if result != expected {
2017-08-12 22:29:46 +00:00
t.Fatal("Expected", expected, "instead", result)
2017-08-12 17:48:06 +00:00
}
}