summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-04-17 02:49:05 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-04-17 02:49:05 -0600
commit001168238aadb4eac052dd17bc5e0c800a64698b (patch)
treebd02a7bf8aa10b199655b15db134a8e98c6c8f5c /cmd
parent50cd710163edb398e72d56414d956607919a805b (diff)
Add tests for StatusClass
Diffstat (limited to 'cmd')
-rw-r--r--cmd/generate/src_contribs.go30
-rw-r--r--cmd/generate/src_contribs_test.go35
2 files changed, 54 insertions, 11 deletions
diff --git a/cmd/generate/src_contribs.go b/cmd/generate/src_contribs.go
index b47cf89..760b56a 100644
--- a/cmd/generate/src_contribs.go
+++ b/cmd/generate/src_contribs.go
@@ -20,7 +20,8 @@ type Contribution struct {
SubmittedAt time.Time `json:"submitted-at"`
LastUpdatedAt time.Time `json:"last-updated-at"`
Status string `json:"status"`
- StatusClass string `json:"-"`
+
+ StatusClass string `json:"-"`
}
func ReadContribs(filename string) ([]Contribution, error) {
@@ -62,19 +63,26 @@ func (c *Contribution) Fill() error {
return err
}
}
+ c.StatusClass, err = classifyStatus(c.Status)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func classifyStatus(status string) (string, error) {
switch {
- case strings.Contains(c.Status, "released") || strings.Contains(c.Status, "deployed"):
- c.StatusClass = "released"
- case strings.Contains(c.Status, "merged"):
- c.StatusClass = "merged"
- case strings.Contains(c.Status, "open"):
- c.StatusClass = "open"
- case strings.Contains(c.Status, "closed") || strings.Contains(c.Status, "locked"):
- c.StatusClass = "closed"
+ case strings.Contains(status, "released") || strings.Contains(status, "deployed"):
+ return "released", nil
+ case strings.Contains(status, "merged"):
+ return "merged", nil
+ case strings.Contains(status, "open"):
+ return "open", nil
+ case strings.Contains(status, "closed") || strings.Contains(status, "locked"):
+ return "closed", nil
default:
- return fmt.Errorf("unrecognized status string: %q", c.Status)
+ return "", fmt.Errorf("unrecognized status string: %q", status)
}
- return nil
}
var (
diff --git a/cmd/generate/src_contribs_test.go b/cmd/generate/src_contribs_test.go
new file mode 100644
index 0000000..f7566c0
--- /dev/null
+++ b/cmd/generate/src_contribs_test.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+ "testing"
+
+ "github.com/alecthomas/assert/v2"
+)
+
+func TestClassifyStatus(t *testing.T) {
+ testcases := map[string]struct {
+ Str string
+ Err string
+ }{
+ "merged+deployed": {"released", ""},
+ "released in v1.2": {"released", ""},
+
+ "merged": {"merged", ""},
+
+ "open": {"open", ""},
+
+ "closed": {"closed", ""},
+ "locked": {"closed", ""},
+ }
+ for in, exp := range testcases {
+ t.Run(in, func(t *testing.T) {
+ actStr, actErr := classifyStatus(in)
+ assert.Equal(t, exp.Str, actStr)
+ if exp.Err == "" {
+ assert.NoError(t, actErr)
+ } else {
+ assert.EqualError(t, actErr, exp.Err)
+ }
+ })
+ }
+}