2015-06-12 20:24:03 -04:00
|
|
|
package file
|
|
|
|
|
|
|
|
import (
|
2015-06-12 21:18:38 -04:00
|
|
|
"strings"
|
2015-06-12 20:24:03 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testConfig() map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
2015-06-12 21:18:38 -04:00
|
|
|
"source": "src.txt",
|
|
|
|
"target": "dst.txt",
|
|
|
|
"content": "Hello, world!",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContentSourceConflict(t *testing.T) {
|
|
|
|
raw := testConfig()
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
var c Config
|
|
|
|
_, errs := c.Prepare(raw)
|
2015-06-12 21:18:38 -04:00
|
|
|
if !strings.Contains(errs.Error(), ErrContentSourceConflict.Error()) {
|
|
|
|
t.Errorf("Expected config error: %s", ErrContentSourceConflict.Error())
|
2015-06-12 20:24:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNoFilename(t *testing.T) {
|
|
|
|
raw := testConfig()
|
|
|
|
|
|
|
|
delete(raw, "filename")
|
2019-12-17 05:25:56 -05:00
|
|
|
var c Config
|
|
|
|
_, errs := c.Prepare(raw)
|
2015-06-12 20:24:03 -04:00
|
|
|
if errs == nil {
|
2015-06-12 21:18:38 -04:00
|
|
|
t.Errorf("Expected config error: %s", ErrTargetRequired.Error())
|
2015-06-12 20:24:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNoContent(t *testing.T) {
|
|
|
|
raw := testConfig()
|
|
|
|
|
2015-06-12 21:18:38 -04:00
|
|
|
delete(raw, "content")
|
|
|
|
delete(raw, "source")
|
2019-12-17 05:25:56 -05:00
|
|
|
var c Config
|
|
|
|
warns, _ := c.Prepare(raw)
|
2015-06-16 14:31:53 -04:00
|
|
|
|
2015-06-12 20:24:03 -04:00
|
|
|
if len(warns) == 0 {
|
2015-06-12 21:18:38 -04:00
|
|
|
t.Error("Expected config warning without any content")
|
2015-06-12 20:24:03 -04:00
|
|
|
}
|
|
|
|
}
|