tests
This commit is contained in:
parent
8b203f9bb7
commit
46db83d076
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue