| 1097 | } |
| 1098 | |
| 1099 | func TestSet(t *testing.T) { |
| 1100 | var ( |
| 1101 | assert = assert.New(t) |
| 1102 | k = koanf.New(delim) |
| 1103 | ) |
| 1104 | assert.Nil(k.Load(file.Provider(mockYAML), yaml.Parser()), |
| 1105 | "error loading file") |
| 1106 | |
| 1107 | assert.Nil(k.Set("parent1.name", "new")) |
| 1108 | assert.Equal(k.String("parent1.name"), "new") |
| 1109 | |
| 1110 | assert.Nil(k.Set("parent1.child1.name", 123)) |
| 1111 | assert.Equal(k.Int("parent1.child1.name"), 123) |
| 1112 | |
| 1113 | assert.Nil(k.Set("parent1.child1.grandchild1.ids", []int{5})) |
| 1114 | assert.Equal(k.Ints("parent1.child1.grandchild1.ids"), []int{5}) |
| 1115 | |
| 1116 | assert.Nil(k.Set("parent1.child1.grandchild1", 123)) |
| 1117 | assert.Equal(k.Int("parent1.child1.grandchild1"), 123) |
| 1118 | assert.Equal(k.Int("parent1.child1.grandchild1.ids"), 0) |
| 1119 | |
| 1120 | assert.Nil(k.Set("parent1.child1.grandchild1", map[string]any{"name": "new"})) |
| 1121 | assert.Equal(k.Get("parent1.child1.grandchild1"), map[string]any{"name": "new"}) |
| 1122 | } |
| 1123 | |
| 1124 | func TestUnmarshal(t *testing.T) { |
| 1125 | assert := assert.New(t) |