Skip to content

Commit

Permalink
media/test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nentenpizza authored and demget committed Mar 5, 2024
1 parent 260a67b commit b67df64
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,39 @@ import (
)

func TestAlbumSetCaption(t *testing.T) {
var a Album
a = append(a, &Photo{Caption: "wrong_caption"})
a = append(a, &Photo{Caption: "t"})
a.SetCaption("correct_caption")
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
assert.Equal(t, "t", a[1].InputMedia().Caption)

a = Album{}
a = append(a, &Animation{Caption: "wrong_caption"})
a = append(a, &Photo{Caption: "t"})
a.SetCaption("correct_caption")
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
assert.Equal(t, "t", a[1].InputMedia().Caption)

a = Album{}
a = append(a, &Audio{Caption: "wrong_caption"})
a = append(a, &Photo{Caption: "t"})
a.SetCaption("correct_caption")
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
assert.Equal(t, "t", a[1].InputMedia().Caption)

a = Album{}
a = append(a, &Document{Caption: "wrong_caption"})
a = append(a, &Photo{Caption: "t"})
a.SetCaption("correct_caption")
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
assert.Equal(t, "t", a[1].InputMedia().Caption)

a = Album{}
a = append(a, &Video{Caption: "wrong_caption"})
a = append(a, &Photo{Caption: "t"})
a.SetCaption("correct_caption")
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
assert.Equal(t, "t", a[1].InputMedia().Caption)
tests := []struct {
name string
media Inputtable
}{
{
name: "photo",
media: &Photo{Caption: "wrong_caption"},
},
{
name: "animation",
media: &Animation{Caption: "wrong_caption"},
},
{
name: "video",
media: &Video{Caption: "wrong_caption"},
},
{
name: "audio",
media: &Audio{Caption: "wrong_caption"},
},
{
name: "document",
media: &Document{Caption: "wrong_caption"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var a Album
a = append(a, tt.media)
a = append(a, &Photo{Caption: "random_caption"})
a.SetCaption("correct_caption")
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
assert.Equal(t, "random_caption", a[1].InputMedia().Caption)
})
}
}

0 comments on commit b67df64

Please sign in to comment.