forked from TrueCloudLab/restic
Update dependenciess
Exclude minio-go for now (pin to 3.x.y).
This commit is contained in:
parent
9d0f13c4c0
commit
946c8399e2
2985 changed files with 1008107 additions and 118934 deletions
314
vendor/github.com/go-ini/ini/section_test.go
generated
vendored
314
vendor/github.com/go-ini/ini/section_test.go
generated
vendored
|
@ -12,64 +12,302 @@
|
|||
// License for the specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package ini
|
||||
package ini_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
func Test_Section(t *testing.T) {
|
||||
Convey("Test CRD sections", t, func() {
|
||||
cfg, err := Load([]byte(_CONF_DATA), "testdata/conf.ini")
|
||||
func TestSection_SetBody(t *testing.T) {
|
||||
Convey("Set body of raw section", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
sec, err := f.NewRawSection("comments", `1111111111111111111000000000000000001110000
|
||||
111111111111111111100000000000111000000000`)
|
||||
So(err, ShouldBeNil)
|
||||
So(cfg, ShouldNotBeNil)
|
||||
So(sec, ShouldNotBeNil)
|
||||
So(sec.Body(), ShouldEqual, `1111111111111111111000000000000000001110000
|
||||
111111111111111111100000000000111000000000`)
|
||||
|
||||
Convey("Get section strings", func() {
|
||||
So(strings.Join(cfg.SectionStrings(), ","), ShouldEqual, "DEFAULT,author,package,package.sub,features,types,array,note,comments,string escapes,advance")
|
||||
})
|
||||
sec.SetBody("1111111111111111111000000000000000001110000")
|
||||
So(sec.Body(), ShouldEqual, `1111111111111111111000000000000000001110000`)
|
||||
|
||||
Convey("Delete a section", func() {
|
||||
cfg.DeleteSection("")
|
||||
So(cfg.SectionStrings()[0], ShouldNotEqual, DEFAULT_SECTION)
|
||||
})
|
||||
|
||||
Convey("Create new sections", func() {
|
||||
cfg.NewSections("test", "test2")
|
||||
_, err := cfg.GetSection("test")
|
||||
So(err, ShouldBeNil)
|
||||
_, err = cfg.GetSection("test2")
|
||||
Convey("Set for non-raw section", func() {
|
||||
sec, err := f.NewSection("author")
|
||||
So(err, ShouldBeNil)
|
||||
So(sec, ShouldNotBeNil)
|
||||
So(sec.Body(), ShouldBeEmpty)
|
||||
|
||||
sec.SetBody("1111111111111111111000000000000000001110000")
|
||||
So(sec.Body(), ShouldBeEmpty)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func Test_SectionRaw(t *testing.T) {
|
||||
Convey("Test section raw string", t, func() {
|
||||
cfg, err := LoadSources(
|
||||
LoadOptions{
|
||||
Insensitive: true,
|
||||
UnparseableSections: []string{"core_lesson", "comments"},
|
||||
},
|
||||
"testdata/aicc.ini")
|
||||
func TestSection_NewKey(t *testing.T) {
|
||||
Convey("Create a new key", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(cfg, ShouldNotBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
So(k.Name(), ShouldEqual, "NAME")
|
||||
So(k.Value(), ShouldEqual, "ini")
|
||||
|
||||
Convey("Get section strings", func() {
|
||||
So(strings.Join(cfg.SectionStrings(), ","), ShouldEqual, "DEFAULT,core,core_lesson,comments")
|
||||
})
|
||||
|
||||
Convey("Validate non-raw section", func() {
|
||||
val, err := cfg.Section("core").GetKey("lesson_status")
|
||||
Convey("With duplicated name", func() {
|
||||
k, err := f.Section("").NewKey("NAME", "ini.v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(val.String(), ShouldEqual, "C")
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
// Overwrite previous existed key
|
||||
So(k.Value(), ShouldEqual, "ini.v1")
|
||||
})
|
||||
|
||||
Convey("Validate raw section", func() {
|
||||
So(cfg.Section("core_lesson").Body(), ShouldEqual, `my lesson state data – 1111111111111111111000000000000000001110000
|
||||
111111111111111111100000000000111000000000 – end my lesson state data`)
|
||||
Convey("With empty string", func() {
|
||||
_, err := f.Section("").NewKey("", "")
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Create keys with same name and allow shadow", t, func() {
|
||||
f, err := ini.ShadowLoad([]byte(""))
|
||||
So(err, ShouldBeNil)
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("").NewKey("NAME", "ini.v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
So(k.ValueWithShadows(), ShouldResemble, []string{"ini", "ini.v1"})
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_NewBooleanKey(t *testing.T) {
|
||||
Convey("Create a new boolean key", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewBooleanKey("start-ssh-server")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
So(k.Name(), ShouldEqual, "start-ssh-server")
|
||||
So(k.Value(), ShouldEqual, "true")
|
||||
|
||||
Convey("With empty string", func() {
|
||||
_, err := f.Section("").NewBooleanKey("")
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_GetKey(t *testing.T) {
|
||||
Convey("Get a key", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
k, err = f.Section("").GetKey("NAME")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
So(k.Name(), ShouldEqual, "NAME")
|
||||
So(k.Value(), ShouldEqual, "ini")
|
||||
|
||||
Convey("Key not exists", func() {
|
||||
_, err := f.Section("").GetKey("404")
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("Key exists in parent section", func() {
|
||||
k, err := f.Section("parent").NewKey("AGE", "18")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
k, err = f.Section("parent.child.son").GetKey("AGE")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
So(k.Value(), ShouldEqual, "18")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_HasKey(t *testing.T) {
|
||||
Convey("Check if a key exists", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
So(f.Section("").HasKey("NAME"), ShouldBeTrue)
|
||||
So(f.Section("").Haskey("NAME"), ShouldBeTrue)
|
||||
So(f.Section("").HasKey("404"), ShouldBeFalse)
|
||||
So(f.Section("").Haskey("404"), ShouldBeFalse)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_HasValue(t *testing.T) {
|
||||
Convey("Check if contains a value in any key", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
So(f.Section("").HasValue("ini"), ShouldBeTrue)
|
||||
So(f.Section("").HasValue("404"), ShouldBeFalse)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_Key(t *testing.T) {
|
||||
Convey("Get a key", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
k = f.Section("").Key("NAME")
|
||||
So(k, ShouldNotBeNil)
|
||||
So(k.Name(), ShouldEqual, "NAME")
|
||||
So(k.Value(), ShouldEqual, "ini")
|
||||
|
||||
Convey("Key not exists", func() {
|
||||
k := f.Section("").Key("404")
|
||||
So(k, ShouldNotBeNil)
|
||||
So(k.Name(), ShouldEqual, "404")
|
||||
})
|
||||
|
||||
Convey("Key exists in parent section", func() {
|
||||
k, err := f.Section("parent").NewKey("AGE", "18")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
k = f.Section("parent.child.son").Key("AGE")
|
||||
So(k, ShouldNotBeNil)
|
||||
So(k.Value(), ShouldEqual, "18")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_Keys(t *testing.T) {
|
||||
Convey("Get all keys in a section", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("").NewKey("VERSION", "v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("").NewKey("IMPORT_PATH", "gopkg.in/ini.v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
keys := f.Section("").Keys()
|
||||
names := []string{"NAME", "VERSION", "IMPORT_PATH"}
|
||||
So(len(keys), ShouldEqual, len(names))
|
||||
for i, name := range names {
|
||||
So(keys[i].Name(), ShouldEqual, name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_ParentKeys(t *testing.T) {
|
||||
Convey("Get all keys of parent sections", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("package").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("package").NewKey("VERSION", "v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("package").NewKey("IMPORT_PATH", "gopkg.in/ini.v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
keys := f.Section("package.sub.sub2").ParentKeys()
|
||||
names := []string{"NAME", "VERSION", "IMPORT_PATH"}
|
||||
So(len(keys), ShouldEqual, len(names))
|
||||
for i, name := range names {
|
||||
So(keys[i].Name(), ShouldEqual, name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_KeyStrings(t *testing.T) {
|
||||
Convey("Get all key names in a section", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("").NewKey("VERSION", "v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("").NewKey("IMPORT_PATH", "gopkg.in/ini.v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
So(f.Section("").KeyStrings(), ShouldResemble, []string{"NAME", "VERSION", "IMPORT_PATH"})
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_KeyHash(t *testing.T) {
|
||||
Convey("Get clone of key hash", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("").NewKey("VERSION", "v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
k, err = f.Section("").NewKey("IMPORT_PATH", "gopkg.in/ini.v1")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
hash := f.Section("").KeysHash()
|
||||
relation := map[string]string{
|
||||
"NAME": "ini",
|
||||
"VERSION": "v1",
|
||||
"IMPORT_PATH": "gopkg.in/ini.v1",
|
||||
}
|
||||
for k, v := range hash {
|
||||
So(v, ShouldEqual, relation[k])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSection_DeleteKey(t *testing.T) {
|
||||
Convey("Delete a key", t, func() {
|
||||
f := ini.Empty()
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
k, err := f.Section("").NewKey("NAME", "ini")
|
||||
So(err, ShouldBeNil)
|
||||
So(k, ShouldNotBeNil)
|
||||
|
||||
So(f.Section("").HasKey("NAME"), ShouldBeTrue)
|
||||
f.Section("").DeleteKey("NAME")
|
||||
So(f.Section("").HasKey("NAME"), ShouldBeFalse)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue