Configuration: 1) Add scheme syntax support to Preset Meta; 2) Some wrong defaults has now been fixed
This commit is contained in:
77
application/configuration/string_test.go
Normal file
77
application/configuration/string_test.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStringString(t *testing.T) {
|
||||
ss := String("aaaaaaaaaaaaa")
|
||||
|
||||
result, err := ss.Parse()
|
||||
|
||||
if err != nil {
|
||||
t.Error("Unable to parse:", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if result != "aaaaaaaaaaaaa" {
|
||||
t.Errorf(
|
||||
"Expecting the result to be %s, got %s instead",
|
||||
"aaaaaaaaaaaaa",
|
||||
result,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFile(t *testing.T) {
|
||||
const testFilename = "sshwifty.configuration.test.string.file.tmp"
|
||||
|
||||
filePath := os.TempDir() + string(os.PathSeparator) + testFilename
|
||||
|
||||
f, err := os.Create(filePath)
|
||||
|
||||
if err != nil {
|
||||
t.Error("Unable to create file:", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
defer os.Remove(filePath)
|
||||
|
||||
f.WriteString("TestAAAA")
|
||||
f.Close()
|
||||
|
||||
ss := String("file://" + filePath)
|
||||
|
||||
result, err := ss.Parse()
|
||||
|
||||
if err != nil {
|
||||
t.Error("Unable to parse:", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if result != "TestAAAA" {
|
||||
t.Errorf(
|
||||
"Expecting the result to be %s, got %s instead",
|
||||
"TestAAAA",
|
||||
result,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ss = String("file://" + filePath + ".notexist")
|
||||
|
||||
result, err = ss.Parse()
|
||||
|
||||
if err == nil {
|
||||
t.Error("Parsing an non-existing file should result an error")
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user