优化结构
This commit is contained in:
@@ -3,6 +3,7 @@ package runtimeconfig
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStoreSetDeleteAndSubscribe(t *testing.T) {
|
||||
@@ -28,3 +29,37 @@ func TestStoreSetDeleteAndSubscribe(t *testing.T) {
|
||||
t.Fatalf("delete update = %#v", update)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreReplaceSkipsUnchangedValues(t *testing.T) {
|
||||
store := NewStore()
|
||||
updates := make(chan Config, 2)
|
||||
stop := store.Subscribe("mq", "rabbitmq", func(config Config) { updates <- config })
|
||||
defer stop()
|
||||
|
||||
config := Config{Kind: "mq", Provider: "rabbitmq", Enabled: true, Values: json.RawMessage(`{"host":"localhost"}`)}
|
||||
store.Set(config)
|
||||
select {
|
||||
case <-updates:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("initial set notification was not delivered")
|
||||
}
|
||||
|
||||
store.Replace([]Config{config})
|
||||
select {
|
||||
case update := <-updates:
|
||||
t.Fatalf("unchanged replace emitted notification: %#v", update)
|
||||
case <-time.After(20 * time.Millisecond):
|
||||
}
|
||||
|
||||
changed := config
|
||||
changed.Values = json.RawMessage(`{"host":"other"}`)
|
||||
store.Replace([]Config{changed})
|
||||
select {
|
||||
case update := <-updates:
|
||||
if string(update.Values) != string(changed.Values) {
|
||||
t.Fatalf("changed replace = %#v", update)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("changed replace notification was not delivered")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user