Unit tests dont need a silly sleep and vendor vue.js
parent
cc7ea37676
commit
085150a7b5
2
main.go
2
main.go
|
|
@ -11,7 +11,7 @@ func main() {
|
|||
c := config.New()
|
||||
log.Println(c)
|
||||
g := storage.NewGraph()
|
||||
if err := view.Html(g); err != nil {
|
||||
if err := view.JSON(g); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -7,13 +7,14 @@ import (
|
|||
"local/dndex/config"
|
||||
"local/dndex/storage"
|
||||
"local/dndex/storage/entity"
|
||||
"local/gziphttp"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Html(g storage.Graph) error {
|
||||
func JSON(g storage.Graph) error {
|
||||
port := config.New().Port
|
||||
log.Println("listening on", port)
|
||||
err := http.ListenAndServe(fmt.Sprintf(":%d", port), foo(g))
|
||||
|
|
@ -23,6 +24,9 @@ func Html(g storage.Graph) error {
|
|||
func foo(g storage.Graph) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
if gziphttp.Can(r) {
|
||||
w = gziphttp.New(w)
|
||||
}
|
||||
var err error
|
||||
switch path.Base(r.URL.Path) {
|
||||
case "who":
|
||||
|
|
@ -87,21 +91,14 @@ func whoOne(ctx context.Context, g storage.Graph, namespace, id string, verbose
|
|||
}
|
||||
for _, another := range ones {
|
||||
another.Connections = nil
|
||||
another.Text = ""
|
||||
for j := range one.Connections {
|
||||
if one.Connections[j].Name == another.Name {
|
||||
one.Connections[j] = entity.One{
|
||||
Relationship: one.Connections[j].Relationship,
|
||||
Type: another.Type,
|
||||
Modified: another.Modified,
|
||||
another.Relationship = one.Connections[j].Relationship
|
||||
one.Connections[j] = another
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for j, v := range one.Connections {
|
||||
v.Name = ""
|
||||
one.Connections[j] = v
|
||||
}
|
||||
}
|
||||
return one, nil
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"local/dndex/storage"
|
||||
"local/dndex/storage/entity"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -16,32 +17,28 @@ import (
|
|||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestHtml(t *testing.T) {
|
||||
func TestJSON(t *testing.T) {
|
||||
if len(os.Getenv("INTEGRATION")) == 0 {
|
||||
t.Logf("skipping because $INTEGRATION unset")
|
||||
return
|
||||
}
|
||||
|
||||
os.Args = os.Args[:1]
|
||||
|
||||
g := storage.NewGraph()
|
||||
ones := fillDB(t, g)
|
||||
want := ones[len(ones)-1]
|
||||
|
||||
go func() {
|
||||
if err := Html(g); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
time.Sleep(time.Millisecond * 250)
|
||||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/col/who?id=%s&v", config.New().Port, want.Name))
|
||||
handler := foo(g)
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d/col/who?id=%s&v", config.New().Port, want.Name), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
|
||||
var v interface{}
|
||||
if b, err := ioutil.ReadAll(resp.Body); err != nil {
|
||||
t.Fatal(err)
|
||||
if b, err := ioutil.ReadAll(w.Body); err != nil {
|
||||
t.Fatalf("failed to read all resp body: %v: %s", err, b)
|
||||
} else if err := json.Unmarshal(b, &v); err != nil {
|
||||
t.Fatalf("err unmarshalling response: %v: %s", err, b)
|
||||
}
|
||||
Loading…
Reference in New Issue