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

Function TestUsers_Keys

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

Source from the content-addressed store, hash-verified

155}
156
157func TestUsers_Keys(t *testing.T) {
158 keys, _, err := client.Users.ListKeys(t.Context(), "willnorris", nil)
159 if err != nil {
160 t.Fatalf("Users.ListKeys('willnorris') returned error: %v", err)
161 }
162
163 if len(keys) == 0 {
164 t.Error("Users.ListKeys('willnorris') returned no keys")
165 }
166
167 // the rest of the tests requires auth
168 skipIfMissingAuth(t)
169
170 // TODO: make this integration test work for any authenticated user.
171 keys, _, err = client.Users.ListKeys(t.Context(), "", nil)
172 if err != nil {
173 t.Fatalf("Users.ListKeys('') returned error: %v", err)
174 }
175
176 // ssh public key for testing (fingerprint: a7:22:ad:8c:36:9f:68:65:eb:ae:a1:e4:59:73:c1:76)
177 key := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCy/RIqaMFj2wjkOEjx9EAU0ReLAIhodga82/feo5nnT9UUkHLbL9xrIavfdLHx28lD3xYgPfAoSicUMaAeNwuQhmuerr2c2LFGxzrdXP8pVsQ+Ol7y7OdmFPfe0KrzoZaLJs9aSiZ4VKyY4z5Se/k2UgcJTdgQVlLfw/P96aqCx8yUu94BiWqkDqYEvgWKRNHrTiIo1EXeVBCCcfgNZe1suFfNJUJSUU2T3EG2bpwBbSOCjE3FyH8+Lz3K3BOGzm3df8E7Regj9j4YIcD8cWJYO86jLJoGgQ0L5MSOq+ishNaHQXech22Ix03D1lVMjCvDT7S/C94Z1LzhI2lhvyff"
178 for _, k := range keys {
179 if k.Key != nil && *k.Key == key {
180 t.Fatal("Test key already exists for user. Please manually remove it first.")
181 }
182 }
183
184 // Add new key
185 _, _, err = client.Users.CreateKey(t.Context(), &github.Key{
186 Title: github.Ptr("go-github test key"),
187 Key: &key,
188 })
189 if err != nil {
190 t.Fatalf("Users.CreateKey() returned error: %v", err)
191 }
192
193 // List keys again and verify new key is present
194 keys, _, err = client.Users.ListKeys(t.Context(), "", nil)
195 if err != nil {
196 t.Fatalf("Users.ListKeys('') returned error: %v", err)
197 }
198
199 var id int64
200 for _, k := range keys {
201 if k.Key != nil && *k.Key == key {
202 id = *k.ID
203 break
204 }
205 }
206
207 if id == 0 {
208 t.Fatal("Users.ListKeys('') does not contain added test key")
209 }
210
211 // Verify that fetching individual key works
212 k, _, err := client.Users.GetKey(t.Context(), id)
213 if err != nil {
214 t.Fatalf("Users.GetKey(%q) returned error: %v", id, err)

Callers

nothing calls this directly

Calls 7

PtrFunction · 0.92
skipIfMissingAuthFunction · 0.85
ListKeysMethod · 0.45
ErrorMethod · 0.45
CreateKeyMethod · 0.45
GetKeyMethod · 0.45
DeleteKeyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…