From 46db83d07608d65677182c00bb726edc6d5a51d4 Mon Sep 17 00:00:00 2001 From: asoseil Date: Sun, 3 Dec 2017 19:06:49 +0100 Subject: [PATCH] tests --- realize/server.go | 4 +++- realize/server_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++ realize/settings.go | 19 ------------------ 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/realize/server.go b/realize/server.go index 6af1354..383fabc 100644 --- a/realize/server.go +++ b/realize/server.go @@ -152,7 +152,9 @@ func (s *Server) Start() (err error) { e.GET("/ws", s.projects) e.HideBanner = true e.Debug = false - go e.Start(string(s.Parent.Server.Host) + ":" + strconv.Itoa(s.Parent.Server.Port)) + go func() { + e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port)) + }() return nil } diff --git a/realize/server_test.go b/realize/server_test.go index 4b7b005..31ff27a 100644 --- a/realize/server_test.go +++ b/realize/server_test.go @@ -1 +1,45 @@ package realize + +import ( + "testing" + "net/http" + "runtime" +) +func TestServer_Start(t *testing.T) { + s := Server{ + Host: "localhost", + Port: 5000, + } + host := "http://localhost:5000/" + urls := []string{ + host, + host + "assets/js/all.min.js", + host + "assets/css/app.css", + host + "app/components/settings/index.html", + host + "app/components/project/index.html", + host + "app/components/project/index.html", + host + "app/components/index.html", + } + err := s.Start() + if err != nil { + t.Fatal(err) + } + for _, elm := range urls { + resp, err := http.Get(elm) + if err != nil || resp.StatusCode != 200 { + t.Fatal(err, resp.StatusCode, elm) + } + } +} + +func TestServer_Open(t *testing.T) { + cmd := map[string]string{ + "windows": "start", + "darwin": "open", + "linux": "xdg-open", + } + key := runtime.GOOS + if _, ok:= cmd[key]; !ok{ + t.Error("System not supported") + } +} \ No newline at end of file diff --git a/realize/settings.go b/realize/settings.go index acf061c..d176a48 100644 --- a/realize/settings.go +++ b/realize/settings.go @@ -4,7 +4,6 @@ import ( "gopkg.in/yaml.v2" "io/ioutil" "log" - "math/rand" "os" "path/filepath" "time" @@ -56,24 +55,6 @@ type Resource struct { Name string } -// Rand is used for generate a random string -func random(n int) string { - src := rand.NewSource(time.Now().UnixNano()) - b := make([]byte, n) - for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; { - if remain == 0 { - cache, remain = src.Int63(), letterIdxMax - } - if idx := int(cache & letterIdxMask); idx < len(letterBytes) { - b[i] = letterBytes[idx] - i-- - } - cache >>= letterIdxBits - remain-- - } - return string(b) -} - // Remove realize folder func (s *Settings) Remove(d string) error { _, err := os.Stat(d)