Exemplo n.º 1
0
// SetupTest prepares the test suite for running by making a fake system
// query service, providing it to a real client query service (the one we
// are testing)
func (suite *ClientQueriesTestSuite) SetupTest() {
	suite.log = logger.Log("client_test")
	var (
		d directory.Directory

		systemQueries MockSystemQueries
		clientQueries ClientQueryService
		mockUsers     MockUsers
	)

	systemQueries.complete = true

	// Set up a directory with:
	//  - A real ClientQueryService (The one we are testing)
	//  - The mocked SystemQueries implementation
	d = directory.New()
	d.AddService("clientQueries", &clientQueries)
	d.AddService("systemQueries", &systemQueries)
	d.AddService("users", &mockUsers)

	// Populate the directory so that clientQueries knows to use our mocked
	// systemQueries
	if err := d.Start(); err != nil {
		suite.log.Fatalf("Could not start directory (%v)", err)
	}

	// Store references for use in tests
	suite.mockSystemQueries = &systemQueries
	suite.clientQueries = &clientQueries
	suite.mockUsers = &mockUsers
}
Exemplo n.º 2
0
func (suite *QueryTestSuite) SetupTest() {
	suite.log = logger.Log("queries_test")

	var (
		d              directory.Directory
		systemQueries  MockSystemQueries
		gameCalculator MockGameCalculator
		events         MockEventsService
		queriesCache   MockQueriesCache
	)

	d = directory.New()
	suite.InitTestConfig()
	d.AddService("configProvider", suite.ConfigProvider)
	d.AddService("systemQueries", &systemQueries)
	d.AddService("gameCalculator", &gameCalculator)
	d.AddService("eventsService", &events)
	d.AddService("queriesCache", &queriesCache)

	if err := d.Start(); err != nil {
		suite.log.Fatalf("Could not start directory: %v", err)
	}

	suite.mockSystemQueries = &systemQueries
	suite.mockGameCalculator = &gameCalculator
	suite.mockEvents = &events
	suite.mockQueriesCache = &queriesCache
}
Exemplo n.º 3
0
func (suite *EventsTestSuite) SetupTest() {
	suite.InitTestConfig()
	suite.log = logger.Log("events_test")

	var (
		d          directory.Directory
		events     *EventsService
		subscriber *MockSubscriber
	)

	events = NewEvents().(*EventsService)
	subscriber = newMockSubscriber().(*MockSubscriber)

	d = directory.New()
	d.AddService("configProvider", suite.ConfigProvider)
	d.AddService("eventSubscriber", subscriber)
	d.AddService("events", events)

	if err := d.Start(); err != nil {
		suite.log.Fatalf("Could not start directory: %v", err)
	}

	suite.events = events
	suite.mockSubscriber = subscriber

	suite.events.ResetTestDB()
}
Exemplo n.º 4
0
func NewApp() *App {
	app := new(App)

	wd, _ := os.Getwd()
	app.config = config.NewConfigProvider("config", wd)

	app.directory = directory.New()

	app.runFixtures = flag.Bool("fixtures", false, "run fixtures")
	flag.Parse()

	return app
}
Exemplo n.º 5
0
func (suite *ConfigTestSuite) TestProvide() {
	var (
		d directory.Directory = directory.New()
	)

	cfg := NewConfigProvider("testconfig", "../").(*viperProvider)

	d.AddService("configProvider", cfg)
	d.AddService("cacheService", &cacheService{})

	err := d.Start()

	assert := assert.New(suite.T())
	assert.Nil(err, "Unable to populate queries cache config")
}
Exemplo n.º 6
0
func (suite *QueriesCacheTestSuite) SetupTest() {
	suite.InitTestConfig()
	suite.log = logger.Log("cache_test")

	var (
		d     directory.Directory
		cache *queriesCache
	)

	cache = NewQueriesCache().(*queriesCache)

	d = directory.New()
	d.AddService("configProvider", suite.ConfigProvider)
	d.AddService("queriesCache", cache)

	if err := d.Start(); err != nil {
		suite.log.Fatalf("Could not start directory: %v", err)
	}

	suite.cache = cache
	suite.cache.collection.Remove(map[string]string{})
}
Exemplo n.º 7
0
func (suite *IntegrationTestSuite) SetupTest() {
	configProvider := config.NewConfigProvider("testconfig", "./")

	suite.log = logger.Log("integration_test")

	suite.Commands = commands.New()
	suite.Queries = queries.NewClientQueryService()

	systemQueries := queries.NewSystemQueryService().(*queries.SystemQueryService)
	eventsService := events.NewEvents().(*events.EventsService)
	usersService := users.NewUsers().(*users.UsersService)

	d := directory.New()
	d.AddService("configProvider", configProvider)
	d.AddService("gameCalculator", game.NewGameCalculator())
	d.AddService("eventSubscriber", queries.NewQueryBuffer())

	d.AddService("systemQueries", systemQueries)
	d.AddService("events", eventsService)
	d.AddService("users", usersService)

	d.AddService("commands", suite.Commands)
	d.AddService("clientQueries", suite.Queries)

	err := d.Start()
	if err != nil {
		suite.log.Fatalf("Could not start directory: %v", err)
	}

	err = d.Start("eventSubscriber")
	if err != nil {
		msg := fmt.Sprintf("Could not start event subscriber: %v", err)
		log.Error(msg)
		return
	}

	usersService.ResetTestDB()
	eventsService.ResetTestDB()
	systemQueries.Cache.Flush()

	time.Sleep(1 * time.Second)

	white := users.User{
		Uuid:           users.NewId(),
		Name:           "whitePlayer",
		AuthIdentifier: "whiteAuthId",
	}
	usersService.Save(&white)

	black := users.User{
		Uuid:           users.NewId(),
		Name:           "blackPlayer",
		AuthIdentifier: "blackAuthId",
	}
	usersService.Save(&black)

	suite.log.Info("white UUID: %s", white.Uuid)
	suite.log.Info("black UUID: %s", black.Uuid)
	suite.whiteId = white.Uuid
	suite.blackId = black.Uuid
}