Beispiel #1
0
func getTestRouter(t *testing.T) *testRouter {
	ctrl := gomock.NewController(t)
	discovery := discovery.NewMockClient(ctrl)
	r := &testRouter{
		router: &router{
			Component: &component.Component{
				Discovery: discovery,
				Ctx:       GetLogger(t, "TestRouter"),
			},
			gateways: map[string]*gateway.Gateway{},
		},
		ctrl:      ctrl,
		discovery: discovery,
	}
	r.InitStatus()
	return r
}
Beispiel #2
0
func TestGetAndVerifyContext(t *testing.T) {
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	tmpDir := fmt.Sprintf("%s/%d", os.TempDir(), r.Int63())
	os.Mkdir(tmpDir, 755)
	defer os.Remove(tmpDir)

	a := assertions.New(t)
	c := new(Component)

	c.Identity = new(discovery.Announcement)

	c.Config.KeyDir = tmpDir
	security.GenerateKeypair(tmpDir)
	c.initKeyPair()

	{
		ctx := c.GetContext("")
		_, err := c.ValidateNetworkContext(ctx)
		a.So(err, assertions.ShouldNotBeNil)
	}

	c.Identity.Id = "test-context"
	{
		ctx := c.GetContext("")
		_, err := c.ValidateNetworkContext(ctx)
		a.So(err, assertions.ShouldNotBeNil)
	}

	c.Identity.ServiceName = "test-service"

	ctrl := gomock.NewController(t)
	discoveryClient := discovery.NewMockClient(ctrl)
	c.Discovery = discoveryClient

	discoveryClient.EXPECT().Get("test-service", "test-context").Return(c.Identity, nil)

	ctx := c.GetContext("")
	_, err := c.ValidateNetworkContext(ctx)
	a.So(err, assertions.ShouldBeNil)

}
Beispiel #3
0
func getTestBroker(t *testing.T) *testBroker {
	ctrl := gomock.NewController(t)
	discovery := pb_discovery.NewMockClient(ctrl)
	ns := pb_networkserver.NewMockNetworkServerClient(ctrl)
	b := &testBroker{
		broker: &broker{
			Component: &component.Component{
				Discovery: discovery,
				Ctx:       GetLogger(t, "TestBroker"),
			},
			handlers:               make(map[string]*handler),
			activationDeduplicator: NewDeduplicator(10 * time.Millisecond),
			uplinkDeduplicator:     NewDeduplicator(10 * time.Millisecond),
			ns:                     ns,
		},
		ns:        ns,
		ctrl:      ctrl,
		discovery: discovery,
	}
	b.InitStatus()
	return b
}