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

Function TestRepositoriesService_GetArchiveLink

github/repos_contents_test.go:955–1010  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

953}
954
955func TestRepositoriesService_GetArchiveLink(t *testing.T) {
956 t.Parallel()
957 tcs := []struct {
958 name string
959 respectRateLimits bool
960 }{
961 {
962 name: "withoutRateLimits",
963 respectRateLimits: false,
964 },
965 {
966 name: "withRateLimits",
967 respectRateLimits: true,
968 },
969 }
970
971 for _, tc := range tcs {
972 t.Run(tc.name, func(t *testing.T) {
973 t.Parallel()
974 client, mux, _ := setup(t)
975 client.rateLimitRedirectionalEndpoints = tc.respectRateLimits
976
977 mux.HandleFunc("/repos/o/r/tarball/yo", func(w http.ResponseWriter, r *http.Request) {
978 testMethod(t, r, "GET")
979 http.Redirect(w, r, "https://github.com/a", http.StatusFound)
980 })
981 ctx := t.Context()
982 url, resp, err := client.Repositories.GetArchiveLink(ctx, "o", "r", Tarball, &RepositoryContentGetOptions{Ref: "yo"}, 1)
983 if err != nil {
984 t.Errorf("Repositories.GetArchiveLink returned error: %v", err)
985 }
986 if resp.StatusCode != http.StatusFound {
987 t.Errorf("Repositories.GetArchiveLink returned status: %v, want %v", resp.StatusCode, http.StatusFound)
988 }
989 want := "https://github.com/a"
990 if url.String() != want {
991 t.Errorf("Repositories.GetArchiveLink returned %+v, want %+v", url, want)
992 }
993
994 const methodName = "GetArchiveLink"
995 testBadOptions(t, methodName, func() (err error) {
996 _, _, err = client.Repositories.GetArchiveLink(ctx, "\n", "\n", Tarball, &RepositoryContentGetOptions{}, 1)
997 return err
998 })
999
1000 // Add custom round tripper
1001 client.client.Transport = roundTripperFunc(func(*http.Request) (*http.Response, error) {
1002 return nil, errors.New("failed to get archive link")
1003 })
1004 testBadOptions(t, methodName, func() (err error) {
1005 _, _, err = client.Repositories.GetArchiveLink(ctx, "o", "r", Tarball, &RepositoryContentGetOptions{}, 1)
1006 return err
1007 })
1008 })
1009 }
1010}
1011
1012func TestRepositoriesService_GetArchiveLink_StatusMovedPermanently_dontFollowRedirects(t *testing.T) {

Callers

nothing calls this directly

Calls 7

testMethodFunction · 0.85
testBadOptionsFunction · 0.85
roundTripperFuncFuncType · 0.85
GetArchiveLinkMethod · 0.80
setupFunction · 0.70
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…