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