Skip to content

Commit

Permalink
update all the headers and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenweber committed Jan 28, 2021
1 parent ce543aa commit 98f6978
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opts *R

// TODO: remove custom Accept headers when APIs fully launch.
acceptHeaders := []string{mediaTypeTopicsPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
req.Header.Set("Accept:", strings.Join(acceptHeaders, ", "))

var repos []*Repository
resp, err := s.client.Do(ctx, req, &repos)
Expand Down Expand Up @@ -368,7 +368,7 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo
}

acceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
req.Header.Set("Accept:", strings.Join(acceptHeaders, ", "))
r := new(Repository)
resp, err := s.client.Do(ctx, req, r)
if err != nil {
Expand Down Expand Up @@ -427,7 +427,7 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep
mediaTypeRepositoryTemplatePreview,
mediaTypeRepositoryVisibilityPreview,
}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
req.Header.Set("Accept:", strings.Join(acceptHeaders, ", "))

repository := new(Repository)
resp, err := s.client.Do(ctx, req, repository)
Expand Down Expand Up @@ -490,7 +490,7 @@ func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repo
}

acceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
req.Header.Set("Accept:", strings.Join(acceptHeaders, ", "))
r := new(Repository)
resp, err := s.client.Do(ctx, req, r)
if err != nil {
Expand Down Expand Up @@ -1308,7 +1308,7 @@ func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo str
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeTopicsPreview)
req.Header.Set("Accept:", mediaTypeTopicsPreview)

topics := new(repositoryTopics)
resp, err := s.client.Do(ctx, req, topics)
Expand Down Expand Up @@ -1336,7 +1336,7 @@ func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeTopicsPreview)
req.Header.Set("Accept:", mediaTypeTopicsPreview)

t = new(repositoryTopics)
resp, err := s.client.Do(ctx, req, t)
Expand Down
24 changes: 12 additions & 12 deletions github/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) {
wantAcceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
testHeader(t, r, "Accept:", strings.Join(wantAcceptHeaders, ", "))
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})

Expand Down Expand Up @@ -59,7 +59,7 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
wantAcceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
testHeader(t, r, "Accept:", strings.Join(wantAcceptHeaders, ", "))
testFormValues(t, r, values{
"visibility": "public",
"affiliation": "owner,collaborator",
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestRepositoriesService_List_specifiedUser_type(t *testing.T) {
wantAcceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
testHeader(t, r, "Accept:", strings.Join(wantAcceptHeaders, ", "))
testFormValues(t, r, values{
"type": "owner",
})
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestRepositoriesService_Create_user(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
testHeader(t, r, "Accept:", strings.Join(wantAcceptHeaders, ", "))
want := &createRepoRequest{Name: String("n")}
if !reflect.DeepEqual(v, want) {
t.Errorf("Request body = %+v, want %+v", v, want)
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestRepositoriesService_Create_org(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
testHeader(t, r, "Accept:", strings.Join(wantAcceptHeaders, ", "))
want := &createRepoRequest{Name: String("n")}
if !reflect.DeepEqual(v, want) {
t.Errorf("Request body = %+v, want %+v", v, want)
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestRepositoriesService_Get(t *testing.T) {
wantAcceptHeaders := []string{mediaTypeCodesOfConductPreview, mediaTypeTopicsPreview, mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
testHeader(t, r, "Accept:", strings.Join(wantAcceptHeaders, ", "))
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`)
})

Expand Down Expand Up @@ -476,7 +476,7 @@ func TestRepositoriesService_Edit(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "PATCH")
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
testHeader(t, r, "Accept:", strings.Join(wantAcceptHeaders, ", "))
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
Expand Down Expand Up @@ -1893,7 +1893,7 @@ func TestRepositoriesService_ListAllTopics(t *testing.T) {

mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeTopicsPreview)
testHeader(t, r, "Accept:", mediaTypeTopicsPreview)
fmt.Fprint(w, `{"names":["go", "go-github", "github"]}`)
})

Expand Down Expand Up @@ -1929,7 +1929,7 @@ func TestRepositoriesService_ListAllTopics_emptyTopics(t *testing.T) {

mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeTopicsPreview)
testHeader(t, r, "Accept:", mediaTypeTopicsPreview)
fmt.Fprint(w, `{"names":[]}`)
})

Expand All @@ -1951,7 +1951,7 @@ func TestRepositoriesService_ReplaceAllTopics(t *testing.T) {

mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Accept", mediaTypeTopicsPreview)
testHeader(t, r, "Accept:", mediaTypeTopicsPreview)
fmt.Fprint(w, `{"names":["go", "go-github", "github"]}`)
})

Expand Down Expand Up @@ -1987,7 +1987,7 @@ func TestRepositoriesService_ReplaceAllTopics_nilSlice(t *testing.T) {

mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Accept", mediaTypeTopicsPreview)
testHeader(t, r, "Accept:", mediaTypeTopicsPreview)
testBody(t, r, `{"names":[]}`+"\n")
fmt.Fprint(w, `{"names":[]}`)
})
Expand All @@ -2010,7 +2010,7 @@ func TestRepositoriesService_ReplaceAllTopics_emptySlice(t *testing.T) {

mux.HandleFunc("/repos/o/r/topics", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Accept", mediaTypeTopicsPreview)
testHeader(t, r, "Accept:", mediaTypeTopicsPreview)
testBody(t, r, `{"names":[]}`+"\n")
fmt.Fprint(w, `{"names":[]}`)
})
Expand Down

0 comments on commit 98f6978

Please sign in to comment.