From a2cc422288ec3484aa2b28adae79800484fa6a4d Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Wed, 16 Oct 2019 09:50:40 -0400 Subject: [PATCH] comedy cards --- pkger_test.go | 2 -- pkging/pkgtest/http.go | 11 +++++++---- pkging/pkgtest/pkgtest.go | 9 +++++++++ pkging/stdos/stdos.go | 4 +++- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 pkging/pkgtest/pkgtest.go diff --git a/pkger_test.go b/pkger_test.go index b85e504..fabcf3f 100644 --- a/pkger_test.go +++ b/pkger_test.go @@ -1,7 +1,6 @@ package pkger import ( - "fmt" "os" "path/filepath" "testing" @@ -106,7 +105,6 @@ func Test_Walk(t *testing.T) { }) r.NoError(err) - fmt.Println(">>>TODO pkger_test.go:109: files ", files) r.True(len(files) > 10) } diff --git a/pkging/pkgtest/http.go b/pkging/pkgtest/http.go index bbfeaa2..ab1bc26 100644 --- a/pkging/pkgtest/http.go +++ b/pkging/pkgtest/http.go @@ -97,8 +97,10 @@ func (s Suite) Test_HTTP_Dir(t *testing.T) { b, err := ioutil.ReadAll(res.Body) r.NoError(err) - r.Contains(string(b), tt.exp) - r.NotContains(string(b), "mark.png") + + s := clean(string(b)) + r.Contains(s, tt.exp) + r.NotContains(s, "mark.png") }) } } @@ -152,7 +154,7 @@ func (s Suite) Test_HTTP_Dir_IndexHTML(t *testing.T) { b, err := ioutil.ReadAll(res.Body) r.NoError(err) - body := string(b) + body := clean(string(b)) r.Contains(body, exp) r.NotContains(body, "mark.png") }) @@ -226,7 +228,8 @@ func (s Suite) Test_HTTP_File(t *testing.T) { r.NoError(err) exp := strings.ReplaceAll(string(gobody), tdir, "") - r.Equal(exp, string(pkgbody)) + exp = clean(exp) + r.Equal(exp, clean(string(pkgbody))) }) } }) diff --git a/pkging/pkgtest/pkgtest.go b/pkging/pkgtest/pkgtest.go new file mode 100644 index 0000000..300dfb1 --- /dev/null +++ b/pkging/pkgtest/pkgtest.go @@ -0,0 +1,9 @@ +package pkgtest + +import "strings" + +func clean(s string) string { + s = strings.TrimSpace(s) + s = strings.ReplaceAll(s, "\\", "/") + return s +} diff --git a/pkging/stdos/stdos.go b/pkging/stdos/stdos.go index c5910b8..94180a5 100644 --- a/pkging/stdos/stdos.go +++ b/pkging/stdos/stdos.go @@ -181,7 +181,9 @@ func (f *Pkger) Walk(p string, wf filepath.WalkFunc) error { if err != nil { return err } - path = strings.TrimPrefix(path, filepath.Dir(f.Here.ImportPath)) + fmt.Println("path", path) + path = strings.TrimPrefix(path, f.Here.Dir) + fmt.Println("path", path) pt, err := f.Parse(fmt.Sprintf("%s:%s", pt.Pkg, path)) if err != nil { return err