| 1 | package slack |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestNewMessageItem(t *testing.T) { |
| 6 | c := "C1" |
| 7 | m := &Message{} |
| 8 | mi := NewMessageItem(c, m) |
| 9 | if mi.Type != TYPE_MESSAGE { |
| 10 | t.Errorf("want Type %s, got %s", mi.Type, TYPE_MESSAGE) |
| 11 | } |
| 12 | if mi.Channel != c { |
| 13 | t.Errorf("got Channel %s, want %s", mi.Channel, c) |
| 14 | } |
| 15 | if mi.Message != m { |
| 16 | t.Errorf("got Message %v, want %v", mi.Message, m) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | func TestNewFileItem(t *testing.T) { |
| 21 | f := &File{} |
| 22 | fi := NewFileItem(f) |
| 23 | if fi.Type != TYPE_FILE { |
| 24 | t.Errorf("got Type %s, want %s", fi.Type, TYPE_FILE) |
| 25 | } |
| 26 | if fi.File != f { |
| 27 | t.Errorf("got File %v, want %v", fi.File, f) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func TestNewFileCommentItem(t *testing.T) { |
| 32 | f := &File{} |
| 33 | c := &Comment{} |
| 34 | fci := NewFileCommentItem(f, c) |
| 35 | if fci.Type != TYPE_FILE_COMMENT { |
| 36 | t.Errorf("got Type %s, want %s", fci.Type, TYPE_FILE_COMMENT) |
| 37 | } |
| 38 | if fci.File != f { |
| 39 | t.Errorf("got File %v, want %v", fci.File, f) |
| 40 | } |
| 41 | if fci.Comment != c { |
| 42 | t.Errorf("got Comment %v, want %v", fci.Comment, c) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | func TestNewChannelItem(t *testing.T) { |
| 47 | c := "C1" |
| 48 | ci := NewChannelItem(c) |
| 49 | if ci.Type != TYPE_CHANNEL { |
| 50 | t.Errorf("got Type %s, want %s", ci.Type, TYPE_CHANNEL) |
| 51 | } |
| 52 | if ci.Channel != "C1" { |
| 53 | t.Errorf("got Channel %v, want %v", ci.Channel, "C1") |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestNewIMItem(t *testing.T) { |
| 58 | c := "D1" |
| 59 | ci := NewIMItem(c) |
| 60 | if ci.Type != TYPE_IM { |
| 61 | t.Errorf("got Type %s, want %s", ci.Type, TYPE_IM) |
| 62 | } |
| 63 | if ci.Channel != "D1" { |
| 64 | t.Errorf("got Channel %v, want %v", ci.Channel, "D1") |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestNewGroupItem(t *testing.T) { |
| 69 | c := "G1" |
| 70 | ci := NewGroupItem(c) |
| 71 | if ci.Type != TYPE_GROUP { |
| 72 | t.Errorf("got Type %s, want %s", ci.Type, TYPE_GROUP) |
| 73 | } |
| 74 | if ci.Channel != "G1" { |
| 75 | t.Errorf("got Channel %v, want %v", ci.Channel, "G1") |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestNewRefToMessage(t *testing.T) { |
| 80 | ref := NewRefToMessage("chan", "ts") |
| 81 | if got, want := ref.Channel, "chan"; got != want { |
| 82 | t.Errorf("Channel got %s, want %s", got, want) |
| 83 | } |
| 84 | if got, want := ref.Timestamp, "ts"; got != want { |
| 85 | t.Errorf("Timestamp got %s, want %s", got, want) |
| 86 | } |
| 87 | if got, want := ref.File, ""; got != want { |
| 88 | t.Errorf("File got %s, want %s", got, want) |
| 89 | } |
| 90 | if got, want := ref.Comment, ""; got != want { |
| 91 | t.Errorf("Comment got %s, want %s", got, want) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func TestNewRefToFile(t *testing.T) { |
| 96 | ref := NewRefToFile("file") |
| 97 | if got, want := ref.Channel, ""; got != want { |
| 98 | t.Errorf("Channel got %s, want %s", got, want) |
| 99 | } |
| 100 | if got, want := ref.Timestamp, ""; got != want { |
| 101 | t.Errorf("Timestamp got %s, want %s", got, want) |
| 102 | } |
| 103 | if got, want := ref.File, "file"; got != want { |
| 104 | t.Errorf("File got %s, want %s", got, want) |
| 105 | } |
| 106 | if got, want := ref.Comment, ""; got != want { |
| 107 | t.Errorf("Comment got %s, want %s", got, want) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | func TestNewRefToComment(t *testing.T) { |
| 112 | ref := NewRefToComment("file_comment") |
| 113 | if got, want := ref.Channel, ""; got != want { |
| 114 | t.Errorf("Channel got %s, want %s", got, want) |
| 115 | } |
| 116 | if got, want := ref.Timestamp, ""; got != want { |
| 117 | t.Errorf("Timestamp got %s, want %s", got, want) |
| 118 | } |
| 119 | if got, want := ref.File, ""; got != want { |
| 120 | t.Errorf("File got %s, want %s", got, want) |
| 121 | } |
| 122 | if got, want := ref.Comment, "file_comment"; got != want { |
| 123 | t.Errorf("Comment got %s, want %s", got, want) |
| 124 | } |
| 125 | } |