|
| 1 | +// Copyright 2025 The go-github AUTHORS. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style |
| 4 | +// license that can be found in the LICENSE file. |
| 5 | + |
| 6 | +package github |
| 7 | + |
| 8 | +import ( |
| 9 | + "encoding/json" |
| 10 | + "errors" |
| 11 | + "net/http" |
| 12 | + "testing" |
| 13 | +) |
| 14 | + |
| 15 | +func TestCredentialsService_Revoke(t *testing.T) { |
| 16 | + t.Parallel() |
| 17 | + client, mux, _ := setup(t) |
| 18 | + |
| 19 | + creds := []string{ |
| 20 | + "ghp_1234567890abcdef1234567890abcdef12345678", |
| 21 | + "ghp_abcdef1234567890abcdef1234567890abcdef12", |
| 22 | + } |
| 23 | + expectedBodyBytes, _ := json.Marshal(map[string][]string{"credentials": creds}) |
| 24 | + expectedBody := string(expectedBodyBytes) + "\n" |
| 25 | + |
| 26 | + mux.HandleFunc("/credentials/revoke", func(w http.ResponseWriter, r *http.Request) { |
| 27 | + testMethod(t, r, "POST") |
| 28 | + testBody(t, r, expectedBody) |
| 29 | + w.WriteHeader(http.StatusAccepted) |
| 30 | + }) |
| 31 | + |
| 32 | + ctx := t.Context() |
| 33 | + resp, err := client.Credentials.Revoke(ctx, creds) |
| 34 | + if !errors.As(err, new(*AcceptedError)) { |
| 35 | + t.Errorf("Credentials.Revoke returned error: %v (want AcceptedError)", err) |
| 36 | + } |
| 37 | + if resp == nil { |
| 38 | + t.Fatal("Credentials.Revoke returned nil response") |
| 39 | + } |
| 40 | + if resp.StatusCode != http.StatusAccepted { |
| 41 | + t.Errorf("Credentials.Revoke returned status %v, want %v", resp.StatusCode, http.StatusAccepted) |
| 42 | + } |
| 43 | + |
| 44 | + const methodName = "Revoke" |
| 45 | + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 46 | + return client.Credentials.Revoke(ctx, []string{"a"}) |
| 47 | + }) |
| 48 | +} |
0 commit comments