io_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package buggo
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func Test_readPath_throws_not_found(t *testing.T) {
  7. _, err := readPath("doesntexist")
  8. assert.Error(t, err, "should never exist!")
  9. _, err2 := readPath("tests/asdfasdf")
  10. assert.Error(t, err2, "should never exist!")
  11. }
  12. func Test_readPath_succeeds(t *testing.T) {
  13. data, err := readPath("tests/bugs/test-1/description")
  14. if err != nil {
  15. assert.Fail(t, "function threw error, does tests/bugs/test-1 exist?")
  16. }
  17. assert.Equal(t, data, "test description\n")
  18. }
  19. func TestLoadBugErr(t *testing.T) {
  20. _, err := LoadBug("doesntexist")
  21. assert.Error(t, err, "should throw an error")
  22. }
  23. func TestLoadBugSuccess(t *testing.T) {
  24. bug, err := LoadBug("tests/bugs/test-1")
  25. if err != nil {
  26. assert.Fail(t, "function threw error, does tests/bugs/test-1 exist?")
  27. }
  28. testBug := Bug{
  29. Description: Field{data: "test description\n", path: "/description"},
  30. Status: Field{data: "open:test\n", path: "/status"},
  31. Tags: VariadicField{
  32. Path: "/tags", Fields: []Field{
  33. {data: "tag-1", path: "tag-1"},
  34. {data: "tag-2", path: "tag-2"},
  35. },
  36. },
  37. Blockedby: VariadicField{
  38. Path: "/blockedby", Fields: []Field{
  39. {data: "blocker-1", path: "blocker-1"},
  40. {data: "blocker-2", path: "blocker-1"},
  41. },
  42. },
  43. }
  44. assert.Equal(t, bug.Description, testBug.Description)
  45. assert.Equal(t, bug.Status, testBug.Status)
  46. assert.Equal(t, len(bug.Tags.Fields), 2)
  47. assert.Equal(t, len(bug.Blockedby.Fields), 2)
  48. }
  49. func Test_loadTags_fails(t *testing.T) {
  50. _, err := loadVariadicField("dosentexist", VariadicField{Path: "/tags"})
  51. assert.Error(t, err)
  52. }
  53. func Test_loadTags_no_tags_dir(t *testing.T) {
  54. _, err := loadVariadicField("tests/bugs/test-2", VariadicField{Path: "/tags"})
  55. assert.Error(t, err, "should not find tags")
  56. }
  57. func Test_loadTags_no_tags_in_dir(t *testing.T) {
  58. vf, err := loadVariadicField("tests/bugs/test-3", VariadicField{Path: "/tags"})
  59. if err != nil {
  60. assert.Fail(t, "should not throw error")
  61. }
  62. assert.Equal(t, len(vf.Fields), 0)
  63. }
  64. func Test_loadTags_success(t *testing.T) {
  65. vf, err := loadVariadicField("tests/bugs/test-1", VariadicField{Path: "/tags"})
  66. if err != nil {
  67. assert.Fail(t, "should not throw error")
  68. }
  69. assert.Equal(t, len(vf.Fields), 2)
  70. }