From 9b9606baba69c6e4e3a8dba29e9e671a4960d0b2 Mon Sep 17 00:00:00 2001 From: Aleksandr Tihomirov Date: Wed, 14 Dec 2016 04:53:38 +0200 Subject: [PATCH] Update test to 1.7 and display correct sorting order (#1219) * Update test to 1.7 and display correct sorting order * Fix potential issue with goroutine exiting prematurely * Better naming for category * Remove unnecesarry format --- .travis.yml | 2 +- repo_test.go | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 684c823..45a7b25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.4 + - 1.7 sudo: false diff --git a/repo_test.go b/repo_test.go index 5aeaa44..33eeeca 100644 --- a/repo_test.go +++ b/repo_test.go @@ -3,7 +3,6 @@ package main import ( "bytes" "io/ioutil" - "log" "sort" "strings" "testing" @@ -25,19 +24,18 @@ func TestDuplicatedLinks(t *testing.T) { links := make(map[string]bool, 0) query.Find("body a").Each(func(_ int, s *goquery.Selection) { - href, ok := s.Attr("href") - if !ok { - log.Printf("expected '%s' href", s) - t.Fail() - } + t.Run(s.Text(), func(t *testing.T) { + href, ok := s.Attr("href") + if !ok { + t.Error("expected to have href") + } - if links[href] { - log.Printf("duplicated link '%s'", href) - t.Fail() - return - } + if links[href] { + t.Fatalf("duplicated link '%s'", href) + } - links[href] = true + links[href] = true + }) }) } @@ -46,7 +44,12 @@ func testList(t *testing.T, list *goquery.Selection) { testList(t, items) items.RemoveFiltered("ul") }) - checkAlphabeticOrder(t, list) + + category := list.Prev().Text() + + t.Run(category, func(t *testing.T) { + checkAlphabeticOrder(t, list) + }) } func readme() []byte { @@ -80,8 +83,10 @@ func checkAlphabeticOrder(t *testing.T, s *goquery.Selection) { for k, item := range items { if item != sorted[k] { - log.Printf("expected '%s' but actual is '%s'", sorted[k], item) - t.Fail() + t.Errorf("expected '%s' but actual is '%s'", sorted[k], item) } } + if t.Failed() { + t.Logf("expected order is:\n%s", strings.Join(sorted, "\n")) + } }