Skip to content

Commit

Permalink
Merge 1de5dea into 259dd6f
Browse files Browse the repository at this point in the history
  • Loading branch information
d4l3k committed Sep 29, 2018
2 parents 259dd6f + 1de5dea commit 66045ae
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go:
- tip

install:
- go get -t -v . ./pry
- go get -t -v . ./pry ./generate ./playground/server

before_install:
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
Expand All @@ -20,5 +20,6 @@ script:
- go test -v -race -coverprofile=pry.coverprofile ./pry
- go test -v -race -coverprofile=generate.coverprofile ./generate
- go test -v -race -coverprofile=main.coverprofile
- go test -v -race -coverprofile=server.coverprofile ./playground/server
- $HOME/gopath/bin/gover
- $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=gover.coverprofile
6 changes: 4 additions & 2 deletions playground/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/pkg/errors"
)

const bundlesDir = "bundles"

var bind = flag.String("bind", ":8080", "address to bind to")

func main() {
Expand Down Expand Up @@ -48,8 +50,8 @@ func normalizePackages(packages string) []string {
func generateBundle(w http.ResponseWriter, r *http.Request, packages string) (retErr error) {
pkgs := normalizePackages(packages)
hash := pkgHash(pkgs)
path := filepath.Join("bundles", hash+".wasm")
goPath := filepath.Join("bundles", hash+".go")
path := filepath.Join(bundlesDir, hash+".wasm")
goPath := filepath.Join(bundlesDir, hash+".go")
_, err := os.Stat(path)
if err == nil {
http.ServeFile(w, r, path)
Expand Down
40 changes: 40 additions & 0 deletions playground/server/server11_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// +build go1.11

package main

import (
"net/http"
"net/http/httptest"
"os"
"testing"
)

func TestGenerateBundle(t *testing.T) {
t.Parallel()

remove := func() {
if err := os.RemoveAll(bundlesDir); err != nil {
t.Fatal(err)
}
}

remove()

if err := os.MkdirAll(bundlesDir, 0755); err != nil {
t.Fatal(err)
}

r, err := http.NewRequest(http.MethodGet, "/wasm/math,fmt", nil)
if err != nil {
t.Fatal(err)
}
resp := httptest.NewRecorder()
if err := generateBundle(resp, r, "math,fmt"); err != nil {
t.Fatal(err)
}
if resp.Code != http.StatusOK {
t.Fatalf("expected StatusOK got %+v", resp.Code)
}

remove()
}
35 changes: 35 additions & 0 deletions playground/server/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"reflect"
"testing"
)

func TestNormalizePackages(t *testing.T) {
t.Parallel()

cases := []struct {
in string
want []string
}{
{
"",
nil,
},
{
"foo, bar,github.com/d4l3k/go-pry ",
[]string{
"bar",
"foo",
"github.com/d4l3k/go-pry",
},
},
}

for i, c := range cases {
out := normalizePackages(c.in)
if !reflect.DeepEqual(out, c.want) {
t.Errorf("%d. normalizePackages(%q) = %+v; not %+v", i, c.in, out, c.want)
}
}
}

0 comments on commit 66045ae

Please sign in to comment.