Esempio n. 1
0
func TestCreateUser(t *testing.T) {
	TournamentTest(t, func(t *testutil.T, tm *Tournament) {
		if isUser, err := tm.UserExists("NameFoo"); err != nil {
			t.ErrorNow(err)
		} else if isUser {
			t.FailNow()
		}
		if users, err := tm.ListUsers(); err != nil {
			t.ErrorNow(err)
		} else if len(users) != 0 {
			t.FailNow()
		}
		if _, err := tm.CreateUser("NameFoo", "PublicKey", CategoryTest); err != nil {
			t.ErrorNow(err)
		}
		if isUser, err := tm.UserExists("NameFoo"); err != nil {
			t.ErrorNow(err)
		} else if !isUser {
			t.FailNow()
		} else if users, err := tm.ListUsers(); err != nil {
			t.ErrorNow(err)
		} else if len(users) != 1 {
			t.FailNow()
		} else if users[0] != "NameFoo" {
			t.FailNow()
		}
	})
}
Esempio n. 2
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()
		}
	})
}
Esempio n. 3
0
func TestRegisterJSON(t *testing.T) {
	ServerTest(t, func(t *testutil.T, server *ServerState) {
		r := sendJSONPost(t, server, "/register", map[string]string{"name": "NameFoo", "public_key": SamplePublicKey, "category": string(tournament.CategoryTest)})
		if Json(t, r).Key("data").Key("name").String() != "NameFoo" {
			t.FailNow()
		}
		if Json(t, r).Key("data").Key("public_key").String() != SamplePublicKey {
			t.FailNow()
		}
	})
}
Esempio n. 4
0
func TestRegisterQuery(t *testing.T) {
	ServerTest(t, func(t *testutil.T, server *ServerState) {
		r := sendPost(t, server, "/register?name=NameFoo&category="+string(tournament.CategoryTest)+"&public_key="+url.QueryEscape(SamplePublicKey), nil)
		if Json(t, r).Key("data").Key("name").String() != "NameFoo" {
			t.FailNow()
		}
		if Json(t, r).Key("data").Key("public_key").String() != SamplePublicKey {
			t.FailNow()
		}
	})
}
Esempio n. 5
0
func TestVersion(t *testing.T) {
	ServerTest(t, func(t *testutil.T, server *ServerState) {
		r := sendGet(t, server, "/version")
		if r["schemaVersion"] == "" {
			t.FailNow()
		}
		if r["sourceVersion"] == "" {
			t.FailNow()
		}
	})
}
Esempio n. 6
0
func TestShutdown(t *testing.T) {
	ServerTest(t, func(t *testutil.T, server *ServerState) {
		go server.Serve()
		//Race condition of server not starting
		time.Sleep(time.Millisecond)
		r := sendPost(t, server, "/shutdown", nil)
		if r["shutdown"] == "" {
			t.FailNow()
		}
		sendPostExpectStatus(t, server, http.StatusInternalServerError, "/shutdown", nil)
	})
}
Esempio n. 7
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)
		}
	})
}
Esempio n. 8
0
func TestCreateMatch(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.FailNow()
		} else if result, err := tm.GetMatchResult(id); err != nil {
			t.ErrorNow(err)
		} else if result != MatchResultInProgress {
			t.FailNow()
		}
	})
}
Esempio n. 9
0
func TestMaps(t *testing.T) {
	ServerTest(t, func(t *testutil.T, server *ServerState) {
		if r := sendGet(t, server, "/maps?category="+string(tournament.CategoryTest)); Json(t, r).Key("data").Key("maps").Len() > 0 {
			t.Error("expected no maps", r)
			t.FailNow()
		}
		sendJSONPost(t, server, "/map/create", map[string]string{"name": "NameFoo", "source": "SourceFoo", "category": string(tournament.CategoryTest)})
		if r := sendGet(t, server, "/maps?category="+string(tournament.CategoryTest)); !compareStrings(Json(t, r).Key("data").Key("maps").Array(), []string{"NameFoo"}) {
			t.Error("expected single player NameFoo", r)
			t.FailNow()
		}
		sendJSONPost(t, server, "/map/create", map[string]string{"name": "NameBar", "source": "SourceBar", "category": string(tournament.CategoryTest)})
		if r := sendGet(t, server, "/maps?category="+string(tournament.CategoryTest)); !compareStringsUnordered(Json(t, r).Key("data").Key("maps").Array(), []string{"NameFoo", "NameBar"}) {
			t.ErrorNow("expected two maps NameFoo, NameBar", r)
		}
	})
}
Esempio n. 10
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()
			}
		}

	})
}
Esempio n. 11
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()
			}
		}

	})
}
Esempio n. 12
0
func TestSimilarPublicKeys(t *testing.T) {
	ServerTest(t, func(t *testutil.T, server *ServerState) {
		r := sendPost(t, server, "/register", strings.NewReader("name=NameFoo&category="+string(tournament.CategoryTest)+"&public_key="+url.QueryEscape(SamplePublicKey)))
		if Json(t, r).Key("data").Key("name").String() != "NameFoo" {
			t.FailNow()
		}
		if Json(t, r).Key("data").Key("public_key").String() != SamplePublicKey {
			t.FailNow()
		}
		r = sendPost(t, server, "/register", strings.NewReader("name=NameBar&category="+string(tournament.CategoryTest)+"&public_key="+url.QueryEscape(SimilarPublicKey)))
		if Json(t, r).Key("data").Key("name").String() != "NameBar" {
			t.FailNow()
		}
		if Json(t, r).Key("data").Key("public_key").String() != SimilarPublicKey {
			t.FailNow()
		}
	})
}