예제 #1
0
파일: teams.go 프로젝트: Jyggafey/drone
// Display a specific Team.
func TeamShow(w http.ResponseWriter, r *http.Request, u *User) error {
	teamParam := r.FormValue(":team")
	team, err := database.GetTeamSlug(teamParam)
	if err != nil {
		return err
	}
	if member, _ := database.IsMember(u.ID, team.ID); !member {
		return fmt.Errorf("Forbidden")
	}
	// list of repositories owned by Team
	repos, err := database.ListReposTeam(team.ID)
	if err != nil {
		return err
	}
	// list all user teams
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}
	// list of recent commits
	commits, err := database.ListCommitsTeam(team.ID)
	if err != nil {
		return err
	}
	data := struct {
		User    *User
		Team    *Team
		Teams   []*Team
		Repos   []*Repo
		Commits []*RepoCommit
	}{u, team, teams, repos, commits}
	return RenderTemplate(w, "team_dashboard.html", &data)
}
예제 #2
0
func TestListReposTeam(t *testing.T) {
	Setup()
	defer Teardown()

	// repos for team_id = 1
	repos, err := database.ListReposTeam(1)
	if err != nil {
		t.Error(err)
	}

	// verify user count
	if len(repos) != 2 {
		t.Errorf("Exepected %d repos in database, got %d", 2, len(repos))
		return
	}

	// get the second repo in the list and verify
	// fields are being populated correctly
	// NOTE: we get the 2nd repo due to sorting
	repo := repos[1]

	if repo.ID != 1 {
		t.Errorf("Exepected ID %d, got %d", 1, repo.ID)
	}

	if repo.Slug != "github.com/drone/drone" {
		t.Errorf("Exepected Slug %s, got %s", "github.com/drone/drone", repo.Slug)
	}

	if repo.Host != "github.com" {
		t.Errorf("Exepected Host %s, got %s", "github.com", repo.Host)
	}

	if repo.Owner != "drone" {
		t.Errorf("Exepected Owner %s, got %s", "drone", repo.Owner)
	}

	if repo.Name != "drone" {
		t.Errorf("Exepected Name %s, got %s", "drone", repo.Name)
	}

	if repo.Private != true {
		t.Errorf("Exepected Private %v, got %v", true, repo.Private)
	}

	if repo.Disabled != false {
		t.Errorf("Exepected Private %v, got %v", false, repo.Disabled)
	}

	if repo.SCM != "git" {
		t.Errorf("Exepected Type %s, got %s", "git", repo.SCM)
	}

	if repo.URL != "[email protected]:drone/drone.git" {
		t.Errorf("Exepected URL %s, got %s", "[email protected]:drone/drone.git", repo.URL)
	}

	if repo.Username != "no username" {
		t.Errorf("Exepected Username %s, got %s", "no username", repo.Username)
	}

	if repo.Password != "no password" {
		t.Errorf("Exepected Password %s, got %s", "no password", repo.Password)
	}

	if repo.PublicKey != pubkey {
		t.Errorf("Exepected PublicKey %s, got %s", "public key", repo.PublicKey)
	}

	if repo.PrivateKey != privkey {
		t.Errorf("Exepected PrivateKey %s, got %s", "private key", repo.PrivateKey)
	}

	if repo.UserID != 1 {
		t.Errorf("Exepected ID %d, got %d", 1, repo.UserID)
	}

	if repo.TeamID != 1 {
		t.Errorf("Exepected ID %d, got %d", 1, repo.TeamID)
	}
}