realize/settings/settings_test.go

52 lines
1.0 KiB
Go
Raw Normal View History

2017-08-12 17:48:06 +00:00
package settings
import (
"io/ioutil"
"path/filepath"
"testing"
)
func TestSettings_Read(t *testing.T) {
s := Settings{}
var a interface{}
s.Resources.Config = "settings_b"
if err := s.Read(a); err == nil {
2017-08-12 22:29:46 +00:00
t.Fatal("Error unexpected", err)
2017-08-12 17:48:06 +00:00
}
s.Resources.Config = "settings_test.yaml"
d, err := ioutil.TempFile("", "settings_test.yaml")
if err != nil {
t.Fatal(err)
}
s.Resources.Config = d.Name()
if err := s.Read(a); err != nil {
2017-08-12 22:29:46 +00:00
t.Fatal("Error unexpected", err)
2017-08-12 17:48:06 +00:00
}
}
func TestSettings_Remove(t *testing.T) {
s := Settings{}
if err := s.Remove("abcd"); err == nil {
2017-08-12 22:29:46 +00:00
t.Fatal("Error unexpected, dir dosn't exist", err)
2017-08-12 17:48:06 +00:00
}
d, err := ioutil.TempDir("", "settings_test")
if err != nil {
2017-08-12 22:29:46 +00:00
t.Fatal(err)
2017-08-12 17:48:06 +00:00
}
if err := s.Remove(d); err != nil {
2017-08-12 22:29:46 +00:00
t.Fatal("Error unexpected, dir exist", err)
2017-08-12 17:48:06 +00:00
}
}
func TestSettings_Record(t *testing.T) {
s := Settings{}
s.Resources.Config = "settings_test.yaml"
var a interface{}
if err := s.Record(a); err != nil {
2017-08-12 22:29:46 +00:00
t.Fatal(err)
2017-08-12 17:48:06 +00:00
}
2017-08-28 08:49:38 +00:00
s.Remove(filepath.Join(directory, s.Resources.Config))
2017-08-12 17:48:06 +00:00
}