Commit f0ce712f authored by ale's avatar ale

Fix the status template (and add a test)

parent d65d469d
Pipeline #2708 passed with stages
in 4 minutes and 39 seconds
......@@ -272,21 +272,21 @@ var _templatesIndexHtml = []byte(`<!DOCTYPE html>
{{$domain := .Domain}}
{{range .Mounts}}
<li>
<a href="http://{{$domain}}{{.Mount.Name}}"
<a href="http://{{$domain}}{{.Mount.Path}}"
{{if .Mount.RelayUrl}}
data-toggle="tooltip" data-delay="300" title="relay of {{.Mount.RelayUrl}}"
{{end}}
>{{.Mount.Name}}</a>
<a href="http://{{$domain}}{{.Mount.Name}}.m3u">(m3u)</a>
>{{.Mount.Path}}</a>
<a href="http://{{$domain}}{{.Mount.Path}}.m3u">(m3u)</a>
<span class="badge">{{.Listeners}}</span>
{{if .TransMounts}}
<ul>
{{range .TransMounts}}
<li>
<a href="http://{{$domain}}{{.Mount.Name}}"
<a href="http://{{$domain}}{{.Mount.Path}}"
data-toggle="tooltip" data-delay="300" title="{{.Mount.Transcoding.String}}"
>{{.Mount.Name}}</a>
<a href="http://{{$domain}}{{.Mount.Name}}.m3u">(m3u)</a>
>{{.Mount.Path}}</a>
<a href="http://{{$domain}}{{.Mount.Path}}.m3u">(m3u)</a>
<span class="badge">{{.Listeners}}</span>
</li>
{{end}}
......@@ -339,7 +339,7 @@ func templatesIndexHtml() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "templates/index.html", size: 2567, mode: os.FileMode(420), modTime: time.Unix(1543702463, 0)}
info := bindataFileInfo{name: "templates/index.html", size: 2567, mode: os.FileMode(420), modTime: time.Unix(1555111991, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
......
......@@ -5,11 +5,15 @@ import (
"fmt"
"log"
"net"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"
"git.autistici.org/ale/autoradio"
pb "git.autistici.org/ale/autoradio/proto"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/clientv3/concurrency"
"go.etcd.io/etcd/embed"
"go.etcd.io/etcd/etcdserver/api/v3client"
......@@ -33,6 +37,7 @@ func TestNode(t *testing.T) {
if err != nil {
t.Fatalf("StartEtcd: %v", err)
}
defer e.Close()
<-e.Server.ReadyNotify()
cli := v3client.New(e.Server)
......@@ -70,3 +75,59 @@ func TestNode(t *testing.T) {
n.Wait()
}
}
func TestNode_StatusPage(t *testing.T) {
cfg := embed.NewConfig()
cfg.Dir = "default.etcd"
defer os.RemoveAll(cfg.Dir)
e, err := embed.StartEtcd(cfg)
if err != nil {
t.Fatalf("StartEtcd: %v", err)
}
defer e.Close()
<-e.Server.ReadyNotify()
cli := v3client.New(e.Server)
session, _ := concurrency.NewSession(cli, concurrency.WithTTL(2))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Create a new Mount
m := &pb.Mount{
Path: "/test.ogg",
SourceUsername: "user",
SourcePassword: "pass",
}
mdata, _ := proto.Marshal(m)
_, err = cli.Put(ctx, autoradio.MountPrefix+"test.ogg", string(mdata))
if err != nil {
t.Fatalf("Put error: %v", err)
}
n, err := New(
ctx,
session,
&fakeIcecast{},
"node1",
[]net.IP{net.ParseIP("127.0.0.1")},
net.ParseIP("127.0.0.1"),
4014,
"random",
0, 0,
)
if err != nil {
t.Fatalf("NewNode: %v", err)
}
httpSrv := httptest.NewServer(newHTTPHandler(n, 8080, "example.com"))
resp, err := http.Get(httpSrv.URL)
if err != nil {
t.Fatalf("http.Get error: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
t.Fatalf("HTTP response: %s", resp.Status)
}
}
......@@ -78,17 +78,22 @@ func (s *Server) Wait() error {
// NewServer creates a new Server. Will use publicAddrs / peerAddr to
// build all the necessary addr/port combinations.
//
// The main http handler will bind on all available interfaces. The
// DNS servers will bind only to the publicAddrs (both TCP and
// UDP). The metrics and the status services, which are internal, will
// bind on peerAddr.
func NewServer(n *Node, domain string, nameservers []string, publicAddrs []net.IP, peerAddr net.IP, httpPort, dnsPort, gossipPort, icecastPort, metricsPort int) *Server {
httpHandler := newHTTPHandler(n, icecastPort, domain)
dnsHandler := newDNSHandler(n, domain, nameservers)
servers := []genericServer{
newStatusServer(mkaddr(peerAddr, gossipPort), n.statusMgr),
newHTTPServer("main", fmt.Sprintf(":%d", httpPort), httpHandler),
newHTTPServer("metrics", fmt.Sprintf(":%d", metricsPort), newMetricsHandler()),
}
for _, ip := range publicAddrs {
servers = append(servers,
newHTTPServer("main", mkaddr(ip, httpPort), httpHandler),
newDNSServer("dns(udp)", mkaddr(ip, dnsPort), "udp", dnsHandler),
newDNSServer("dns(tcp)", mkaddr(ip, dnsPort), "tcp", dnsHandler),
)
......
......@@ -25,21 +25,21 @@
{{$domain := .Domain}}
{{range .Mounts}}
<li>
<a href="http://{{$domain}}{{.Mount.Name}}"
<a href="http://{{$domain}}{{.Mount.Path}}"
{{if .Mount.RelayUrl}}
data-toggle="tooltip" data-delay="300" title="relay of {{.Mount.RelayUrl}}"
{{end}}
>{{.Mount.Name}}</a>
<a href="http://{{$domain}}{{.Mount.Name}}.m3u">(m3u)</a>
>{{.Mount.Path}}</a>
<a href="http://{{$domain}}{{.Mount.Path}}.m3u">(m3u)</a>
<span class="badge">{{.Listeners}}</span>
{{if .TransMounts}}
<ul>
{{range .TransMounts}}
<li>
<a href="http://{{$domain}}{{.Mount.Name}}"
<a href="http://{{$domain}}{{.Mount.Path}}"
data-toggle="tooltip" data-delay="300" title="{{.Mount.Transcoding.String}}"
>{{.Mount.Name}}</a>
<a href="http://{{$domain}}{{.Mount.Name}}.m3u">(m3u)</a>
>{{.Mount.Path}}</a>
<a href="http://{{$domain}}{{.Mount.Path}}.m3u">(m3u)</a>
<span class="badge">{{.Listeners}}</span>
</li>
{{end}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment