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-01-31 02:41:33 +00: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-01-31 02:41:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMilestones(t *testing.T) {
|
|
|
|
log.Println("== TestMilestones ==")
|
|
|
|
c := newTestClient()
|
|
|
|
|
|
|
|
repo, _ := createTestRepo(t, "TestMilestones", c)
|
|
|
|
now := time.Now()
|
2022-04-28 16:33:21 +01:00
|
|
|
future := time.Unix(1896134400, 0) // 2030-02-01
|
2020-01-31 02:41:33 +00:00
|
|
|
closed := "closed"
|
2020-06-04 10:19:02 +01:00
|
|
|
sClosed := StateClosed
|
2020-01-31 02:41:33 +00:00
|
|
|
|
|
|
|
// CreateMilestone 4x
|
2020-09-14 03:37:09 +01:00
|
|
|
m1, _, err := c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v1.0", Description: "First Version", Deadline: &now})
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
_, _, err = c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v2.0", Description: "Second Version", Deadline: &future})
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
_, _, err = c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v3.0", Description: "Third Version", Deadline: nil})
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
m4, _, err := c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "temp", Description: "part time milestone"})
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// EditMilestone
|
2020-09-14 03:37:09 +01:00
|
|
|
m1, _, err = c.EditMilestone(repo.Owner.UserName, repo.Name, m1.ID, EditMilestoneOption{Description: &closed, State: &sClosed})
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// DeleteMilestone
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.DeleteMilestone(repo.Owner.UserName, repo.Name, m4.ID)
|
|
|
|
assert.NoError(t, err)
|
2020-01-31 02:41:33 +00:00
|
|
|
|
|
|
|
// ListRepoMilestones
|
2020-09-14 03:37:09 +01:00
|
|
|
ml, _, err := c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{})
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, ml, 2)
|
2020-09-14 03:37:09 +01:00
|
|
|
ml, _, err = c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{State: StateClosed})
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, ml, 1)
|
2020-09-14 03:37:09 +01:00
|
|
|
ml, _, err = c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{State: StateAll})
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, ml, 3)
|
2020-09-14 03:37:09 +01:00
|
|
|
ml, _, err = c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{State: StateAll, Name: "V3.0"})
|
2020-09-05 07:27:44 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, ml, 1)
|
|
|
|
assert.EqualValues(t, "v3.0", ml[0].Title)
|
2020-01-31 02:41:33 +00:00
|
|
|
|
2020-09-15 17:29:24 +01:00
|
|
|
// test fallback resolveMilestoneByName
|
|
|
|
m, _, err := c.resolveMilestoneByName(repo.Owner.UserName, repo.Name, "V3.0")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, ml[0].ID, m.ID)
|
2022-04-28 16:33:21 +01:00
|
|
|
_, _, err = c.resolveMilestoneByName(repo.Owner.UserName, repo.Name, "NoEvidenceOfExist")
|
2020-09-15 17:29:24 +01:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.EqualValues(t, "milestone 'NoEvidenceOfExist' do not exist", err.Error())
|
|
|
|
|
2020-01-31 02:41:33 +00:00
|
|
|
// GetMilestone
|
2020-09-14 03:37:09 +01:00
|
|
|
_, _, err = c.GetMilestone(repo.Owner.UserName, repo.Name, m4.ID)
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.Error(t, err)
|
2020-09-15 17:29:24 +01:00
|
|
|
m, _, err = c.GetMilestone(repo.Owner.UserName, repo.Name, m1.ID)
|
2020-05-27 14:04:51 +01:00
|
|
|
assert.NoError(t, err)
|
2020-01-31 02:41:33 +00:00
|
|
|
assert.EqualValues(t, m1, m)
|
2020-09-15 17:29:24 +01:00
|
|
|
m2, _, err := c.GetMilestoneByName(repo.Owner.UserName, repo.Name, m.Title)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, m, m2)
|
2020-01-31 02:41:33 +00:00
|
|
|
}
|