From f619fdce4c342451f4b7f96e6630d5e9d0479725 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 18 May 2024 12:38:37 -0600 Subject: test: parse json fields --- pkg/gitlab/issue.go | 17 ++++++++++++----- pkg/gitlab/issue_test.go | 11 ++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'pkg') diff --git a/pkg/gitlab/issue.go b/pkg/gitlab/issue.go index 959ade6..2a21e84 100644 --- a/pkg/gitlab/issue.go +++ b/pkg/gitlab/issue.go @@ -6,12 +6,19 @@ import ( "github.com/xlgmokha/x/pkg/serde" ) +type IssueState string + +const ( + StateClosed IssueState = "closed" +) + type Issue struct { - ID int `json:"id"` - IID int `json:"iid"` - ProjectID int `json:"project_id"` - Title string `json:"title"` - Description string `json:"description"` + ID int `json:"id"` + IID int `json:"iid"` + ProjectID int `json:"project_id"` + Title string `json:"title"` + Description string `json:"description"` + State IssueState `json:"state"` } func FromIssues(r io.Reader) ([]Issue, error) { diff --git a/pkg/gitlab/issue_test.go b/pkg/gitlab/issue_test.go index 3c969fa..0d15061 100644 --- a/pkg/gitlab/issue_test.go +++ b/pkg/gitlab/issue_test.go @@ -33,7 +33,16 @@ func TestIssue(t *testing.T) { results, err := FromIssues(reader) require.NoError(t, err) - assert.Equal(t, 20, len(results)) + assert.Len(t, results, 20) + + result := results[0] + + assert.Equal(t, 146760799, result.ID) + assert.Equal(t, 6375, result.IID) + assert.Equal(t, 40549124, result.ProjectID) + assert.Contains(t, result.Title, "`gitlab-org/gitlab` broken `master` with rspec unit") + assert.Contains(t, result.Description, "## How to close this incident\n\n- Follow the steps in the") + assert.Equal(t, StateClosed, result.State) }) }) } -- cgit v1.2.3