github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/database/testing/teams_test.go (about) 1 package database 2 3 import ( 4 "testing" 5 6 "github.com/drone/drone/pkg/database" 7 ) 8 9 // TODO unit test to verify unique constraint on Member.UserID and Member.TeamID 10 11 // TestGetTeam tests the ability to retrieve a Team 12 // from the database by Unique ID. 13 func TestGetTeam(t *testing.T) { 14 Setup() 15 defer Teardown() 16 17 team, err := database.GetTeam(1) 18 if err != nil { 19 t.Error(err) 20 } 21 22 if team.ID != 1 { 23 t.Errorf("Exepected ID %d, got %d", 1, team.ID) 24 } 25 26 if team.Name != "Drone" { 27 t.Errorf("Exepected Name %s, got %s", "Drone", team.Name) 28 } 29 30 if team.Slug != "drone" { 31 t.Errorf("Exepected Slug %s, got %s", "drone", team.Slug) 32 } 33 34 if team.Email != "support@drone.io" { 35 t.Errorf("Exepected Email %s, got %s", "brad@drone.io", team.Email) 36 } 37 38 if team.Gravatar != "8c58a0be77ee441bb8f8595b7f1b4e87" { 39 t.Errorf("Exepected Gravatar %s, got %s", "8c58a0be77ee441bb8f8595b7f1b4e87", team.Gravatar) 40 } 41 } 42 43 // TestGetTeamName tests the ability to retrieve a Team 44 // from the database by Unique Team Name (aka Slug). 45 func TestGetTeamSlug(t *testing.T) { 46 Setup() 47 defer Teardown() 48 49 team, err := database.GetTeamSlug("drone") 50 if err != nil { 51 t.Error(err) 52 } 53 54 if team.ID != 1 { 55 t.Errorf("Exepected ID %d, got %d", 1, team.ID) 56 } 57 58 if team.Name != "Drone" { 59 t.Errorf("Exepected Name %s, got %s", "Drone", team.Name) 60 } 61 62 if team.Slug != "drone" { 63 t.Errorf("Exepected Slug %s, got %s", "drone", team.Slug) 64 } 65 66 if team.Email != "support@drone.io" { 67 t.Errorf("Exepected Email %s, got %s", "brad@drone.io", team.Email) 68 } 69 70 if team.Gravatar != "8c58a0be77ee441bb8f8595b7f1b4e87" { 71 t.Errorf("Exepected Gravatar %s, got %s", "8c58a0be77ee441bb8f8595b7f1b4e87", team.Gravatar) 72 } 73 } 74 75 // TestUpdateTeam tests the ability to updatee an 76 // existing Team in the database. 77 func TestUpdateTeam(t *testing.T) { 78 Setup() 79 defer Teardown() 80 81 // get the user we plan to update 82 team, err := database.GetTeam(1) 83 if err != nil { 84 t.Error(err) 85 } 86 87 // update fields 88 team.Email = "brad@drone.io" 89 team.Gravatar = "61024896f291303615bcd4f7a0dcfb74" 90 91 // update the database 92 if err := database.SaveTeam(team); err != nil { 93 t.Error(err) 94 } 95 96 // get the updated team 97 updatedTeam, err := database.GetTeam(1) 98 if err != nil { 99 t.Error(err) 100 } 101 102 // verify the updated fields 103 if team.Email != updatedTeam.Email { 104 t.Errorf("Exepected Email %s, got %s", team.Email, updatedTeam.Email) 105 } 106 107 if team.Gravatar != updatedTeam.Gravatar { 108 t.Errorf("Exepected Gravatar %s, got %s", team.Gravatar, updatedTeam.Gravatar) 109 } 110 } 111 112 // Test the ability to delete a Team. 113 func TestDeleteTeam(t *testing.T) { 114 Setup() 115 defer Teardown() 116 117 // get the team we plan to update 118 if err := database.DeleteTeam(1); err != nil { 119 t.Error(err) 120 } 121 122 // now try to get the team from the database 123 _, err := database.GetTeam(1) 124 if err == nil { 125 t.Fail() 126 } 127 } 128 129 // Test the ability to get a list of Teams 130 // to which a User belongs. 131 func TestListTeam(t *testing.T) { 132 Setup() 133 defer Teardown() 134 135 teams, err := database.ListTeams(1) 136 if err != nil { 137 t.Error(err) 138 } 139 140 // verify team count 141 if len(teams) != 3 { 142 t.Errorf("Exepected %d teams in database, got %d", 3, len(teams)) 143 return 144 } 145 146 // get the first user in the list and verify 147 // fields are being populated correctly 148 team := teams[0] 149 150 if team.ID != 1 { 151 t.Errorf("Exepected ID %d, got %d", 1, team.ID) 152 } 153 154 if team.Name != "Drone" { 155 t.Errorf("Exepected Name %s, got %s", "Drone", team.Name) 156 } 157 158 if team.Slug != "drone" { 159 t.Errorf("Exepected Slug %s, got %s", "drone", team.Slug) 160 } 161 162 if team.Email != "support@drone.io" { 163 t.Errorf("Exepected Email %s, got %s", "brad@drone.io", team.Email) 164 } 165 166 if team.Gravatar != "8c58a0be77ee441bb8f8595b7f1b4e87" { 167 t.Errorf("Exepected Gravatar %s, got %s", "8c58a0be77ee441bb8f8595b7f1b4e87", team.Gravatar) 168 } 169 }