summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2024-05-18 12:13:45 -0600
committermo khan <mo@mokhan.ca>2024-05-18 12:13:45 -0600
commit41fe3a65860c6d9572e4dde4682d8233a3bd3ba3 (patch)
treede36e942848a5b21a8254d360fad43636602036a
parentcf1abd6a058af31659fe8692ae771d0f5d63626b (diff)
test: start to add unit tests
-rw-r--r--.gitlab-ci.yml8
-rw-r--r--cmd/stanuki/main.go11
-rw-r--r--go.mod12
-rw-r--r--go.sum7
-rw-r--r--pkg/gitlab/issue.go9
-rw-r--r--pkg/gitlab/issue_test.go15
6 files changed, 51 insertions, 11 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1b50f86..898fa7a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,6 +2,7 @@ image: golang:alpine
stages:
- build
+ - test
go_build:
stage: build
@@ -13,3 +14,10 @@ go_build:
- apk add --no-cache git
script:
- go build -o stanuki cmd/stanuki/main.go
+
+go_test:
+ stage: test
+ before_script:
+ - apk add --no-cache git
+ script:
+ - go test ./...
diff --git a/cmd/stanuki/main.go b/cmd/stanuki/main.go
index 332c1ad..18284d4 100644
--- a/cmd/stanuki/main.go
+++ b/cmd/stanuki/main.go
@@ -9,16 +9,9 @@ import (
"github.com/xlgmokha/x/pkg/env"
"github.com/xlgmokha/x/pkg/serde"
"github.com/xlgmokha/x/pkg/x"
+ "gitlab.com/mokhax/stanuki/pkg/gitlab"
)
-type Issue struct {
- ID int `json:"id"`
- IID int `json:"iid"`
- ProjectID int `json:"project_id"`
- Title string `json:"title"`
- Description string `json:"description"`
-}
-
func main() {
token := env.Fetch("GITLAB_TOKEN", "")
url := "https://gitlab.com/api/v4/groups/9970/issues"
@@ -29,7 +22,7 @@ func main() {
if env.Fetch("DUMP", "") != "" {
fmt.Println(string(x.Must(io.ReadAll(response.Body))))
} else {
- issues := x.Must(serde.From[[]Issue](response.Body, serde.JSON))
+ issues := x.Must(serde.From[[]gitlab.Issue](response.Body, serde.JSON))
for _, issue := range issues {
fmt.Printf("%v: %v\n", issue.ID, issue.Title)
}
diff --git a/go.mod b/go.mod
index 44e95a7..c78d8ee 100644
--- a/go.mod
+++ b/go.mod
@@ -2,6 +2,14 @@ module gitlab.com/mokhax/stanuki
go 1.22
-require github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1
+require (
+ github.com/stretchr/testify v1.8.0
+ github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1
+)
-require github.com/google/jsonapi v1.0.0 // indirect
+require (
+ github.com/davecgh/go-spew v1.1.1 // indirect
+ github.com/google/jsonapi v1.0.0 // indirect
+ github.com/pmezard/go-difflib v1.0.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
+)
diff --git a/go.sum b/go.sum
index fedec6e..8ff9c07 100644
--- a/go.sum
+++ b/go.sum
@@ -1,12 +1,19 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/jsonapi v1.0.0 h1:qIGgO5Smu3yJmSs+QlvhQnrscdZfFhiV6S8ryJAglqU=
github.com/google/jsonapi v1.0.0/go.mod h1:YYHiRPJT8ARXGER8In9VuLv4qvLfDmA9ULQqptbLE4s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1 h1:MIqcDqEAcr16QUq/kFJC3xbYoaAjjsxYEJLGtol2U58=
github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1/go.mod h1:Hf/0a9FveTBuVKvZ+Emmw6BlJyLGlhgjQwa4dFXp48s=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/pkg/gitlab/issue.go b/pkg/gitlab/issue.go
new file mode 100644
index 0000000..720a78b
--- /dev/null
+++ b/pkg/gitlab/issue.go
@@ -0,0 +1,9 @@
+package gitlab
+
+type Issue struct {
+ ID int `json:"id"`
+ IID int `json:"iid"`
+ ProjectID int `json:"project_id"`
+ Title string `json:"title"`
+ Description string `json:"description"`
+}
diff --git a/pkg/gitlab/issue_test.go b/pkg/gitlab/issue_test.go
new file mode 100644
index 0000000..fd1feeb
--- /dev/null
+++ b/pkg/gitlab/issue_test.go
@@ -0,0 +1,15 @@
+package gitlab
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestIssue(t *testing.T) {
+ t.Run("ParseIssues", func(t *testing.T) {
+ t.Run("parses the array of issues from IO", func(t *testing.T) {
+ assert.Equal(t, false, true)
+ })
+ })
+}