server tests
This commit is contained in:
parent
9ffdf3c773
commit
a841339b72
@ -117,13 +117,11 @@ func (s *Server) Start(p *cli.Context) (err error) {
|
||||
e.GET("/ws", s.projects)
|
||||
|
||||
go e.Start(string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))
|
||||
if s.Open {
|
||||
_, err = Open("http://" + string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))
|
||||
_, err = s.OpenURL("http://" + string(s.Settings.Server.Host) + ":" + strconv.Itoa(s.Settings.Server.Port))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
48
server/main_test.go
Normal file
48
server/main_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/tockins/realize/settings"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func TestServer_Start(t *testing.T) {
|
||||
s := settings.Settings{
|
||||
Server: settings.Server{
|
||||
Status: true,
|
||||
Open: false,
|
||||
Host: "localhost",
|
||||
Port: 5000,
|
||||
},
|
||||
}
|
||||
server := Server{
|
||||
Settings: &s,
|
||||
}
|
||||
err := server.Start(nil)
|
||||
host := "http://localhost:5000/"
|
||||
urls := []string{
|
||||
host,
|
||||
host+"ws",
|
||||
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",
|
||||
host+"assets/img/svg/ic_settings_black_24px.svg",
|
||||
host+"assets/img/svg/ic_fullscreen_black_24px.svg",
|
||||
host+"assets/img/svg/ic_add_black_24px.svg",
|
||||
host+"assets/img/svg/ic_keyboard_backspace_black_24px.svg",
|
||||
host+"assets/img/svg/ic_error_black_48px.svg",
|
||||
host+"assets/img/svg/ic_remove_black_24px.svg",
|
||||
host+"assets/img/svg/logo.svg",
|
||||
host+"assets/img/favicon-32x32.png",
|
||||
host+"assets/img/svg/ic_swap_vertical_circle_black_48px.svg",
|
||||
}
|
||||
for _, elm := range urls {
|
||||
_, err = http.Get(elm)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
@ -21,17 +21,17 @@ func init() {
|
||||
}
|
||||
|
||||
// Open a url in the default browser
|
||||
func Open(url string) (io.Writer, error) {
|
||||
goos := runtime.GOOS
|
||||
open, err := cmd[goos]
|
||||
func (s *Server) OpenURL(url string) (io.Writer, error) {
|
||||
if s.Open {
|
||||
open, err := cmd[runtime.GOOS]
|
||||
if !err {
|
||||
return nil, fmt.Errorf("operating system %q is not supported", goos)
|
||||
return nil, fmt.Errorf("operating system %q is not supported", runtime.GOOS)
|
||||
}
|
||||
cmd := exec.Command(open, url)
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return cmd.Stderr, err
|
||||
}
|
||||
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
28
server/open_test.go
Normal file
28
server/open_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"testing"
|
||||
//"fmt"
|
||||
"fmt"
|
||||
"github.com/tockins/realize/settings"
|
||||
)
|
||||
|
||||
func TestOpen(t *testing.T) {
|
||||
config := settings.Settings{
|
||||
Server: settings.Server{
|
||||
Open: true,
|
||||
},
|
||||
}
|
||||
s := Server{
|
||||
Settings: &config,
|
||||
}
|
||||
url := "open_test"
|
||||
out, err := s.OpenURL(url)
|
||||
if err == nil {
|
||||
t.Fatal("Unexpected, invalid url", url, err)
|
||||
}
|
||||
output := fmt.Sprint(out)
|
||||
if output == "" {
|
||||
t.Fatal("Unexpected, invalid url", url, output)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user