From dd2c285be53cc49cb9e37914a0bd363c36aef08b Mon Sep 17 00:00:00 2001 From: Guangwen Feng Date: Thu, 21 Sep 2023 12:07:44 +0800 Subject: [PATCH] test: add unit test for Notify (#2748) Signed-off-by: Guangwen Feng --- client/config/dynconfig_local_test.go | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/client/config/dynconfig_local_test.go b/client/config/dynconfig_local_test.go index 64e4b5ea9..4b542d1b9 100644 --- a/client/config/dynconfig_local_test.go +++ b/client/config/dynconfig_local_test.go @@ -149,3 +149,68 @@ func TestDynconfigLocal_GetResolveSchedulerAddrs(t *testing.T) { }) } } + +func TestDynconfigLocal_Notify(t *testing.T) { + grpcServer := grpc.NewServer() + healthpb.RegisterHealthServer(grpcServer, health.NewServer()) + l, err := net.Listen("tcp", ":3000") + if err != nil { + t.Fatal(err) + } + defer l.Close() + + tests := []struct { + name string + config *DaemonOption + }{ + { + name: "normal", + config: &DaemonOption{ + Scheduler: SchedulerOption{ + NetAddrs: []dfnet.NetAddr{ + { + Addr: "127.0.0.1:3000", + }, + }, + }, + }, + }, + { + name: "missing port in address", + config: &DaemonOption{ + Scheduler: SchedulerOption{ + NetAddrs: []dfnet.NetAddr{ + { + Addr: "127.0.0.1", + }, + }, + }, + }, + }, + { + name: "port value is illegal", + config: &DaemonOption{ + Scheduler: SchedulerOption{ + NetAddrs: []dfnet.NetAddr{ + { + Addr: "127.0.0.1:", + }, + }, + }, + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + dynconfig, err := NewDynconfig(LocalSourceType, tc.config) + if err != nil { + t.Fatal(err) + } + + errNotify := dynconfig.Notify() + assert := assert.New(t) + assert.NoError(errNotify) + }) + } +}