示例#1
0
func ServerTest(test *testing.T, f func(*testutil.T, *ServerState)) {
	t := (*testutil.T)(test)
	if host, err := git.CreateGitHost(":temp:", nil); err != nil {
		t.ErrorNow(err)
	} else {
		defer host.Cleanup()
		if replay, err := ioutil.ReadFile("../simulator/" + string(tournament.CategoryBattlecode2015) + "/replay.xml.gz"); err != nil {
			t.ErrorNow()
		} else {
			dummyArena := arena.DummyArena{time.Now(), arena.MatchResult{arena.WinnerA, arena.ReasonVictory, replay}, nil}
			remote := &git.TempRemote{}
			bootstrap := &arena.MinimalBootstrap{"../arena/internal/categories"}
			if database, err := tournament.NewInMemoryDatabase(); err != nil {
				t.ErrorNow(err)
			} else if err = database.MigrateSchema(); err != nil {
				t.ErrorNow(err)
			} else {
				tournament := tournament.NewTournament(database, dummyArena, bootstrap, host, remote)
				properties := Properties{
					":memory:",
					"8081",
					":temp:",
					nil,
					"../arena",
				}
				server := NewServer(tournament, properties)
				f(t, server)
			}
		}
	}
}
示例#2
0
func CreateServer(properties server.Properties) (*server.ServerState, error) {
	if database, err := tournament.OpenDatabase(properties.DatabaseURL); err != nil {
		return nil, err
	} else if err := database.MigrateSchema(); err != nil {
		return nil, err
	} else if host, err := git.CreateGitHost(properties.GitServerType, properties.GitServerConf); err != nil {
		return nil, err
	} else if err := host.Validate(); err != nil {
		return nil, err
	} else {
		matchArena := arena.NewArena(properties.ArenaResourcePath())
		remote := git.TempRemote{}
		bootstrap := arena.MinimalBootstrap{properties.ArenaResourcePath()}
		tm := tournament.NewTournament(database, matchArena, bootstrap, host, remote)
		webserver := server.NewServer(tm, properties)
		return webserver, nil
	}

}