add definition config
This commit is contained in:
@@ -23,17 +23,17 @@ func TestProvider(t *testing.T) {
|
||||
et, err := test.NewEtcd(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
provider := etcd.NewProvider(et)
|
||||
provider := etcd.NewProvider("fdevs", "config", et)
|
||||
read := []test.Read{
|
||||
test.NewRead("db_dsn", test.DSN),
|
||||
test.NewRead("duration", 12*time.Minute),
|
||||
test.NewRead("port", 8080),
|
||||
test.NewRead("maintain", true),
|
||||
test.NewRead("start_at", test.Time("2020-01-02T15:04:05Z")),
|
||||
test.NewRead("percent", .064),
|
||||
test.NewRead("count", uint(2020)),
|
||||
test.NewRead("int64", int64(2021)),
|
||||
test.NewRead("uint64", int64(2022)),
|
||||
test.NewRead(test.DSN, "db_dsn"),
|
||||
test.NewRead(12*time.Minute, "duration"),
|
||||
test.NewRead(8080, "port"),
|
||||
test.NewRead(true, "maintain"),
|
||||
test.NewRead(test.Time("2020-01-02T15:04:05Z"), "start_at"),
|
||||
test.NewRead(.064, "percent"),
|
||||
test.NewRead(uint(2020), "count"),
|
||||
test.NewRead(int64(2021), "int64"),
|
||||
test.NewRead(int64(2022), "uint64"),
|
||||
test.NewReadConfig("config"),
|
||||
}
|
||||
test.Run(t, provider, read)
|
||||
@@ -49,11 +49,7 @@ func TestWatcher(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
key := config.Key{
|
||||
AppName: "config",
|
||||
Namespace: "fdevs",
|
||||
Name: "test_watch",
|
||||
}
|
||||
key := "test_watch"
|
||||
|
||||
et, err := test.NewEtcd(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -65,24 +61,24 @@ func TestWatcher(t *testing.T) {
|
||||
|
||||
var cnt, cnt2 int32
|
||||
|
||||
prov := etcd.NewProvider(et)
|
||||
prov := etcd.NewProvider("fdevs", "config", et)
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(6)
|
||||
|
||||
watch := func(cnt *int32) func(ctx context.Context, oldVar, newVar config.Variable) {
|
||||
return func(ctx context.Context, oldVar, newVar config.Variable) {
|
||||
watch := func(cnt *int32) func(ctx context.Context, oldVar, newVar config.Value) {
|
||||
return func(ctx context.Context, oldVar, newVar config.Value) {
|
||||
switch *cnt {
|
||||
case 0:
|
||||
assert.Equal(t, value(*cnt), newVar.Value.String())
|
||||
assert.Nil(t, oldVar.Value)
|
||||
assert.Equal(t, value(*cnt), newVar.String())
|
||||
assert.Nil(t, oldVar)
|
||||
case 1:
|
||||
assert.Equal(t, value(*cnt), newVar.Value.String())
|
||||
assert.Equal(t, value(*cnt-1), oldVar.Value.String())
|
||||
assert.Equal(t, value(*cnt), newVar.String())
|
||||
assert.Equal(t, value(*cnt-1), oldVar.String())
|
||||
case 2:
|
||||
_, perr := newVar.Value.ParseString()
|
||||
_, perr := newVar.ParseString()
|
||||
assert.NoError(t, perr)
|
||||
assert.Equal(t, "", newVar.Value.String())
|
||||
assert.Equal(t, value(*cnt-1), oldVar.Value.String())
|
||||
assert.Equal(t, "", newVar.String())
|
||||
assert.Equal(t, value(*cnt-1), oldVar.String())
|
||||
default:
|
||||
assert.Fail(t, "unexpected watch")
|
||||
}
|
||||
@@ -92,8 +88,8 @@ func TestWatcher(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
err = prov.Watch(ctx, key, watch(&cnt))
|
||||
err = prov.Watch(ctx, key, watch(&cnt2))
|
||||
err = prov.Watch(ctx, watch(&cnt), key)
|
||||
err = prov.Watch(ctx, watch(&cnt2), key)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.AfterFunc(time.Second, func() {
|
||||
|
||||
Reference in New Issue
Block a user