| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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)
- }
|