forgejo-sdk/forgejo/issue_milestone_test.go
Martijn van der Kleijn c686623cee ci: update testing for Forgejo 7.0.4 release (#12)
- bump Forgejo version to test against to 7.0.4
- ci: Increase the number of milestones to be checked in the test from 2 to 3
- ci: improve test stability by increasing sleep by 100ms
- ci: update avatar url in user test and test more user emails

Reviewed-on: https://codeberg.org/mvdkleijn/forgejo-sdk/pulls/12
Co-authored-by: Martijn van der Kleijn <martijn.niji@gmail.com>
Co-committed-by: Martijn van der Kleijn <martijn.niji@gmail.com>
2024-06-15 21:37:06 +00:00

79 lines
3 KiB
Go

// Copyright 2024 The Forgejo Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// 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.
package forgejo
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()
future := time.Unix(1896134400, 0) // 2030-02-01
closed := "closed"
sClosed := StateClosed
// CreateMilestone 4x
m1, _, err := c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v1.0", Description: "First Version", Deadline: &now})
assert.NoError(t, err)
_, _, err = c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v2.0", Description: "Second Version", Deadline: &future})
assert.NoError(t, err)
_, _, err = c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v3.0", Description: "Third Version", Deadline: nil})
assert.NoError(t, err)
m4, _, err := c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "temp", Description: "part time milestone"})
assert.NoError(t, err)
// EditMilestone
m1, _, err = c.EditMilestone(repo.Owner.UserName, repo.Name, m1.ID, EditMilestoneOption{Description: &closed, State: &sClosed})
assert.NoError(t, err)
// DeleteMilestone
_, err = c.DeleteMilestone(repo.Owner.UserName, repo.Name, m4.ID)
assert.NoError(t, err)
// ListRepoMilestones
ml, _, err := c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{})
assert.NoError(t, err)
assert.Len(t, ml, 3)
ml, _, err = c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{State: StateClosed})
assert.NoError(t, err)
assert.Len(t, ml, 1)
ml, _, err = c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{State: StateAll})
assert.NoError(t, err)
assert.Len(t, ml, 3)
ml, _, err = c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{State: StateAll, Name: "V3.0"})
assert.NoError(t, err)
assert.Len(t, ml, 1)
assert.EqualValues(t, "v3.0", ml[0].Title)
// 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)
_, _, err = c.resolveMilestoneByName(repo.Owner.UserName, repo.Name, "NoEvidenceOfExist")
assert.Error(t, err)
assert.EqualValues(t, "milestone 'NoEvidenceOfExist' do not exist", err.Error())
// GetMilestone
_, _, err = c.GetMilestone(repo.Owner.UserName, repo.Name, m4.ID)
assert.Error(t, err)
m, _, err = c.GetMilestone(repo.Owner.UserName, repo.Name, m1.ID)
assert.NoError(t, err)
assert.EqualValues(t, m1, m)
m2, _, err := c.GetMilestoneByName(repo.Owner.UserName, repo.Name, m.Title)
assert.NoError(t, err)
assert.EqualValues(t, m, m2)
}