This repository has been archived on 2022-08-18. You can view files and clone it, but cannot push or open issues or pull requests.
rageshake/vendor/src/github.com/google/go-github/github/admin_test.go

82 lines
2.1 KiB
Go

// Copyright 2016 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestAdminService_UpdateUserLDAPMapping(t *testing.T) {
setup()
defer teardown()
input := &UserLDAPMapping{
LDAPDN: String("uid=asdf,ou=users,dc=github,dc=com"),
}
mux.HandleFunc("/admin/ldap/users/u/mapping", func(w http.ResponseWriter, r *http.Request) {
v := new(UserLDAPMapping)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1,"ldap_dn":"uid=asdf,ou=users,dc=github,dc=com"}`)
})
mapping, _, err := client.Admin.UpdateUserLDAPMapping(context.Background(), "u", input)
if err != nil {
t.Errorf("Admin.UpdateUserLDAPMapping returned error: %v", err)
}
want := &UserLDAPMapping{
ID: Int(1),
LDAPDN: String("uid=asdf,ou=users,dc=github,dc=com"),
}
if !reflect.DeepEqual(mapping, want) {
t.Errorf("Admin.UpdateUserLDAPMapping returned %+v, want %+v", mapping, want)
}
}
func TestAdminService_UpdateTeamLDAPMapping(t *testing.T) {
setup()
defer teardown()
input := &TeamLDAPMapping{
LDAPDN: String("cn=Enterprise Ops,ou=teams,dc=github,dc=com"),
}
mux.HandleFunc("/admin/ldap/teams/1/mapping", func(w http.ResponseWriter, r *http.Request) {
v := new(TeamLDAPMapping)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1,"ldap_dn":"cn=Enterprise Ops,ou=teams,dc=github,dc=com"}`)
})
mapping, _, err := client.Admin.UpdateTeamLDAPMapping(context.Background(), 1, input)
if err != nil {
t.Errorf("Admin.UpdateTeamLDAPMapping returned error: %v", err)
}
want := &TeamLDAPMapping{
ID: Int(1),
LDAPDN: String("cn=Enterprise Ops,ou=teams,dc=github,dc=com"),
}
if !reflect.DeepEqual(mapping, want) {
t.Errorf("Admin.UpdateTeamLDAPMapping returned %+v, want %+v", mapping, want)
}
}