key_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. // Copyright 2014 Unknwon
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. // License for the specific language governing permissions and limitations
  13. // under the License.
  14. package ini_test
  15. import (
  16. "bytes"
  17. "fmt"
  18. "strings"
  19. "testing"
  20. "time"
  21. . "github.com/smartystreets/goconvey/convey"
  22. "gopkg.in/ini.v1"
  23. )
  24. func TestKey_AddShadow(t *testing.T) {
  25. Convey("Add shadow to a key", t, func() {
  26. f, err := ini.ShadowLoad([]byte(`
  27. [notes]
  28. -: note1`))
  29. So(err, ShouldBeNil)
  30. So(f, ShouldNotBeNil)
  31. k, err := f.Section("").NewKey("NAME", "ini")
  32. So(err, ShouldBeNil)
  33. So(k, ShouldNotBeNil)
  34. So(k.AddShadow("ini.v1"), ShouldBeNil)
  35. So(k.ValueWithShadows(), ShouldResemble, []string{"ini", "ini.v1"})
  36. Convey("Add shadow to boolean key", func() {
  37. k, err := f.Section("").NewBooleanKey("published")
  38. So(err, ShouldBeNil)
  39. So(k, ShouldNotBeNil)
  40. So(k.AddShadow("beta"), ShouldNotBeNil)
  41. })
  42. Convey("Add shadow to auto-increment key", func() {
  43. So(f.Section("notes").Key("#1").AddShadow("beta"), ShouldNotBeNil)
  44. })
  45. })
  46. Convey("Shadow is not allowed", t, func() {
  47. f := ini.Empty()
  48. So(f, ShouldNotBeNil)
  49. k, err := f.Section("").NewKey("NAME", "ini")
  50. So(err, ShouldBeNil)
  51. So(k, ShouldNotBeNil)
  52. So(k.AddShadow("ini.v1"), ShouldNotBeNil)
  53. })
  54. }
  55. // Helpers for slice tests.
  56. func float64sEqual(values []float64, expected ...float64) {
  57. So(values, ShouldHaveLength, len(expected))
  58. for i, v := range expected {
  59. So(values[i], ShouldEqual, v)
  60. }
  61. }
  62. func intsEqual(values []int, expected ...int) {
  63. So(values, ShouldHaveLength, len(expected))
  64. for i, v := range expected {
  65. So(values[i], ShouldEqual, v)
  66. }
  67. }
  68. func int64sEqual(values []int64, expected ...int64) {
  69. So(values, ShouldHaveLength, len(expected))
  70. for i, v := range expected {
  71. So(values[i], ShouldEqual, v)
  72. }
  73. }
  74. func uintsEqual(values []uint, expected ...uint) {
  75. So(values, ShouldHaveLength, len(expected))
  76. for i, v := range expected {
  77. So(values[i], ShouldEqual, v)
  78. }
  79. }
  80. func uint64sEqual(values []uint64, expected ...uint64) {
  81. So(values, ShouldHaveLength, len(expected))
  82. for i, v := range expected {
  83. So(values[i], ShouldEqual, v)
  84. }
  85. }
  86. func timesEqual(values []time.Time, expected ...time.Time) {
  87. So(values, ShouldHaveLength, len(expected))
  88. for i, v := range expected {
  89. So(values[i].String(), ShouldEqual, v.String())
  90. }
  91. }
  92. func TestKey_Helpers(t *testing.T) {
  93. Convey("Getting and setting values", t, func() {
  94. f, err := ini.Load(fullConf)
  95. So(err, ShouldBeNil)
  96. So(f, ShouldNotBeNil)
  97. Convey("Get string representation", func() {
  98. sec := f.Section("")
  99. So(sec, ShouldNotBeNil)
  100. So(sec.Key("NAME").Value(), ShouldEqual, "ini")
  101. So(sec.Key("NAME").String(), ShouldEqual, "ini")
  102. So(sec.Key("NAME").Validate(func(in string) string {
  103. return in
  104. }), ShouldEqual, "ini")
  105. So(sec.Key("NAME").Comment, ShouldEqual, "; Package name")
  106. So(sec.Key("IMPORT_PATH").String(), ShouldEqual, "gopkg.in/ini.v1")
  107. Convey("With ValueMapper", func() {
  108. f.ValueMapper = func(in string) string {
  109. if in == "gopkg.in/%(NAME)s.%(VERSION)s" {
  110. return "github.com/go-ini/ini"
  111. }
  112. return in
  113. }
  114. So(sec.Key("IMPORT_PATH").String(), ShouldEqual, "github.com/go-ini/ini")
  115. })
  116. })
  117. Convey("Get values in non-default section", func() {
  118. sec := f.Section("author")
  119. So(sec, ShouldNotBeNil)
  120. So(sec.Key("NAME").String(), ShouldEqual, "Unknwon")
  121. So(sec.Key("GITHUB").String(), ShouldEqual, "https://github.com/Unknwon")
  122. sec = f.Section("package")
  123. So(sec, ShouldNotBeNil)
  124. So(sec.Key("CLONE_URL").String(), ShouldEqual, "https://gopkg.in/ini.v1")
  125. })
  126. Convey("Get auto-increment key names", func() {
  127. keys := f.Section("features").Keys()
  128. for i, k := range keys {
  129. So(k.Name(), ShouldEqual, fmt.Sprintf("#%d", i+1))
  130. }
  131. })
  132. Convey("Get parent-keys that are available to the child section", func() {
  133. parentKeys := f.Section("package.sub").ParentKeys()
  134. for _, k := range parentKeys {
  135. So(k.Name(), ShouldEqual, "CLONE_URL")
  136. }
  137. })
  138. Convey("Get overwrite value", func() {
  139. So(f.Section("author").Key("E-MAIL").String(), ShouldEqual, "u@gogs.io")
  140. })
  141. Convey("Get sections", func() {
  142. sections := f.Sections()
  143. for i, name := range []string{ini.DefaultSection, "author", "package", "package.sub", "features", "types", "array", "note", "comments", "string escapes", "advance"} {
  144. So(sections[i].Name(), ShouldEqual, name)
  145. }
  146. })
  147. Convey("Get parent section value", func() {
  148. So(f.Section("package.sub").Key("CLONE_URL").String(), ShouldEqual, "https://gopkg.in/ini.v1")
  149. So(f.Section("package.fake.sub").Key("CLONE_URL").String(), ShouldEqual, "https://gopkg.in/ini.v1")
  150. })
  151. Convey("Get multiple line value", func() {
  152. So(f.Section("author").Key("BIO").String(), ShouldEqual, "Gopher.\nCoding addict.\nGood man.\n")
  153. })
  154. Convey("Get values with type", func() {
  155. sec := f.Section("types")
  156. v1, err := sec.Key("BOOL").Bool()
  157. So(err, ShouldBeNil)
  158. So(v1, ShouldBeTrue)
  159. v1, err = sec.Key("BOOL_FALSE").Bool()
  160. So(err, ShouldBeNil)
  161. So(v1, ShouldBeFalse)
  162. v2, err := sec.Key("FLOAT64").Float64()
  163. So(err, ShouldBeNil)
  164. So(v2, ShouldEqual, 1.25)
  165. v3, err := sec.Key("INT").Int()
  166. So(err, ShouldBeNil)
  167. So(v3, ShouldEqual, 10)
  168. v4, err := sec.Key("INT").Int64()
  169. So(err, ShouldBeNil)
  170. So(v4, ShouldEqual, 10)
  171. v5, err := sec.Key("UINT").Uint()
  172. So(err, ShouldBeNil)
  173. So(v5, ShouldEqual, 3)
  174. v6, err := sec.Key("UINT").Uint64()
  175. So(err, ShouldBeNil)
  176. So(v6, ShouldEqual, 3)
  177. t, err := time.Parse(time.RFC3339, "2015-01-01T20:17:05Z")
  178. So(err, ShouldBeNil)
  179. v7, err := sec.Key("TIME").Time()
  180. So(err, ShouldBeNil)
  181. So(v7.String(), ShouldEqual, t.String())
  182. v8, err := sec.Key("HEX_NUMBER").Int()
  183. So(err, ShouldBeNil)
  184. So(v8, ShouldEqual, 0x3000)
  185. Convey("Must get values with type", func() {
  186. So(sec.Key("STRING").MustString("404"), ShouldEqual, "str")
  187. So(sec.Key("BOOL").MustBool(), ShouldBeTrue)
  188. So(sec.Key("FLOAT64").MustFloat64(), ShouldEqual, 1.25)
  189. So(sec.Key("INT").MustInt(), ShouldEqual, 10)
  190. So(sec.Key("INT").MustInt64(), ShouldEqual, 10)
  191. So(sec.Key("UINT").MustUint(), ShouldEqual, 3)
  192. So(sec.Key("UINT").MustUint64(), ShouldEqual, 3)
  193. So(sec.Key("TIME").MustTime().String(), ShouldEqual, t.String())
  194. So(sec.Key("HEX_NUMBER").MustInt(), ShouldEqual, 0x3000)
  195. dur, err := time.ParseDuration("2h45m")
  196. So(err, ShouldBeNil)
  197. So(sec.Key("DURATION").MustDuration().Seconds(), ShouldEqual, dur.Seconds())
  198. Convey("Must get values with default value", func() {
  199. So(sec.Key("STRING_404").MustString("404"), ShouldEqual, "404")
  200. So(sec.Key("BOOL_404").MustBool(true), ShouldBeTrue)
  201. So(sec.Key("FLOAT64_404").MustFloat64(2.5), ShouldEqual, 2.5)
  202. So(sec.Key("INT_404").MustInt(15), ShouldEqual, 15)
  203. So(sec.Key("INT64_404").MustInt64(15), ShouldEqual, 15)
  204. So(sec.Key("UINT_404").MustUint(6), ShouldEqual, 6)
  205. So(sec.Key("UINT64_404").MustUint64(6), ShouldEqual, 6)
  206. So(sec.Key("HEX_NUMBER_404").MustInt(0x3001), ShouldEqual, 0x3001)
  207. t, err := time.Parse(time.RFC3339, "2014-01-01T20:17:05Z")
  208. So(err, ShouldBeNil)
  209. So(sec.Key("TIME_404").MustTime(t).String(), ShouldEqual, t.String())
  210. So(sec.Key("DURATION_404").MustDuration(dur).Seconds(), ShouldEqual, dur.Seconds())
  211. Convey("Must should set default as key value", func() {
  212. So(sec.Key("STRING_404").String(), ShouldEqual, "404")
  213. So(sec.Key("BOOL_404").String(), ShouldEqual, "true")
  214. So(sec.Key("FLOAT64_404").String(), ShouldEqual, "2.5")
  215. So(sec.Key("INT_404").String(), ShouldEqual, "15")
  216. So(sec.Key("INT64_404").String(), ShouldEqual, "15")
  217. So(sec.Key("UINT_404").String(), ShouldEqual, "6")
  218. So(sec.Key("UINT64_404").String(), ShouldEqual, "6")
  219. So(sec.Key("TIME_404").String(), ShouldEqual, "2014-01-01T20:17:05Z")
  220. So(sec.Key("DURATION_404").String(), ShouldEqual, "2h45m0s")
  221. So(sec.Key("HEX_NUMBER_404").String(), ShouldEqual, "12289")
  222. })
  223. })
  224. })
  225. })
  226. Convey("Get value with candidates", func() {
  227. sec := f.Section("types")
  228. So(sec.Key("STRING").In("", []string{"str", "arr", "types"}), ShouldEqual, "str")
  229. So(sec.Key("FLOAT64").InFloat64(0, []float64{1.25, 2.5, 3.75}), ShouldEqual, 1.25)
  230. So(sec.Key("INT").InInt(0, []int{10, 20, 30}), ShouldEqual, 10)
  231. So(sec.Key("INT").InInt64(0, []int64{10, 20, 30}), ShouldEqual, 10)
  232. So(sec.Key("UINT").InUint(0, []uint{3, 6, 9}), ShouldEqual, 3)
  233. So(sec.Key("UINT").InUint64(0, []uint64{3, 6, 9}), ShouldEqual, 3)
  234. zt, err := time.Parse(time.RFC3339, "0001-01-01T01:00:00Z")
  235. So(err, ShouldBeNil)
  236. t, err := time.Parse(time.RFC3339, "2015-01-01T20:17:05Z")
  237. So(err, ShouldBeNil)
  238. So(sec.Key("TIME").InTime(zt, []time.Time{t, time.Now(), time.Now().Add(1 * time.Second)}).String(), ShouldEqual, t.String())
  239. Convey("Get value with candidates and default value", func() {
  240. So(sec.Key("STRING_404").In("str", []string{"str", "arr", "types"}), ShouldEqual, "str")
  241. So(sec.Key("FLOAT64_404").InFloat64(1.25, []float64{1.25, 2.5, 3.75}), ShouldEqual, 1.25)
  242. So(sec.Key("INT_404").InInt(10, []int{10, 20, 30}), ShouldEqual, 10)
  243. So(sec.Key("INT64_404").InInt64(10, []int64{10, 20, 30}), ShouldEqual, 10)
  244. So(sec.Key("UINT_404").InUint(3, []uint{3, 6, 9}), ShouldEqual, 3)
  245. So(sec.Key("UINT_404").InUint64(3, []uint64{3, 6, 9}), ShouldEqual, 3)
  246. So(sec.Key("TIME_404").InTime(t, []time.Time{time.Now(), time.Now(), time.Now().Add(1 * time.Second)}).String(), ShouldEqual, t.String())
  247. })
  248. })
  249. Convey("Get values in range", func() {
  250. sec := f.Section("types")
  251. So(sec.Key("FLOAT64").RangeFloat64(0, 1, 2), ShouldEqual, 1.25)
  252. So(sec.Key("INT").RangeInt(0, 10, 20), ShouldEqual, 10)
  253. So(sec.Key("INT").RangeInt64(0, 10, 20), ShouldEqual, 10)
  254. minT, err := time.Parse(time.RFC3339, "0001-01-01T01:00:00Z")
  255. So(err, ShouldBeNil)
  256. midT, err := time.Parse(time.RFC3339, "2013-01-01T01:00:00Z")
  257. So(err, ShouldBeNil)
  258. maxT, err := time.Parse(time.RFC3339, "9999-01-01T01:00:00Z")
  259. So(err, ShouldBeNil)
  260. t, err := time.Parse(time.RFC3339, "2015-01-01T20:17:05Z")
  261. So(err, ShouldBeNil)
  262. So(sec.Key("TIME").RangeTime(t, minT, maxT).String(), ShouldEqual, t.String())
  263. Convey("Get value in range with default value", func() {
  264. So(sec.Key("FLOAT64").RangeFloat64(5, 0, 1), ShouldEqual, 5)
  265. So(sec.Key("INT").RangeInt(7, 0, 5), ShouldEqual, 7)
  266. So(sec.Key("INT").RangeInt64(7, 0, 5), ShouldEqual, 7)
  267. So(sec.Key("TIME").RangeTime(t, minT, midT).String(), ShouldEqual, t.String())
  268. })
  269. })
  270. Convey("Get values into slice", func() {
  271. sec := f.Section("array")
  272. So(strings.Join(sec.Key("STRINGS").Strings(","), ","), ShouldEqual, "en,zh,de")
  273. So(len(sec.Key("STRINGS_404").Strings(",")), ShouldEqual, 0)
  274. vals1 := sec.Key("FLOAT64S").Float64s(",")
  275. float64sEqual(vals1, 1.1, 2.2, 3.3)
  276. vals2 := sec.Key("INTS").Ints(",")
  277. intsEqual(vals2, 1, 2, 3)
  278. vals3 := sec.Key("INTS").Int64s(",")
  279. int64sEqual(vals3, 1, 2, 3)
  280. vals4 := sec.Key("UINTS").Uints(",")
  281. uintsEqual(vals4, 1, 2, 3)
  282. vals5 := sec.Key("UINTS").Uint64s(",")
  283. uint64sEqual(vals5, 1, 2, 3)
  284. t, err := time.Parse(time.RFC3339, "2015-01-01T20:17:05Z")
  285. So(err, ShouldBeNil)
  286. vals6 := sec.Key("TIMES").Times(",")
  287. timesEqual(vals6, t, t, t)
  288. })
  289. Convey("Test string slice escapes", func() {
  290. sec := f.Section("string escapes")
  291. So(sec.Key("key1").Strings(","), ShouldResemble, []string{"value1", "value2", "value3"})
  292. So(sec.Key("key2").Strings(","), ShouldResemble, []string{"value1, value2"})
  293. So(sec.Key("key3").Strings(","), ShouldResemble, []string{`val\ue1`, "value2"})
  294. So(sec.Key("key4").Strings(","), ShouldResemble, []string{`value1\`, `value\\2`})
  295. So(sec.Key("key5").Strings(",,"), ShouldResemble, []string{"value1,, value2"})
  296. So(sec.Key("key6").Strings(" "), ShouldResemble, []string{"aaa", "bbb and space", "ccc"})
  297. })
  298. Convey("Get valid values into slice", func() {
  299. sec := f.Section("array")
  300. vals1 := sec.Key("FLOAT64S").ValidFloat64s(",")
  301. float64sEqual(vals1, 1.1, 2.2, 3.3)
  302. vals2 := sec.Key("INTS").ValidInts(",")
  303. intsEqual(vals2, 1, 2, 3)
  304. vals3 := sec.Key("INTS").ValidInt64s(",")
  305. int64sEqual(vals3, 1, 2, 3)
  306. vals4 := sec.Key("UINTS").ValidUints(",")
  307. uintsEqual(vals4, 1, 2, 3)
  308. vals5 := sec.Key("UINTS").ValidUint64s(",")
  309. uint64sEqual(vals5, 1, 2, 3)
  310. t, err := time.Parse(time.RFC3339, "2015-01-01T20:17:05Z")
  311. So(err, ShouldBeNil)
  312. vals6 := sec.Key("TIMES").ValidTimes(",")
  313. timesEqual(vals6, t, t, t)
  314. })
  315. Convey("Get values one type into slice of another type", func() {
  316. sec := f.Section("array")
  317. vals1 := sec.Key("STRINGS").ValidFloat64s(",")
  318. So(vals1, ShouldBeEmpty)
  319. vals2 := sec.Key("STRINGS").ValidInts(",")
  320. So(vals2, ShouldBeEmpty)
  321. vals3 := sec.Key("STRINGS").ValidInt64s(",")
  322. So(vals3, ShouldBeEmpty)
  323. vals4 := sec.Key("STRINGS").ValidUints(",")
  324. So(vals4, ShouldBeEmpty)
  325. vals5 := sec.Key("STRINGS").ValidUint64s(",")
  326. So(vals5, ShouldBeEmpty)
  327. vals6 := sec.Key("STRINGS").ValidTimes(",")
  328. So(vals6, ShouldBeEmpty)
  329. })
  330. Convey("Get valid values into slice without errors", func() {
  331. sec := f.Section("array")
  332. vals1, err := sec.Key("FLOAT64S").StrictFloat64s(",")
  333. So(err, ShouldBeNil)
  334. float64sEqual(vals1, 1.1, 2.2, 3.3)
  335. vals2, err := sec.Key("INTS").StrictInts(",")
  336. So(err, ShouldBeNil)
  337. intsEqual(vals2, 1, 2, 3)
  338. vals3, err := sec.Key("INTS").StrictInt64s(",")
  339. So(err, ShouldBeNil)
  340. int64sEqual(vals3, 1, 2, 3)
  341. vals4, err := sec.Key("UINTS").StrictUints(",")
  342. So(err, ShouldBeNil)
  343. uintsEqual(vals4, 1, 2, 3)
  344. vals5, err := sec.Key("UINTS").StrictUint64s(",")
  345. So(err, ShouldBeNil)
  346. uint64sEqual(vals5, 1, 2, 3)
  347. t, err := time.Parse(time.RFC3339, "2015-01-01T20:17:05Z")
  348. So(err, ShouldBeNil)
  349. vals6, err := sec.Key("TIMES").StrictTimes(",")
  350. So(err, ShouldBeNil)
  351. timesEqual(vals6, t, t, t)
  352. })
  353. Convey("Get invalid values into slice", func() {
  354. sec := f.Section("array")
  355. vals1, err := sec.Key("STRINGS").StrictFloat64s(",")
  356. So(vals1, ShouldBeEmpty)
  357. So(err, ShouldNotBeNil)
  358. vals2, err := sec.Key("STRINGS").StrictInts(",")
  359. So(vals2, ShouldBeEmpty)
  360. So(err, ShouldNotBeNil)
  361. vals3, err := sec.Key("STRINGS").StrictInt64s(",")
  362. So(vals3, ShouldBeEmpty)
  363. So(err, ShouldNotBeNil)
  364. vals4, err := sec.Key("STRINGS").StrictUints(",")
  365. So(vals4, ShouldBeEmpty)
  366. So(err, ShouldNotBeNil)
  367. vals5, err := sec.Key("STRINGS").StrictUint64s(",")
  368. So(vals5, ShouldBeEmpty)
  369. So(err, ShouldNotBeNil)
  370. vals6, err := sec.Key("STRINGS").StrictTimes(",")
  371. So(vals6, ShouldBeEmpty)
  372. So(err, ShouldNotBeNil)
  373. })
  374. })
  375. }
  376. func TestKey_StringsWithShadows(t *testing.T) {
  377. Convey("Get strings of shadows of a key", t, func() {
  378. f, err := ini.ShadowLoad([]byte(""))
  379. So(err, ShouldBeNil)
  380. So(f, ShouldNotBeNil)
  381. k, err := f.Section("").NewKey("NUMS", "1,2")
  382. So(err, ShouldBeNil)
  383. So(k, ShouldNotBeNil)
  384. k, err = f.Section("").NewKey("NUMS", "4,5,6")
  385. So(err, ShouldBeNil)
  386. So(k, ShouldNotBeNil)
  387. So(k.StringsWithShadows(","), ShouldResemble, []string{"1", "2", "4", "5", "6"})
  388. })
  389. }
  390. func TestKey_SetValue(t *testing.T) {
  391. Convey("Set value of key", t, func() {
  392. f := ini.Empty()
  393. So(f, ShouldNotBeNil)
  394. k, err := f.Section("").NewKey("NAME", "ini")
  395. So(err, ShouldBeNil)
  396. So(k, ShouldNotBeNil)
  397. So(k.Value(), ShouldEqual, "ini")
  398. k.SetValue("ini.v1")
  399. So(k.Value(), ShouldEqual, "ini.v1")
  400. })
  401. }
  402. func TestKey_NestedValues(t *testing.T) {
  403. Convey("Read and write nested values", t, func() {
  404. f, err := ini.LoadSources(ini.LoadOptions{
  405. AllowNestedValues: true,
  406. }, []byte(`
  407. aws_access_key_id = foo
  408. aws_secret_access_key = bar
  409. region = us-west-2
  410. s3 =
  411. max_concurrent_requests=10
  412. max_queue_size=1000`))
  413. So(err, ShouldBeNil)
  414. So(f, ShouldNotBeNil)
  415. So(f.Section("").Key("s3").NestedValues(), ShouldResemble, []string{"max_concurrent_requests=10", "max_queue_size=1000"})
  416. var buf bytes.Buffer
  417. _, err = f.WriteTo(&buf)
  418. So(err, ShouldBeNil)
  419. So(buf.String(), ShouldEqual, `aws_access_key_id = foo
  420. aws_secret_access_key = bar
  421. region = us-west-2
  422. s3 =
  423. max_concurrent_requests=10
  424. max_queue_size=1000
  425. `)
  426. })
  427. }
  428. func TestRecursiveValues(t *testing.T) {
  429. Convey("Recursive values should not reflect on same key", t, func() {
  430. f, err := ini.Load([]byte(`
  431. NAME = ini
  432. expires = yes
  433. [package]
  434. NAME = %(NAME)s
  435. expires = %(expires)s`))
  436. So(err, ShouldBeNil)
  437. So(f, ShouldNotBeNil)
  438. So(f.Section("package").Key("NAME").String(), ShouldEqual, "ini")
  439. So(f.Section("package").Key("expires").String(), ShouldEqual, "yes")
  440. })
  441. }