2024-02-23 00:26:49 +00:00
|
|
|
// Copyright 2024 The Forgjo Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-09-29 15:35:59 +01:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2024-02-23 00:26:49 +00:00
|
|
|
package forgejo
|
2020-09-29 15:35:59 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRelease(t *testing.T) {
|
|
|
|
log.Println("== TestRelease ==")
|
|
|
|
c := newTestClient()
|
|
|
|
|
|
|
|
repo, _ := createTestRepo(t, "ReleaseTests", c)
|
|
|
|
|
|
|
|
// ListReleases
|
|
|
|
rl, _, err := c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, rl, 0)
|
|
|
|
|
|
|
|
// CreateRelease
|
|
|
|
r, _, err := c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
|
|
|
|
TagName: "awesome",
|
2022-04-22 08:52:45 +01:00
|
|
|
Target: "main",
|
2020-09-29 15:35:59 +01:00
|
|
|
Title: "Release 1",
|
|
|
|
Note: "yes it's awesome",
|
|
|
|
IsDraft: true,
|
|
|
|
IsPrerelease: true,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, "awesome", r.TagName)
|
|
|
|
assert.EqualValues(t, true, r.IsPrerelease)
|
|
|
|
assert.EqualValues(t, true, r.IsDraft)
|
|
|
|
assert.EqualValues(t, "Release 1", r.Title)
|
|
|
|
assert.EqualValues(t, fmt.Sprintf("%s/api/v1/repos/%s/releases/%d", c.url, repo.FullName, r.ID), r.URL)
|
2022-04-22 08:52:45 +01:00
|
|
|
assert.EqualValues(t, "main", r.Target)
|
2020-09-29 15:35:59 +01:00
|
|
|
assert.EqualValues(t, "yes it's awesome", r.Note)
|
|
|
|
assert.EqualValues(t, c.username, r.Publisher.UserName)
|
|
|
|
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
|
|
|
assert.Len(t, rl, 1)
|
|
|
|
|
|
|
|
// GetRelease
|
|
|
|
r2, _, err := c.GetRelease(repo.Owner.UserName, repo.Name, r.ID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, r, r2)
|
|
|
|
r2, _, err = c.GetReleaseByTag(repo.Owner.UserName, repo.Name, r.TagName)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, r, r2)
|
2022-02-15 15:14:18 +00:00
|
|
|
// ListRelease without pre-releases
|
|
|
|
tr := true
|
|
|
|
rl, _, err = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{
|
|
|
|
IsPreRelease: &tr,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2022-03-29 00:09:57 +01:00
|
|
|
assert.Len(t, rl, 1) // created release is a pre-release
|
2020-09-29 15:35:59 +01:00
|
|
|
// test fallback
|
|
|
|
r2, _, err = c.fallbackGetReleaseByTag(repo.Owner.UserName, repo.Name, r.TagName)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, r, r2)
|
|
|
|
|
|
|
|
// EditRelease
|
|
|
|
r2, _, err = c.EditRelease(repo.Owner.UserName, repo.Name, r.ID, EditReleaseOption{
|
|
|
|
Title: "Release Awesome",
|
|
|
|
Note: "",
|
2020-11-12 21:27:28 +00:00
|
|
|
IsDraft: OptionalBool(false),
|
|
|
|
IsPrerelease: OptionalBool(false),
|
2020-09-29 15:35:59 +01:00
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, r.Target, r2.Target)
|
2020-11-12 21:27:28 +00:00
|
|
|
assert.EqualValues(t, false, r2.IsDraft)
|
|
|
|
assert.EqualValues(t, false, r2.IsPrerelease)
|
2020-09-29 15:35:59 +01:00
|
|
|
assert.EqualValues(t, r.Note, r2.Note)
|
|
|
|
|
2024-01-06 05:14:12 +00:00
|
|
|
// GetLatestRelease
|
|
|
|
r3, _, err := c.GetLatestRelease(repo.Owner.UserName, repo.Name)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, r2, r3)
|
|
|
|
|
2020-09-29 15:35:59 +01:00
|
|
|
// DeleteRelease
|
|
|
|
_, err = c.DeleteRelease(repo.Owner.UserName, repo.Name, r.ID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
|
|
|
assert.Len(t, rl, 0)
|
2020-12-09 18:08:22 +00:00
|
|
|
|
2021-02-13 16:14:24 +00:00
|
|
|
// CreateRelease
|
|
|
|
_, _, err = c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{
|
|
|
|
TagName: "aNewReleaseTag",
|
2022-04-22 08:52:45 +01:00
|
|
|
Target: "main",
|
2021-02-13 16:14:24 +00:00
|
|
|
Title: "Title of aNewReleaseTag",
|
|
|
|
})
|
2020-12-09 18:08:22 +00:00
|
|
|
assert.NoError(t, err)
|
2021-02-13 16:14:24 +00:00
|
|
|
|
|
|
|
// DeleteReleaseByTag
|
|
|
|
_, err = c.DeleteReleaseByTag(repo.Owner.UserName, repo.Name, "aNewReleaseTag")
|
2020-12-09 18:08:22 +00:00
|
|
|
assert.NoError(t, err)
|
2021-02-13 16:14:24 +00:00
|
|
|
rl, _, _ = c.ListReleases(repo.Owner.UserName, repo.Name, ListReleasesOptions{})
|
|
|
|
assert.Len(t, rl, 0)
|
|
|
|
_, err = c.DeleteReleaseByTag(repo.Owner.UserName, repo.Name, "aNewReleaseTag")
|
|
|
|
assert.Error(t, err)
|
2020-09-29 15:35:59 +01:00
|
|
|
|
|
|
|
// Test Response if try to get not existing release
|
|
|
|
_, resp, err := c.GetRelease(repo.Owner.UserName, repo.Name, 1234)
|
|
|
|
assert.Error(t, err)
|
|
|
|
if assert.NotNil(t, resp) {
|
|
|
|
assert.EqualValues(t, 404, resp.StatusCode)
|
|
|
|
}
|
|
|
|
_, resp, err = c.GetReleaseByTag(repo.Owner.UserName, repo.Name, "not_here")
|
|
|
|
assert.Error(t, err)
|
|
|
|
if assert.NotNil(t, resp) {
|
|
|
|
assert.EqualValues(t, 404, resp.StatusCode)
|
|
|
|
}
|
|
|
|
_, resp, err = c.fallbackGetReleaseByTag(repo.Owner.UserName, repo.Name, "not_here")
|
|
|
|
assert.Error(t, err)
|
|
|
|
if assert.NotNil(t, resp) {
|
|
|
|
assert.EqualValues(t, 404, resp.StatusCode)
|
|
|
|
}
|
|
|
|
}
|