mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Fix test to not fail when order is different, but slice contents are the same.
This commit is contained in:
parent
be37c0b37a
commit
aae6fa0b6b
1 changed files with 26 additions and 3 deletions
|
@ -2,9 +2,11 @@ package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/hugo/source"
|
"github.com/spf13/hugo/source"
|
||||||
"github.com/spf13/hugo/target"
|
"github.com/spf13/hugo/target"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ALIAS_DOC_1 = "---\ntitle: alias doc\naliases:\n - \"alias1/\"\n - \"alias-2/\"\n---\naliases\n"
|
const ALIAS_DOC_1 = "---\ntitle: alias doc\naliases:\n - \"alias1/\"\n - \"alias-2/\"\n---\naliases\n"
|
||||||
|
@ -24,14 +26,35 @@ var fakeSource = []source.ByteSource{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stringInSlice(a string, list []string) bool {
|
||||||
|
for _, b := range list {
|
||||||
|
if b == a {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func checkShowPlanExpected(t *testing.T, s *Site, expected string) {
|
func checkShowPlanExpected(t *testing.T, s *Site, expected string) {
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
if err := s.ShowPlan(out); err != nil {
|
if err := s.ShowPlan(out); err != nil {
|
||||||
t.Fatalf("ShowPlan unexpectedly returned an error: %s", err)
|
t.Fatalf("ShowPlan unexpectedly returned an error: %s", err)
|
||||||
}
|
}
|
||||||
got := out.String()
|
got := out.String()
|
||||||
if got != expected {
|
|
||||||
t.Errorf("ShowPlan expected:\n%q\ngot\n%q", expected, got)
|
gotList := strings.Split(got, "\n")
|
||||||
|
expectedList := strings.Split(expected, "\n")
|
||||||
|
|
||||||
|
for _, x := range gotList {
|
||||||
|
if !stringInSlice(x, expectedList) {
|
||||||
|
t.Errorf("ShowPlan expected:\n%q\ngot\n%q", expected, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, x := range expectedList {
|
||||||
|
if !stringInSlice(x, gotList) {
|
||||||
|
t.Errorf("ShowPlan expected:\n%q\ngot\n%q", expected, got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue