Example #1
0
func TestOutput(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	message := &LogMessage{Level: 1}

	mockLogOuter := NewMockLogOuter(mockCtrl)
	mockLogOuter.EXPECT().Output(message)

	logger := NewLogger(mockLogOuter, 0, nil)
	logger.Log(1, func() *LogMessage { return message })
}
Example #2
0
func TestNoOutput(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	mockLogOuter := NewMockLogOuter(mockCtrl)

	var called bool = false

	logger := NewLogger(mockLogOuter, 1, nil)
	// The message is logged below the filter level.
	logger.Log(0, func() *LogMessage { called = true; return nil })

	if called {
		t.Error("Closure evaluated even though no output produced")
	}
}
Example #3
0
func TestFailFunc(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	mockLogOuter := NewMockLogOuter(mockCtrl)

	var called bool = false

	// TODO(awreece) Our testing fail function violates spec by returning to
	// normal control flow?
	logger := NewLogger(mockLogOuter, 1, func() { called = true })

	logger.FailNow()
	if !called {
		t.Error("Fail function not called!")
	}
}
func TestCommandFramework(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	itemType1 := gamerules.ItemType{1, "1", 64, 0, 0}

	mockGame := gamerules.NewMockIGame(mockCtrl)
	mockPlayer := gamerules.NewMockIPlayerClient(mockCtrl)
	mockOther := gamerules.NewMockIPlayerClient(mockCtrl)

	cf := NewCommandFramework("/")

	mockGame.EXPECT().BroadcastMessage("§dthis is a broadcast")
	cf.Process(mockPlayer, "/say this is a broadcast", mockGame)

	mockGame.EXPECT().PlayerByName("thePlayer").Return(mockPlayer)
	mockGame.EXPECT().ItemTypeById(1).Return(itemType1, true)
	mockPlayer.EXPECT().EchoMessage("Giving 64 of '1' to thePlayer")
	mockPlayer.EXPECT().GiveItem(gamerules.Slot{1, 64, 0})
	cf.Process(mockPlayer, "/give thePlayer 1 64", mockGame)

	mockGame.EXPECT().PlayerByName("otherPlayer")
	mockPlayer.EXPECT().EchoMessage("'otherPlayer' is not logged in")
	cf.Process(mockPlayer, "/give otherPlayer 1 64", mockGame)

	mockGame.EXPECT().PlayerByName("otherPlayer").Return(mockOther)
	mockGame.EXPECT().ItemTypeById(1).Return(gamerules.ItemType{}, false)
	mockPlayer.EXPECT().EchoMessage("'1' is not a valid item id")
	cf.Process(mockPlayer, "/give otherPlayer 1 64", mockGame)

	mockGame.EXPECT().PlayerByName("otherPlayer").Return(mockOther)
	mockGame.EXPECT().ItemTypeById(1).Return(itemType1, true)
	mockPlayer.EXPECT().EchoMessage("Cannot give more than 512 items at once")
	cf.Process(mockPlayer, "/give otherPlayer 1 513", mockGame)

	mockPlayer.EXPECT().EchoMessage(&testmatcher.StringPrefix{"Commands:"})
	cf.Process(mockPlayer, "/help", mockGame)

	gomock.InOrder(
		mockPlayer.EXPECT().EchoMessage("Command: /help"),
		mockPlayer.EXPECT().EchoMessage("Usage: help|?"),
		mockPlayer.EXPECT().EchoMessage("Description: Shows a list of all commands."),
	)
	cf.Process(mockPlayer, "/help help", mockGame)
}
Example #5
0
func TestSetMinLogLevel(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	message := &LogMessage{}

	mockLogOuter := NewMockLogOuter(mockCtrl)
	mockLogOuter.EXPECT().Output(message)

	logger := NewLogger(mockLogOuter, 0, nil)
	logger.Log(0, func() *LogMessage { return message })

	logger.SetMinLogLevel(1)

	var called bool = false
	logger.Log(0, func() *LogMessage { called = true; return nil })

	if called {
		t.Error("Message logged when log level wrong")
	}
}
Example #6
0
func testTickFixtures(t *testing.T) (mockCtrl *gomock.Controller, mockBlockQuerier *MockIBlockQuerier, pointObj *PointObject) {
	mockCtrl = gomock.NewController(t)
	mockBlockQuerier = NewMockIBlockQuerier(mockCtrl)
	pointObj = new(PointObject)
	return
}