コード例 #1
0
ファイル: repo_test.go プロジェクト: GlenKelley/battleref
func TestPush(t *testing.T) {
	LocalDirHostTest(t, func(t *testutil.T, host *LocalDirHost) {
		t.CheckError(host.InitRepository("foo", nil, nil))
		repoURL := host.RepositoryURL("foo")
		var head string
		if repo, err := (TempRemote{}).CheckoutRepository(repoURL); err != nil {
			t.ErrorNow(err)
		} else {
			defer repo.Delete()
			t.CheckError(ioutil.WriteFile(filepath.Join(repo.Dir(), "foo.txt"), []byte("hello"), os.ModePerm))
			t.CheckError(repo.AddFiles([]string{"foo.txt"}))
			t.CheckError(repo.CommitFiles([]string{"foo.txt"}, "commit message"))
			t.CheckError(repo.Push())
			if h, err := repo.Head(); err != nil {
				t.ErrorNow(err)
			} else {
				head = h
			}
		}
		if repo, err := (TempRemote{}).CheckoutRepository(repoURL); err != nil {
			t.ErrorNow(err)
		} else {
			defer repo.Delete()
			if head2, err := repo.Head(); err != nil {
				t.ErrorNow(err)
			} else if head != head2 {
				t.ErrorNowf("Expected <%v> != Actual <%v>", head, head2)
			}
		}

	})
}
コード例 #2
0
ファイル: host_test.go プロジェクト: GlenKelley/battleref
func TestInitLocalRepo(t *testing.T) {
	LocalDirHostTest(t, func(t *testutil.T, local *LocalDirHost) {
		t.CheckError(local.InitRepository("foo", nil, nil))
		repoURL := local.RepositoryURL("foo")
		if stat, err := os.Stat(repoURL); err != nil {
			t.ErrorNow(err)
		} else if !stat.IsDir() {
			t.ErrorNowf("%s is not a directory", repoURL)
		} else {
			CheckDirectoryContent(t, repoURL, []string{"HEAD", "branches", "config", "description", "hooks", "info", "objects", "refs"})
		}
	})
}
コード例 #3
0
func TestListCategories(t *testing.T) {
	TournamentTest(t, func(t *testutil.T, tm *Tournament) {
		categories := tm.ListCategories()
		if len(categories) != 3 {
			t.ErrorNowf("expected 3 category, got %v", len(categories))
		}
		as := []string{}
		bs := []string{string(CategoryBattlecode2014), string(CategoryBattlecode2015), string(CategoryBattlecode2016)}
		for _, category := range categories {
			as = append(as, string(category))
		}
		t.CompareStringsUnsorted(as, bs)
	})
}
コード例 #4
0
func TestRunMatch(t *testing.T) {
	TournamentTest(t, func(t *testutil.T, tm *Tournament) {
		p1 := Submission{"p1", "c1"}
		p2 := Submission{"p2", "c2"}
		t.CheckError(tm.CreateMap("MapFoo", "SourceFoo", CategoryTest))
		if id, result, err := tm.RunMatch(CategoryTest, "MapFoo", p1, p2, SystemClock()); err != nil {
			t.ErrorNow(err)
		} else if result != "WinA" {
			t.ErrorNowf("Expected WinA not %v\n", result)
		} else if result2, err := tm.GetMatchResult(id); err != nil {
			t.ErrorNow(err)
		} else if result != result2 {
			t.ErrorNowf("Expected %v not %v\n", result, result2)
		} else if matches, err := tm.ListMatches(CategoryTest); err != nil {
			t.ErrorNow(err)
		} else if len(matches) != 1 {
			t.ErrorNowf("Expected 1 match not %v\n", len(matches))
		} else if matches[0].Result != result {
			t.ErrorNowf("Expected %v not %v\n", result, matches[0].Result)
		}
	})
}