MCPcopy Index your code
hub / github.com/google/go-github / TestUsers_Emails

Function TestUsers_Emails

test/integration/users_test.go:93–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestUsers_Emails(t *testing.T) {
94 skipIfMissingAuth(t)
95
96 emails, _, err := client.Users.ListEmails(t.Context(), nil)
97 if err != nil {
98 t.Fatalf("Users.ListEmails() returned error: %v", err)
99 }
100
101 // create random address not currently in user's emails
102 var email string
103EmailLoop:
104 for {
105 email = fmt.Sprintf("test-%v@example.com", rand.Int())
106 for _, e := range emails {
107 if e.Email != nil && *e.Email == email {
108 continue EmailLoop
109 }
110 }
111 break
112 }
113
114 // Add new address
115 _, _, err = client.Users.AddEmails(t.Context(), []string{email})
116 if err != nil {
117 t.Fatalf("Users.AddEmails() returned error: %v", err)
118 }
119
120 // List emails again and verify new email is present
121 emails, _, err = client.Users.ListEmails(t.Context(), nil)
122 if err != nil {
123 t.Fatalf("Users.ListEmails() returned error: %v", err)
124 }
125
126 var found bool
127 for _, e := range emails {
128 if e.Email != nil && *e.Email == email {
129 found = true
130 break
131 }
132 }
133
134 if !found {
135 t.Fatalf("Users.ListEmails() does not contain new address: %v", email)
136 }
137
138 // Remove new address
139 _, err = client.Users.DeleteEmails(t.Context(), []string{email})
140 if err != nil {
141 t.Fatalf("Users.DeleteEmails() returned error: %v", err)
142 }
143
144 // List emails again and verify new email was removed
145 emails, _, err = client.Users.ListEmails(t.Context(), nil)
146 if err != nil {
147 t.Fatalf("Users.ListEmails() returned error: %v", err)
148 }
149
150 for _, e := range emails {

Callers

nothing calls this directly

Calls 4

skipIfMissingAuthFunction · 0.85
ListEmailsMethod · 0.80
AddEmailsMethod · 0.80
DeleteEmailsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…