Configuration: 1) Add scheme syntax support to Preset Meta; 2) Some wrong defaults has now been fixed

This commit is contained in:
NI
2020-08-13 22:37:53 +08:00
parent 1c018ce560
commit d86c92867c
7 changed files with 271 additions and 48 deletions

View 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
}
}