aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-02-04 18:28:47 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-02-04 18:28:47 +0300
commitec0baaa14313e84af97ea1783559e5ccdc293c8e (patch)
treec85f3695f178bef383991a8d3559a15ed3a967e0
parentdda2cae72b1dc9fb87959c7f31fa23d07a84ee37 (diff)
downloadradiorus-rss-ec0baaa14313e84af97ea1783559e5ccdc293c8e.tar.gz
radiorus-rss-ec0baaa14313e84af97ea1783559e5ccdc293c8e.zip
refactor tests
-rw-r--r--main_test.go49
1 files changed, 17 insertions, 32 deletions
diff --git a/main_test.go b/main_test.go
index 96c8d11..d403753 100644
--- a/main_test.go
+++ b/main_test.go
@@ -50,6 +50,19 @@ func helperLoadBytes(t testing.TB, name string) []byte {
return bytes
}
+func assertGolden(t *testing.T, actual []byte, golden string) {
+ t.Helper()
+
+ if *update {
+ writeFile(actual, golden)
+ }
+ expected, _ := ioutil.ReadFile(golden)
+
+ if !bytes.Equal(actual, expected) {
+ t.Fail()
+ }
+}
+
func TestFeed(t *testing.T) {
var page []byte
@@ -73,14 +86,7 @@ func TestFeed(t *testing.T) {
actual := createFeed(feed)
golden := filepath.Join("testdata", t.Name()+".golden")
- if *update {
- writeFile(actual, golden)
- }
- expected, _ := ioutil.ReadFile(golden)
-
- if !bytes.Equal(actual, expected) {
- t.Fail()
- }
+ assertGolden(t, actual, golden)
}
func TestFindEpisodes(t *testing.T) {
@@ -95,14 +101,7 @@ func TestFindEpisodes(t *testing.T) {
actual := bytes.Join(findEpisodes(page), []byte("\n&&&\n"))
golden := filepath.Join("testdata", t.Name()+"."+test+".golden")
- if *update {
- writeFile(actual, golden)
- }
- expected, _ := ioutil.ReadFile(golden)
-
- if !bytes.Equal(actual, expected) {
- t.Fail()
- }
+ assertGolden(t, actual, golden)
}
}
@@ -122,14 +121,7 @@ func TestUpdatingFeed(t *testing.T) {
actual := createFeed(feed)
golden := filepath.Join("testdata", t.Name()+".golden")
- if *update {
- writeFile(actual, golden)
- }
- expected, _ := ioutil.ReadFile(golden)
-
- if !bytes.Equal(actual, expected) {
- t.Fail()
- }
+ assertGolden(t, actual, golden)
}
func TestMissingEpisode(t *testing.T) {
@@ -199,14 +191,7 @@ func TestServedFeed(t *testing.T) {
actual := bytes.ReplaceAll(createFeed(feed), []byte(server.URL), []byte(fakeURL))
golden := filepath.Join("testdata", t.Name()+".golden")
- if *update {
- writeFile(actual, golden)
- }
- expected, _ := ioutil.ReadFile(golden)
-
- if !bytes.Equal(actual, expected) {
- t.Fail()
- }
+ assertGolden(t, actual, golden)
}
func BenchmarkServedFeed(b *testing.B) {