From 28af04274c9f5dbdbdb09f944053f065fcc2a5d4 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 3 Sep 2019 18:38:52 -0400 Subject: [PATCH] games of chance --- .gitignore | 1 + pkging/pkgtest/http.go | 53 +++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 6f31e5c..65a6e19 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ gin-bin .idea/ pkged.go cover.out +.pkgtest diff --git a/pkging/pkgtest/http.go b/pkging/pkgtest/http.go index 17b8d5b..b4d5c13 100644 --- a/pkging/pkgtest/http.go +++ b/pkging/pkgtest/http.go @@ -74,6 +74,8 @@ func (s Suite) Test_HTTP_Dir(t *testing.T) { dir, err := s.Open(tt.in) r.NoError(err) + defer dir.Close() + ts := httptest.NewServer(http.FileServer(dir)) defer ts.Close() @@ -114,6 +116,7 @@ func (s Suite) Test_HTTP_Dir_IndexHTML(t *testing.T) { dir, err := s.Open(tt.in) r.NoError(err) + defer dir.Close() ts := httptest.NewServer(http.FileServer(dir)) defer ts.Close() @@ -132,25 +135,49 @@ func (s Suite) Test_HTTP_Dir_IndexHTML(t *testing.T) { } } -// func (s Suite) Test_HTTP_File_Memory(t *testing.T) { +// func (s Suite) Test_HTTP_File(t *testing.T) { // r := require.New(t) // -// fs := NewPkger() -// r.NoError(Folder.Create(fs)) -// -// dir, err := fs.Open("/") +// cur, err := s.Current() // r.NoError(err) -// ts := httptest.NewServer(http.FileServer(dir)) -// defer ts.Close() +// ip := cur.ImportPath // -// res, err := http.Get(ts.URL + "/public/images/mark.png") -// r.NoError(err) -// r.Equal(200, res.StatusCode) +// table := []struct { +// in string +// }{ +// {in: "/public"}, +// {in: ":" + "/public"}, +// {in: ip + ":" + "/public"}, +// } +// +// for _, tt := range table { +// s.Run(t, tt.in, func(st *testing.T) { +// +// r := require.New(st) +// +// r.NoError(s.LoadFolder()) +// +// dir, err := s.Open(tt.in) +// r.NoError(err) +// defer dir.Close() +// +// ts := httptest.NewServer(http.FileServer(dir)) +// defer ts.Close() +// +// res, err := http.Get(ts.URL + "/images/mark.png") +// r.NoError(err) +// r.Equal(200, res.StatusCode) +// +// b, err := ioutil.ReadAll(res.Body) +// r.NoError(err) +// +// body := string(b) +// r.Contains(body, `!/public/images/mark.png`) +// }) +// } // -// b, err := ioutil.ReadAll(res.Body) -// r.NoError(err) -// r.Contains(string(b), `!/public/images/mark.png`) // } + // // func (s Suite) Test_HTTP_Dir_Memory_StripPrefix(t *testing.T) { // r := require.New(t)