|
|
@@ -0,0 +1,83 @@
|
|
|
+package buggo
|
|
|
+
|
|
|
+import (
|
|
|
+ "testing"
|
|
|
+
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
|
+)
|
|
|
+
|
|
|
+func Test_readPath_throws_not_found(t *testing.T) {
|
|
|
+ _, err := readPath("doesntexist")
|
|
|
+ assert.Error(t, err, "should never exist!")
|
|
|
+
|
|
|
+ _, err2 := readPath("tests/asdfasdf")
|
|
|
+ assert.Error(t, err2, "should never exist!")
|
|
|
+}
|
|
|
+
|
|
|
+func Test_readPath_succeeds(t *testing.T) {
|
|
|
+ data, err := readPath("tests/bugs/test-1/description")
|
|
|
+ if err != nil {
|
|
|
+ assert.Fail(t, "function threw error, does tests/bugs/test-1 exist?")
|
|
|
+ }
|
|
|
+ assert.Equal(t, data, "test description\n")
|
|
|
+}
|
|
|
+
|
|
|
+func TestLoadBugErr(t *testing.T) {
|
|
|
+ _, err := LoadBug("doesntexist")
|
|
|
+ assert.Error(t, err, "should throw an error")
|
|
|
+}
|
|
|
+
|
|
|
+func TestLoadBugSuccess(t *testing.T) {
|
|
|
+ bug, err := LoadBug("tests/bugs/test-1")
|
|
|
+ if err != nil {
|
|
|
+ assert.Fail(t, "function threw error, does tests/bugs/test-1 exist?")
|
|
|
+ }
|
|
|
+
|
|
|
+ testBug := Bug{
|
|
|
+ Description: Field{data: "test description\n", path: "/description"},
|
|
|
+ Status: Field{data: "open:test\n", path: "/status"},
|
|
|
+ Tags: VariadicField{
|
|
|
+ Path: "/tags", Fields: []Field{
|
|
|
+ {data: "tag-1", path: "tag-1"},
|
|
|
+ {data: "tag-2", path: "tag-2"},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ Blockedby: VariadicField{
|
|
|
+ Path: "/blockedby", Fields: []Field{
|
|
|
+ {data: "blocker-1", path: "blocker-1"},
|
|
|
+ {data: "blocker-2", path: "blocker-1"},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ assert.Equal(t, bug.Description, testBug.Description)
|
|
|
+ assert.Equal(t, bug.Status, testBug.Status)
|
|
|
+ assert.Equal(t, len(bug.Tags.Fields), 2)
|
|
|
+ assert.Equal(t, len(bug.Blockedby.Fields), 2)
|
|
|
+}
|
|
|
+
|
|
|
+func Test_loadTags_fails(t *testing.T) {
|
|
|
+ _, err := loadVariadicField("dosentexist", VariadicField{Path: "/tags"})
|
|
|
+ assert.Error(t, err)
|
|
|
+}
|
|
|
+
|
|
|
+func Test_loadTags_no_tags_dir(t *testing.T) {
|
|
|
+ _, err := loadVariadicField("tests/bugs/test-2", VariadicField{Path: "/tags"})
|
|
|
+ assert.Error(t, err, "should not find tags")
|
|
|
+}
|
|
|
+
|
|
|
+func Test_loadTags_no_tags_in_dir(t *testing.T) {
|
|
|
+ vf, err := loadVariadicField("tests/bugs/test-3", VariadicField{Path: "/tags"})
|
|
|
+ if err != nil {
|
|
|
+ assert.Fail(t, "should not throw error")
|
|
|
+ }
|
|
|
+ assert.Equal(t, len(vf.Fields), 0)
|
|
|
+}
|
|
|
+
|
|
|
+func Test_loadTags_success(t *testing.T) {
|
|
|
+ vf, err := loadVariadicField("tests/bugs/test-1", VariadicField{Path: "/tags"})
|
|
|
+ if err != nil {
|
|
|
+ assert.Fail(t, "should not throw error")
|
|
|
+ }
|
|
|
+ assert.Equal(t, len(vf.Fields), 2)
|
|
|
+}
|