Skip to content

Commit

Permalink
feat:add service unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
geebytes committed May 24, 2024
1 parent 70326cf commit d2b768f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions internal/biz/endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,23 @@ func testWatcherUpdate(t *testing.T) {
err = watcher.Handle(context.TODO(), mvccpb.PUT, cnf.GetServiceKey(epId), string(val))
c.So(err, c.ShouldNotBeNil)
c.So(err.Error(), c.ShouldContainSubstring, "register error")
patch2.Reset()
gw := gateway.Get()

patch3 := gomonkey.ApplyMethodReturn(gw, "DeleteHandlerClient", fmt.Errorf("test DeleteHandlerClient error"))
defer patch3.Reset()
err = watcher.Handle(context.TODO(), mvccpb.PUT, cnf.GetServiceKey(epId), string(val))
patch3.Reset()
c.So(err, c.ShouldNotBeNil)
c.So(err.Error(), c.ShouldContainSubstring, "test DeleteHandlerClient error")

patch4 := gomonkey.ApplyFuncReturn(gateway.NewLoadBalanceEndpoint,nil, fmt.Errorf("test gateway.NewLoadBalanceEndpoint error"))
defer patch4.Reset()
err = watcher.Handle(context.TODO(), mvccpb.PUT, cnf.GetServiceKey(epId), string(val))
patch4.Reset()
c.So(err, c.ShouldNotBeNil)
c.So(err.Error(), c.ShouldContainSubstring, errors.ErrUnknownLoadBalancer.Error())


})
}
Expand Down Expand Up @@ -379,6 +396,11 @@ func testWatcherDel(t *testing.T) {
err = watcher.Handle(context.TODO(), mvccpb.DELETE, cnf.GetServiceKey(epId), string(val))
c.So(err, c.ShouldNotBeNil)
c.So(err.Error(), c.ShouldContainSubstring, "unregister error")
patch.Reset()

err = watcher.Handle(context.TODO(), mvccpb.Event_EventType(3), cnf.GetServiceKey(epId), string(val))
c.So(err, c.ShouldNotBeNil)
c.So(err.Error(), c.ShouldContainSubstring, "unknown operation")

})
}
Expand Down

0 comments on commit d2b768f

Please sign in to comment.