Пример #1
0
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
func TestCreateExistingMapError(t *testing.T) {
	TournamentTest(t, func(t *testutil.T, tm *Tournament) {
		t.CheckError(tm.CreateMap("NameFoo", "SourceFoo", CategoryTest))
		if err := tm.CreateMap("NameFoo", "SourceFoo", CategoryTest); err == nil {
			t.ErrorNow("expected error")
		}
	})
}
Пример #3
0
func TestInitExitingLocalRepoFails(t *testing.T) {
	LocalDirHostTest(t, func(t *testutil.T, local *LocalDirHost) {
		t.CheckError(local.InitRepository("foo", nil, nil))
		if err := local.InitRepository("foo", nil, nil); err == nil {
			t.FailNow()
		}
	})
}
Пример #4
0
func TestDeleteLocalRepo(t *testing.T) {
	LocalDirHostTest(t, func(t *testutil.T, local *LocalDirHost) {
		t.CheckError(local.InitRepository("foo", nil, nil))
		t.CheckError(local.DeleteRepository("foo"))
		repoURL := local.RepositoryURL("foo")
		if _, err := os.Stat(repoURL); err == nil {
			t.FailNow()
		} else if !os.IsNotExist(err) {
			t.ErrorNow(err)
		}
	})
}
Пример #5
0
func TestCheckoutRepository(t *testing.T) {
	LocalDirHostTest(t, func(t *testutil.T, host *LocalDirHost) {
		t.CheckError(host.InitRepository("foo", nil, nil))
		repoURL := host.RepositoryURL("foo")
		if repo, err := (TempRemote{}).CheckoutRepository(repoURL); err != nil {
			t.ErrorNow(err)
		} else {
			defer repo.Delete()
			CheckDirectoryContent(t, repo.Dir(), []string{".git"})
		}

	})
}
Пример #6
0
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"})
		}
	})
}
Пример #7
0
func TestSubmitCommit(t *testing.T) {
	TournamentTest(t, func(t *testutil.T, tm *Tournament) {
		if _, err := tm.CreateUser("NameFoo", "PublicKeyFoo", CategoryTest); err != nil {
			t.ErrorNow(err)
		}
		t.CheckError(tm.SubmitCommit("NameFoo", CategoryTest, "abcdef", time.Now()))
		if commits, err := tm.ListCommits("NameFoo", CategoryTest); err != nil {
			t.ErrorNow(err)
		} else if len(commits) != 1 {
			t.ErrorNow(len(commits), "but expected", 1)
		} else if commits[0] != "abcdef" {
			t.ErrorNow(commits[0], "but expected", "abcdef")
		}
	})
}
Пример #8
0
func TestCreateMap(t *testing.T) {
	TournamentTest(t, func(t *testutil.T, tm *Tournament) {
		t.CheckError(tm.CreateMap("MapFoo", "MapString", CategoryTest))
		if maps, err := tm.ListMaps(CategoryTest); err != nil {
			t.ErrorNow(err)
		} else if len(maps) != 1 {
			t.ErrorNow(len(maps), "but expected", 1)
		} else if maps[0] != "MapFoo" {
			t.ErrorNow(maps[0], "but expected", "MapFoo")
		}
		if mapSource, err := tm.GetMapSource("MapFoo", CategoryTest); err != nil {
			t.ErrorNow(err)
		} else if mapSource != "MapString" {
			t.ErrorNow(mapSource, "but expected", "MapString")
		}
	})
}
Пример #9
0
func TestUpdateMatch(t *testing.T) {
	TournamentTest(t, func(t *testutil.T, tm *Tournament) {
		p1 := Submission{"p1", "c1"}
		p2 := Submission{"p2", "c2"}
		if id, err := tm.CreateMatch(CategoryTest, "MapFoo", p1, p2, time.Now()); err != nil {
			t.ErrorNow(err)
		} else {
			t.CheckError(tm.UpdateMatch(CategoryTest, "MapFoo", p1, p2, time.Now(), MatchResultWinA, []byte("LogFoo")))
			if result, err := tm.GetMatchResult(id); err != nil {
				t.ErrorNow(t, err)
			} else if result != MatchResultWinA {
				t.ErrorNow(result, " expected ", MatchResultWinA)
			} else if replay, err := tm.GetMatchReplayRaw(id); err != nil {
				t.ErrorNow(err)
			} else if string(replay) != "LogFoo" {
				t.ErrorNow(replay, " expected LogFoo")
			}
		}
	})
}
Пример #10
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)
		}
	})
}
Пример #11
0
func TestDeleteGitoliteRepo(t *testing.T) {
	GitoliteHostTest(t, func(t *testutil.T, host *GitoliteHost) {
		t.CheckError(createRepo(host, "foo"))
		t.CheckError(host.DeleteRepository("foo"))
		cmd := exec.Command("ssh", "-v", "-v", "-i", host.SSHKey, host.User+"@"+host.InternalHostname, "[[ ! -d repositories/foo.git ]]")
		t.CheckError(cmd.Run())
	})
}
Пример #12
0
func TestCommitFiles(t *testing.T) {
	LocalDirHostTest(t, func(t *testutil.T, host *LocalDirHost) {
		t.CheckError(host.InitRepository("foo", nil, nil))
		repoURL := host.RepositoryURL("foo")
		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"))
			if log, err := repo.Log(); err != nil {
				t.ErrorNow(err)
			} else if len(log) != 1 {
				t.FailNow()
			}
		}

	})
}
Пример #13
0
func TestDeleteFiles(t *testing.T) {
	LocalDirHostTest(t, func(t *testutil.T, host *LocalDirHost) {
		t.CheckError(host.InitRepository("foo", nil, nil))
		repoURL := host.RepositoryURL("foo")
		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(os.Mkdir(filepath.Join(repo.Dir(), "bar"), os.ModeDir|0755))
			t.CheckError(ioutil.WriteFile(filepath.Join(repo.Dir(), "bar", "moo.txt"), []byte("world"), os.ModePerm))
			t.CheckError(repo.AddFiles([]string{"foo.txt", "bar"}))
			t.CheckError(repo.CommitFiles(nil, "commit message"))
			if log, err := repo.Log(); err != nil {
				t.ErrorNow(err)
			} else if len(log) != 1 {
				t.FailNow()
			}

			CheckDirectoryContent(t, repo.Dir(), []string{".git", "foo.txt", "bar"})
			CheckDirectoryContent(t, filepath.Join(repo.Dir(), "bar"), []string{"moo.txt"})
			//Delete
			t.CheckError(repo.DeleteFiles([]string{"foo.txt"}))
			t.CheckError(repo.DeleteFiles([]string{"bar"}))
			if err := repo.DeleteFiles([]string{"other"}); err == nil {
				t.ErrorNow("Expected error")
			}
			CheckDirectoryContent(t, repo.Dir(), []string{".git"})
			t.CheckError(repo.CommitFiles([]string{}, "commit message"))
			if log, err := repo.Log(); err != nil {
				t.ErrorNow(err)
			} else if len(log) != 2 {
				t.FailNow()
			}
		}

	})
}