From 33e29b61f45de90825f6d5fd439c09efe8f61e67 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 15 Oct 2019 17:12:46 -0400 Subject: [PATCH] don't get me wrong --- examples/app/go.sum | 1 + examples/app/main.go | 2 +- go.sum | 3 +++ pkging/mem/mem.go | 8 +++++++- pkging/mem/mem_test.go | 28 ---------------------------- pkging/pkgtest/http.go | 12 +++++++++--- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/examples/app/go.sum b/examples/app/go.sum index a4282e2..b14b7d1 100644 --- a/examples/app/go.sum +++ b/examples/app/go.sum @@ -580,6 +580,7 @@ github.com/markbates/deplist v1.0.5/go.mod h1:gRRbPbbuA8TmMiRvaOzUlRfzfjeCCBqX2A github.com/markbates/deplist v1.1.3/go.mod h1:BF7ioVzAJYEtzQN/os4rt8H8Ti3h0T7EoN+7eyALktE= github.com/markbates/deplist v1.2.0/go.mod h1:dtsWLZ5bWoazbM0rCxZncQaAPifWbvHgBJk8UNI1Yfk= github.com/markbates/deplist v1.3.0/go.mod h1:dtsWLZ5bWoazbM0rCxZncQaAPifWbvHgBJk8UNI1Yfk= +github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI= github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc= github.com/markbates/going v1.0.2/go.mod h1:UWCk3zm0UKefHZ7l8BNqi26UyiEMniznk8naLdTcy6c= github.com/markbates/going v1.0.3/go.mod h1:fQiT6v6yQar9UD6bd/D4Z5Afbk9J6BBVBtLiyY4gp2o= diff --git a/examples/app/main.go b/examples/app/main.go index 0e9dc7d..c03fa87 100644 --- a/examples/app/main.go +++ b/examples/app/main.go @@ -43,7 +43,7 @@ func main() { // : - seperator between the module/package name, pkg, and the "file path" // path - this is the ABSOLUTE path to the file/directory you want, as relative // to the root of the module/package's go.mod file. - dir, err := pkger.Open("github.com/markbates/pkger/examples/app:/public") + dir, err := pkger.Open("github.com/gobuffalo/buffalo:/plugins") if err != nil { log.Fatal(err) } diff --git a/go.sum b/go.sum index 47ebe53..c108def 100644 --- a/go.sum +++ b/go.sum @@ -268,6 +268,7 @@ github.com/gobuffalo/httptest v1.0.6/go.mod h1:7T1IbSrg60ankme0aDLVnEY0h056g9M1/ github.com/gobuffalo/httptest v1.1.0/go.mod h1:BIfCgiqCOotRc5xYwCcZN7IFYag4277Ynqjar/Ra3iI= github.com/gobuffalo/httptest v1.2.0/go.mod h1:0KfourZCsapuvkljDMSr7YM+66kCt/rXv54YcWRWwhc= github.com/gobuffalo/httptest v1.3.0/go.mod h1:Y4qebOsMH91XdB0cZuS8OUdAKHGV7hVDcjgzGupoYlk= +github.com/gobuffalo/httptest v1.4.0 h1:DaoTl/2iFRTk9Uau6b0Lh644tcbRtBNMHcWg6WhieS8= github.com/gobuffalo/httptest v1.4.0/go.mod h1:VDkgCFmIxAunkLNts49TC949NRLTtvyLKuN67o6hrXM= github.com/gobuffalo/licenser v0.0.0-20180924033006-eae28e638a42/go.mod h1:Ubo90Np8gpsSZqNScZZkVXXAo5DGhTb+WYFIjlnog8w= github.com/gobuffalo/licenser v0.0.0-20181025145548-437d89de4f75/go.mod h1:x3lEpYxkRG/XtGCUNkio+6RZ/dlOvLzTI9M1auIwFcw= @@ -367,6 +368,7 @@ github.com/gobuffalo/packr v1.21.9/go.mod h1:GC76q6nMzRtR+AEN/VV4w0z2/4q7SOaEmXh github.com/gobuffalo/packr v1.22.0/go.mod h1:Qr3Wtxr3+HuQEwWqlLnNW4t1oTvK+7Gc/Rnoi/lDFvA= github.com/gobuffalo/packr v1.24.0/go.mod h1:p9Sgang00I1hlr1ub+tgI9AQdFd4f+WH1h62jYpzetM= github.com/gobuffalo/packr v1.24.1/go.mod h1:absPnW/XUUa4DmIh5ga7AipGXXg0DOcd5YWKk5RZs8Y= +github.com/gobuffalo/packr v1.25.0 h1:NtPK45yOKFdTKHTvRGKL+UIKAKmJVWIVJOZBDI/qEdY= github.com/gobuffalo/packr v1.25.0/go.mod h1:NqsGg8CSB2ZD+6RBIRs18G7aZqdYDlYNNvsSqP6T4/U= github.com/gobuffalo/packr/v2 v2.0.0-rc.5/go.mod h1:e6gmOfhf3KmT4zl2X/NDRSfBXk2oV4TXZ+NNOM0xwt8= github.com/gobuffalo/packr/v2 v2.0.0-rc.7/go.mod h1:BzhceHWfF3DMAkbPUONHYWs63uacCZxygFY1b4H9N2A= @@ -392,6 +394,7 @@ github.com/gobuffalo/packr/v2 v2.4.0/go.mod h1:ra341gygw9/61nSjAbfwcwh8IrYL4WmR4 github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw= github.com/gobuffalo/packr/v2 v2.5.2/go.mod h1:sgEE1xNZ6G0FNN5xn9pevVu4nywaxHvgup67xisti08= github.com/gobuffalo/packr/v2 v2.5.3/go.mod h1:sgEE1xNZ6G0FNN5xn9pevVu4nywaxHvgup67xisti08= +github.com/gobuffalo/packr/v2 v2.6.0 h1:EMUzJIb5rof6r087PtGmgdzdLKpRBESJ/8jyL9MexfY= github.com/gobuffalo/packr/v2 v2.6.0/go.mod h1:sgEE1xNZ6G0FNN5xn9pevVu4nywaxHvgup67xisti08= github.com/gobuffalo/plush v3.7.16+incompatible/go.mod h1:rQ4zdtUUyZNqULlc6bqd5scsPfLKfT0+TGMChgduDvI= github.com/gobuffalo/plush v3.7.20+incompatible/go.mod h1:rQ4zdtUUyZNqULlc6bqd5scsPfLKfT0+TGMChgduDvI= diff --git a/pkging/mem/mem.go b/pkging/mem/mem.go index 921d697..30e3ac3 100644 --- a/pkging/mem/mem.go +++ b/pkging/mem/mem.go @@ -1,6 +1,7 @@ package mem import ( + "bytes" "encoding/json" "fmt" "io" @@ -166,10 +167,12 @@ func (fx *Pkger) Add(f pkging.File) error { } if !info.IsDir() { - _, err = io.Copy(mf, f) + bb := &bytes.Buffer{} + _, err = io.Copy(bb, f) if err != nil { return err } + mf.data = bb.Bytes() } fx.files.Store(mf.Path(), mf) @@ -306,6 +309,7 @@ func (fx *Pkger) Open(name string) (pkging.File, error) { return nil, err } + fmt.Println(">>>TODO pkging/mem/mem.go:309: pt ", pt) fl, ok := fx.files.Load(pt) if !ok { return nil, fmt.Errorf("could not open %s", name) @@ -322,6 +326,8 @@ func (fx *Pkger) Open(name string) (pkging.File, error) { her: f.her, } + fmt.Println(">>>TODO pkging/mem/mem.go:326: nf.info ", nf.info) + return nf, nil } diff --git a/pkging/mem/mem_test.go b/pkging/mem/mem_test.go index c9afb58..724e767 100644 --- a/pkging/mem/mem_test.go +++ b/pkging/mem/mem_test.go @@ -1,13 +1,11 @@ package mem import ( - "os" "testing" "github.com/markbates/pkger/here" "github.com/markbates/pkger/pkging" "github.com/markbates/pkger/pkging/pkgtest" - "github.com/markbates/pkger/pkging/stdos" ) func Test_Pkger(t *testing.T) { @@ -22,32 +20,6 @@ func Test_Pkger(t *testing.T) { return nil, err } - disk, err := stdos.New(info) - if err != nil { - return nil, err - } - - err = disk.Walk("/examples/app/public", func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - pt, err := disk.Parse(path) - if err != nil { - return err - } - - f, err := disk.Open(pt.String()) - if err != nil { - return err - } - defer f.Close() - if err := pkg.Add(f); err != nil { - return err - } - - return nil - }) - return pkg, nil }) if err != nil { diff --git a/pkging/pkgtest/http.go b/pkging/pkgtest/http.go index f8ab796..5eab0bd 100644 --- a/pkging/pkgtest/http.go +++ b/pkging/pkgtest/http.go @@ -1,11 +1,13 @@ package pkgtest import ( + "fmt" "io/ioutil" "net/http" "net/http/httptest" "os" "path/filepath" + "strings" "testing" "github.com/markbates/pkger/pkging" @@ -184,7 +186,9 @@ func (s Suite) Test_HTTP_File(t *testing.T) { defer os.RemoveAll(tdir) r.NoError(s.WriteFolder(tdir)) - gots := httptest.NewServer(http.FileServer(http.Dir(tdir))) + tpub := filepath.Join(tdir, "public") + fmt.Println(">>>TODO pkging/pkgtest/http.go:190: tpub ", tpub) + gots := httptest.NewServer(http.FileServer(http.Dir(tpub))) defer gots.Close() dir, err := pkg.Open(tt.in) @@ -198,7 +202,7 @@ func (s Suite) Test_HTTP_File(t *testing.T) { "/", "/index.html", "/images", - "/images/images/mark.png", + "/images/mark.png", } for _, path := range paths { @@ -216,7 +220,9 @@ func (s Suite) Test_HTTP_File(t *testing.T) { pkgbody, err := ioutil.ReadAll(pkgres.Body) r.NoError(err) - r.Equal(string(gobody), string(pkgbody)) + + exp := strings.ReplaceAll(string(gobody), tdir, "") + r.Equal(exp, string(pkgbody)) }) } })