Repository: google/go-github
File: github/repos_releases_test.go (Go)

Code before:
		return resp, err
	})
}

func TestRepositoriesService_CreateRelease(t *testing.T) {
	t.Parallel()
	client, mux, _ := setup(t)

	input := &RepositoryRelease{
		Name:                   Ptr("v1.0"),
		DiscussionCategoryName: Ptr("General"),
		GenerateReleaseNotes:   Ptr(true),
		// Fields to be removed:
		ID:          Ptr(int64(2)),
		CreatedAt:   &Timestamp{referenceTime},
		PublishedAt: &Timestamp{referenceTime},
		URL:         Ptr("http://url/"),
		HTMLURL:     Ptr("http://htmlurl/"),
		AssetsURL:   Ptr("http://assetsurl/"),
		Assets:      []*ReleaseAsset{{ID: Ptr(int64(5))}},
		UploadURL:   Ptr("http://uploadurl/"),
		ZipballURL:  Ptr("http://zipballurl/"),
		TarballURL:  Ptr("http://tarballurl/"),
		Author:      &User{Name: Ptr("octocat")},
		NodeID:      Ptr("nodeid"),
	}

	mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) {
		v := new(repositoryReleaseRequest)
		assertNilError(t, json.NewDecoder(r.Body).Decode(v))

		testMethod(t, r, "POST")
		want := &repositoryReleaseRequest{
			Name:                   Ptr("v1.0"),
			DiscussionCategoryName: Ptr("General"),
			GenerateReleaseNotes:   Ptr(true),
		}
		if !cmp.Equal(v, want) {
			t.Errorf("Request body = %+v, want %+v", v, want)
		}
		fmt.Fprint(w, `{"id":1}`)
	})

	ctx := context.Background()
	release, _, err := client.Repositories.CreateRelease(ctx, "o", "r", input)
	if err != nil {
		t.Errorf("Repositories.CreateRelease returned error: %v", err)
	}

	want := &RepositoryRelease{ID: Ptr(int64(1))}
	if !cmp.Equal(release, want) {

Review comment (suggestion):
We can't set `Immutable` in `CreateRelease`, see https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release--parameters

Code after:
		return resp, err
	})
}

func TestRepositoriesService_CreateRelease(t *testing.T) {
	t.Parallel()
	client, mux, _ := setup(t)

	input := &RepositoryRelease{
		Name:                   Ptr("v1.0"),
		DiscussionCategoryName: Ptr("General"),
		GenerateReleaseNotes:   Ptr(true),
		// Fields to be removed:
		ID:          Ptr(int64(2)),
		CreatedAt:   &Timestamp{referenceTime},
		PublishedAt: &Timestamp{referenceTime},
		URL:         Ptr("http://url/"),
		HTMLURL:     Ptr("http://htmlurl/"),
		AssetsURL:   Ptr("http://assetsurl/"),
		Assets:      []*ReleaseAsset{{ID: Ptr(int64(5))}},
		UploadURL:   Ptr("http://uploadurl/"),
		ZipballURL:  Ptr("http://zipballurl/"),
		TarballURL:  Ptr("http://tarballurl/"),
		Author:      &User{Name: Ptr("octocat")},
		NodeID:      Ptr("nodeid"),
		Immutable:   Ptr(false),
	}

	mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) {
		v := new(repositoryReleaseRequest)
		assertNilError(t, json.NewDecoder(r.Body).Decode(v))

		testMethod(t, r, "POST")
		want := &repositoryReleaseRequest{
			Name:                   Ptr("v1.0"),
			DiscussionCategoryName: Ptr("General"),
			GenerateReleaseNotes:   Ptr(true),
		}
		if !cmp.Equal(v, want) {
			t.Errorf("Request body = %+v, want %+v", v, want)
		}
		fmt.Fprint(w, `{"id":1}`)
	})

	ctx := context.Background()
	release, _, err := client.Repositories.CreateRelease(ctx, "o", "r", input)
	if err != nil {
		t.Errorf("Repositories.CreateRelease returned error: %v", err)
	}

	want := &RepositoryRelease{ID: Ptr(int64(1))}