package proxy import ( "testing" "github.com/stretchr/testify/assert" ) func TestPicture_Extract(t *testing.T) { tbl := []struct { inp string res []string }{ { `

blah test

`, []string{"http://radio-t.com/img.png"}, }, { `

blah test

`, []string{}, }, { ``, []string{"http://radio-t.com/img2.png"}, }, { `
xyz
`, []string{"http://radio-t.com/img3.png", "http://images.pexels.com/67636/img4.jpeg"}, }, { `
xyz
`, []string{"http://images.pexels.com/67636/img4.jpeg"}, }, { `abcd blah

xxx

`, []string{}, }, } img := Image{Enabled: true} for i, tt := range tbl { res, err := img.extract(tt.inp) assert.Nil(t, err, "err in #%d", i) assert.Equal(t, tt.res, res, "mismatch in #%d", i) } } func TestPicture_Replace(t *testing.T) { img := Image{Enabled: true, RoutePath: "/img"} r := img.replace(` xyz `, []string{"http://radio-t.com/img3.png", "http://images.pexels.com/67636/img4.jpeg"}) assert.Equal(t, ` xyz `, r) }