func TournamentTest(test *testing.T, f func(*testutil.T, *Tournament)) { t := (*testutil.T)(test) if host, err := git.CreateGitHost(":temp:", nil); err != nil { t.ErrorNow(err) } else { defer host.Cleanup() gzReplay := bytes.Buffer{} gz := gzip.NewWriter(&gzReplay) if xmlReplay, err := xml.MarshalIndent(bc2015.Replay{}, "", "\t"); err != nil { t.ErrorNow(err) } else if _, err := gz.Write(xmlReplay); err != nil { t.ErrorNow(err) } else if err := gz.Close(); err != nil { t.ErrorNow(err) } dummyArena := arena.DummyArena{time.Now(), arena.MatchResult{arena.WinnerA, arena.ReasonVictory, gzReplay.Bytes()}, nil} remote := git.TempRemote{} bootstrap := &arena.MinimalBootstrap{"../arena/internal/categories"} if database, err := NewInMemoryDatabase(); err != nil { t.ErrorNow(err) } else if err = database.MigrateSchema(); err != nil { t.ErrorNow(err) } else { tournament := NewTournament(database, dummyArena, bootstrap, host, remote) f(t, tournament) } } }
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) } } } }
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 } }