1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
package gitlab
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestListGroupSSHCertificates(t *testing.T) {
mux, client := setup(t)
path := "/api/v4/groups/1/ssh_certificates"
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
mustWriteHTTPResponse(t, w, "testdata/list_group_ssh_certificates.json")
})
certificates, _, err := client.GroupSSHCertificates.ListGroupSSHCertificates(1)
require.NoError(t, err)
want := []*GroupSSHCertificate{
{
ID: 1876,
Title: "SSH Certificate",
Key: "ssh-rsa FAKE-KEY example@gitlab.com",
CreatedAt: Ptr(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
},
}
require.Equal(t, want, certificates)
}
func TestCreateGroupSSHCertificate(t *testing.T) {
mux, client := setup(t)
path := "/api/v4/groups/84/ssh_certificates"
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
mustWriteHTTPResponse(t, w, "testdata/create_group_ssh_certificates.json")
})
cert, _, err := client.GroupSSHCertificates.CreateGroupSSHCertificate(84, &CreateGroupSSHCertificateOptions{
Key: Ptr("ssh-rsa FAKE-KEY example@gitlab.com"),
Title: Ptr("SSH Certificate"),
})
require.NoError(t, err)
want := &GroupSSHCertificate{
ID: 1876,
Title: "SSH Certificate",
Key: "ssh-rsa FAKE-KEY example@gitlab.com",
CreatedAt: Ptr(time.Date(2022, time.March, 20, 20, 42, 40, 221000000, time.UTC)),
}
require.Equal(t, want, cert)
}
func TestDeleteGroupSSHCertificate(t *testing.T) {
mux, client := setup(t)
path := "/api/v4/groups/1/ssh_certificates/1876"
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
})
_, err := client.GroupSSHCertificates.DeleteGroupSSHCertificate(1, 1876)
require.NoError(t, err)
}
|