From ddabcc97d9ea0116cebbc9e88fb5ed8469d7eb5f Mon Sep 17 00:00:00 2001 From: Boris Ershov Date: Sat, 9 Oct 2021 21:20:36 +0700 Subject: [PATCH] Changed project id from in to string --- attachments_test.go | 2 +- go.mod | 2 +- issues_test.go | 4 ++-- memberships.go | 10 +++++----- memberships_test.go | 10 +++++----- projects.go | 12 ++++++------ projects_test.go | 39 ++++++++++++++++++++++++++++++++------- 7 files changed, 52 insertions(+), 27 deletions(-) diff --git a/attachments_test.go b/attachments_test.go index bac3fcc..25f837f 100644 --- a/attachments_test.go +++ b/attachments_test.go @@ -26,7 +26,7 @@ func TestAttachmentsCRUD(t *testing.T) { // Preparing auxiliary data pCreated := testProjectCreate(t, r, []int{testIssueTrackerID}) - defer testProjectDetele(t, r, pCreated.ID) + defer testProjectDetele(t, r, pCreated.Identifier) // Get multi diff --git a/go.mod b/go.mod index 0806b53..574d586 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/nixys/nxs-go-redmine/v3 +module github.com/nixys/nxs-go-redmine/v4 go 1.14 diff --git a/issues_test.go b/issues_test.go index 97f40a9..309f882 100644 --- a/issues_test.go +++ b/issues_test.go @@ -32,12 +32,12 @@ func TestIssuesCRUD(t *testing.T) { // Preparing auxiliary data pCreated := testProjectCreate(t, r, []int{testIssueTrackerID}) - defer testProjectDetele(t, r, pCreated.ID) + defer testProjectDetele(t, r, pCreated.Identifier) uCreated := testUserCreate(t, r) defer testUserDetele(t, r, uCreated.ID) - testMembershipAdd(t, r, pCreated.ID, uCreated.ID, testMembershipRoleID) + testMembershipAdd(t, r, pCreated.Identifier, uCreated.ID, testMembershipRoleID) // Add and delete iCreated := testIssueCreate(t, r, pCreated.ID, uCreated.ID, nil) diff --git a/memberships.go b/memberships.go index a033c1c..0f52ccf 100644 --- a/memberships.go +++ b/memberships.go @@ -74,7 +74,7 @@ type membershipUpdate struct { // MembershipAllGet gets info for all memberships for project with specified ID // // see: http://www.redmine.org/projects/redmine/wiki/Rest_Memberships#GET -func (r *Context) MembershipAllGet(projectID int) (MembershipResult, int, error) { +func (r *Context) MembershipAllGet(projectID string) (MembershipResult, int, error) { var ( membership MembershipResult @@ -114,7 +114,7 @@ func (r *Context) MembershipAllGet(projectID int) (MembershipResult, int, error) // MembershipMultiGet gets info for multiple memberships for project with specified ID // // see: http://www.redmine.org/projects/redmine/wiki/Rest_Memberships#GET -func (r *Context) MembershipMultiGet(projectID int, request MembershipMultiGetRequest) (MembershipResult, int, error) { +func (r *Context) MembershipMultiGet(projectID string, request MembershipMultiGetRequest) (MembershipResult, int, error) { var m MembershipResult @@ -123,7 +123,7 @@ func (r *Context) MembershipMultiGet(projectID int, request MembershipMultiGetRe urlParams.Add("limit", strconv.Itoa(request.Limit)) ur := url.URL{ - Path: "/projects/" + strconv.Itoa(projectID) + "/memberships.json", + Path: "/projects/" + projectID + "/memberships.json", RawQuery: urlParams.Encode(), } @@ -151,12 +151,12 @@ func (r *Context) MembershipSingleGet(membershipID int) (MembershipObject, int, // MembershipAdd adds new member to project with specified ID // // see: http://www.redmine.org/projects/redmine/wiki/Rest_Memberships#POST -func (r *Context) MembershipAdd(projectID int, membership MembershipAddObject) (MembershipObject, int, error) { +func (r *Context) MembershipAdd(projectID string, membership MembershipAddObject) (MembershipObject, int, error) { var m membershipSingleResult ur := url.URL{ - Path: "/projects/" + strconv.Itoa(projectID) + "/memberships.json", + Path: "/projects/" + projectID + "/memberships.json", } status, err := r.post(membershipAdd{Membership: membership}, &m, ur, http.StatusCreated) diff --git a/memberships_test.go b/memberships_test.go index d08b883..fcd8dc7 100644 --- a/memberships_test.go +++ b/memberships_test.go @@ -26,14 +26,14 @@ func TestMembershipCRUD(t *testing.T) { defer testUserDetele(t, r, uCreated.ID) pCreated := testProjectCreate(t, r, []int{}) - defer testProjectDetele(t, r, pCreated.ID) + defer testProjectDetele(t, r, pCreated.Identifier) // Add and delete - mCreated := testMembershipAdd(t, r, pCreated.ID, uCreated.ID, testMembershipRoleID1) + mCreated := testMembershipAdd(t, r, pCreated.Identifier, uCreated.ID, testMembershipRoleID1) defer testMembershipDetele(t, r, mCreated.ID) // Get all - testMembershipAllGet(t, r, mCreated.ID, pCreated.ID, testMembershipRoleID1) + testMembershipAllGet(t, r, mCreated.ID, pCreated.Identifier, testMembershipRoleID1) // Update testMembershipUpdate(t, r, mCreated.ID, testMembershipRoleID1, testMembershipRoleID2) @@ -42,7 +42,7 @@ func TestMembershipCRUD(t *testing.T) { testMembershipSingleGet(t, r, mCreated.ID, testMembershipRoleID2) } -func testMembershipAdd(t *testing.T, r Context, projectID, userID, roleID int) MembershipObject { +func testMembershipAdd(t *testing.T, r Context, projectID string, userID, roleID int) MembershipObject { m, _, err := r.MembershipAdd(projectID, MembershipAddObject{ UserID: userID, @@ -79,7 +79,7 @@ func testMembershipDetele(t *testing.T, r Context, id int) { t.Logf("Membership delete: success") } -func testMembershipAllGet(t *testing.T, r Context, id, projectID, roleID int) { +func testMembershipAllGet(t *testing.T, r Context, id int, projectID string, roleID int) { m, _, err := r.MembershipAllGet(projectID) if err != nil { diff --git a/projects.go b/projects.go index 5d73cda..3eabee4 100644 --- a/projects.go +++ b/projects.go @@ -225,7 +225,7 @@ func (r *Context) ProjectMultiGet(request ProjectMultiGetRequest) (ProjectResult // * issue_categories // * enabled_modules // * time_entry_activities (since 3.4.0) -func (r *Context) ProjectSingleGet(id int, request ProjectSingleGetRequest) (ProjectObject, int, error) { +func (r *Context) ProjectSingleGet(id string, request ProjectSingleGetRequest) (ProjectObject, int, error) { var p projectSingleResult @@ -235,7 +235,7 @@ func (r *Context) ProjectSingleGet(id int, request ProjectSingleGetRequest) (Pro urlIncludes(&urlParams, request.Includes) ur := url.URL{ - Path: "/projects/" + strconv.Itoa(id) + ".json", + Path: "/projects/" + id + ".json", RawQuery: urlParams.Encode(), } @@ -263,10 +263,10 @@ func (r *Context) ProjectCreate(project ProjectCreateObject) (ProjectObject, int // ProjectUpdate updates project with specified ID // // see: http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Updating-a-project -func (r *Context) ProjectUpdate(id int, project ProjectUpdateObject) (int, error) { +func (r *Context) ProjectUpdate(id string, project ProjectUpdateObject) (int, error) { ur := url.URL{ - Path: "/projects/" + strconv.Itoa(id) + ".json", + Path: "/projects/" + id + ".json", } status, err := r.put(projectUpdate{Project: project}, nil, ur, http.StatusNoContent) @@ -277,10 +277,10 @@ func (r *Context) ProjectUpdate(id int, project ProjectUpdateObject) (int, error // ProjectDelete deletes project with specified ID // // see: http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Deleting-a-project -func (r *Context) ProjectDelete(id int) (int, error) { +func (r *Context) ProjectDelete(id string) (int, error) { ur := url.URL{ - Path: "/projects/" + strconv.Itoa(id) + ".json", + Path: "/projects/" + id + ".json", } status, err := r.del(nil, nil, ur, http.StatusNoContent) diff --git a/projects_test.go b/projects_test.go index 430d63d..cadb9c8 100644 --- a/projects_test.go +++ b/projects_test.go @@ -12,7 +12,7 @@ const ( testProjectIdentifier = "test_project" ) -func TestProjectsCRUD(t *testing.T) { +func TestProjectsCRUDIdentifier(t *testing.T) { var r Context @@ -27,14 +27,39 @@ func TestProjectsCRUD(t *testing.T) { // Create and delete pCreated := testProjectCreate(t, r, []int{testProjectTrackerID}) - defer testProjectDetele(t, r, pCreated.ID) + defer testProjectDetele(t, r, pCreated.Identifier) // Get testProjectAllGet(t, r) - testProjectSingleGet(t, r, pCreated.ID) + testProjectSingleGet(t, r, pCreated.Identifier) // Update - testProjectUpdate(t, r, pCreated.ID) + testProjectUpdate(t, r, pCreated.Identifier) +} + +func TestProjectsCRUDID(t *testing.T) { + + var r Context + + // Get env variables + testProjectTrackerID, _ := strconv.Atoi(os.Getenv("REDMINE_TRACKER_ID")) + if testProjectTrackerID == 0 { + t.Fatal("Project test error: env variables `REDMINE_TRACKER_ID` does not set") + } + + // Init Redmine context + initTest(&r, t) + + // Create and delete + pCreated := testProjectCreate(t, r, []int{testProjectTrackerID}) + defer testProjectDetele(t, r, strconv.Itoa(pCreated.ID)) + + // Get + testProjectAllGet(t, r) + testProjectSingleGet(t, r, strconv.Itoa(pCreated.ID)) + + // Update + testProjectUpdate(t, r, strconv.Itoa(pCreated.ID)) } func testProjectCreate(t *testing.T, r Context, trackerIDs []int) ProjectObject { @@ -55,7 +80,7 @@ func testProjectCreate(t *testing.T, r Context, trackerIDs []int) ProjectObject return p } -func testProjectUpdate(t *testing.T, r Context, id int) { +func testProjectUpdate(t *testing.T, r Context, id string) { _, err := r.ProjectUpdate(id, ProjectUpdateObject{ Name: testProjectName2, @@ -67,7 +92,7 @@ func testProjectUpdate(t *testing.T, r Context, id int) { t.Logf("Project update: success") } -func testProjectDetele(t *testing.T, r Context, id int) { +func testProjectDetele(t *testing.T, r Context, id string) { _, err := r.ProjectDelete(id) if err != nil { @@ -99,7 +124,7 @@ func testProjectAllGet(t *testing.T, r Context) { t.Fatal("Projects get error: can't find created project") } -func testProjectSingleGet(t *testing.T, r Context, id int) { +func testProjectSingleGet(t *testing.T, r Context, id string) { _, _, err := r.ProjectSingleGet(id, ProjectSingleGetRequest{ Includes: []string{"trackers", "issue_categories", "enabled_modules"},