Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic when update with slice / map val #156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions archaius_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ func (e EListener) Event(event *event.Event) {
openlog.Info(fmt.Sprintf("config value after change %s |%s", event.Key, event.Value))
}

var filename2 string

func TestInit(t *testing.T) {
f1Bytes := []byte(`
age: 14
Expand All @@ -33,7 +31,7 @@ exist: true
`)
d, _ := os.Getwd()
filename1 := filepath.Join(d, "f1.yaml")
filename2 = filepath.Join(d, "f2.yaml")
filename2 := filepath.Join(d, "f2.yaml")
f1, err := os.Create(filename1)
assert.NoError(t, err)
defer f1.Close()
Expand Down Expand Up @@ -116,6 +114,25 @@ func TestConfig_RegisterListener(t *testing.T) {

}

func TestConfig_Update(t *testing.T) {
t.Run("update a simple type config", func(t *testing.T) {
assert.NoError(t, archaius.Set("aNumber", 1))
assert.NoError(t, archaius.Set("aNumber", 2))
})
t.Run("update a slice config", func(t *testing.T) {
assert.NoError(t, archaius.Set("aSlice", []int{1,2,3}))
assert.NoError(t, archaius.Set("aSlice", []int{1,2,3}))
assert.NoError(t, archaius.Set("aSlice", 1))
assert.NoError(t, archaius.Set("aSlice", []int{1,2,3}))
})
t.Run("update a map config", func(t *testing.T) {
assert.NoError(t, archaius.Set("aMap", map[int]int{1: 1}))
assert.NoError(t, archaius.Set("aMap", map[int]int{1: 1}))
assert.NoError(t, archaius.Set("aMap", 1))
assert.NoError(t, archaius.Set("aMap", map[int]int{1: 1}))
})
}

func TestUnmarshalConfig(t *testing.T) {
b := []byte(`
key: peter
Expand Down
4 changes: 2 additions & 2 deletions source/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ func (m *Manager) updateEventWithConfigUpdateLock(e *event.Event) error {
}
// we need to update cache if oldSrc != src || oldVal != val
m.updateCacheWithoutConfigUpdateLock(src.GetSourceName(), e.Key, val)
if oldVal == val {
openlog.Info(fmt.Sprintf("the key %s value %s is up-to-date, ignore value change", e.Key, val))
if reflect.DeepEqual(oldVal, val) {
openlog.Info(fmt.Sprintf("the key %q value %+v is up-to-date, ignore value change", e.Key, val))
return ErrIgnoreChange
}
}
Expand Down