feat: teai role
This commit is contained in:
@@ -288,6 +288,91 @@ func TestErrorPropagation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleWorker(t *testing.T) {
|
||||
s, _ := newTestScanner()
|
||||
got, err := s.Role()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != RoleWorker {
|
||||
t.Errorf("Agents 團隊成員應為 worker,得到 %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleSupervisor(t *testing.T) {
|
||||
s, fc := newTestScanner()
|
||||
fc.teams["alterminal"] = []Team{
|
||||
{ID: 1, Name: "Agents"},
|
||||
{ID: 2, Name: "Supervisor"},
|
||||
}
|
||||
fc.teamMembers[2] = []string{"alex"}
|
||||
got, err := s.Role()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != RoleSupervisor {
|
||||
t.Errorf("Supervisor 團隊成員應為 supervisor,得到 %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleSupervisorTakesPrecedence(t *testing.T) {
|
||||
s, fc := newTestScanner()
|
||||
// alex 同時在 Agents(newTestScanner 預設)與 Supervisor。
|
||||
fc.teams["alterminal"] = []Team{
|
||||
{ID: 1, Name: "Agents"},
|
||||
{ID: 2, Name: "Supervisor"},
|
||||
}
|
||||
fc.teamMembers[2] = []string{"alex", "ceo"}
|
||||
got, err := s.Role()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != RoleSupervisor {
|
||||
t.Errorf("同時屬於兩者時應為 supervisor,得到 %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleNone(t *testing.T) {
|
||||
s, fc := newTestScanner()
|
||||
fc.currentUser = "outsider"
|
||||
got, err := s.Role()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "" {
|
||||
t.Errorf("不在 Supervisor/Agents 應回空字串,得到 %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleWorkerWhenSupervisorExists(t *testing.T) {
|
||||
s, fc := newTestScanner()
|
||||
fc.teams["alterminal"] = []Team{
|
||||
{ID: 1, Name: "Agents"},
|
||||
{ID: 2, Name: "Supervisor"},
|
||||
}
|
||||
fc.teamMembers[2] = []string{"ceo"}
|
||||
got, err := s.Role()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != RoleWorker {
|
||||
t.Errorf("只在 Agents、不在 Supervisor 應為 worker,得到 %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleErrorPropagation(t *testing.T) {
|
||||
s, fc := newTestScanner()
|
||||
fc.failOn["teams"] = errors.New("boom")
|
||||
if _, err := s.Role(); err == nil {
|
||||
t.Errorf("ListTeams 錯誤應向上傳播")
|
||||
}
|
||||
delete(fc.failOn, "teams")
|
||||
fc.failOn["members"] = errors.New("boom")
|
||||
if _, err := s.Role(); err == nil {
|
||||
t.Errorf("ListTeamMembers 錯誤應向上傳播")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPullsDefault(t *testing.T) {
|
||||
s, fc := newTestScanner()
|
||||
fc.pulls["alterminal/teai"] = []PullRequest{
|
||||
|
||||
Reference in New Issue
Block a user