-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpublisher_test.go
More file actions
65 lines (59 loc) · 1.57 KB
/
publisher_test.go
File metadata and controls
65 lines (59 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package server
import (
"fmt"
"net"
"net/http"
"net/http/httptest"
"testing"
)
func TestIsPublishableApp(t *testing.T) {
s := &Server{}
appName := "go_v2.web.1"
if !s.IsPublishableApp(appName) {
t.Errorf("%s should be publishable", appName)
}
badAppName := "go_v2"
if s.IsPublishableApp(badAppName) {
t.Errorf("%s should not be publishable", badAppName)
}
// publisher assumes that an app name of "test" with a null etcd client has v3 running
oldVersion := "ceci-nest-pas-une-app_v2.web.1"
if s.IsPublishableApp(oldVersion) {
t.Errorf("%s should not be publishable", oldVersion)
}
currentVersion := "ceci-nest-pas-une-app_v3.web.1"
if !s.IsPublishableApp(currentVersion) {
t.Errorf("%s should be publishable", currentVersion)
}
futureVersion := "ceci-nest-pas-une-app_v4.web.1"
if !s.IsPublishableApp(futureVersion) {
t.Errorf("%s should be publishable", futureVersion)
}
}
func TestIsPortOpen(t *testing.T) {
ln, err := net.Listen("tcp4", "127.0.0.1:0")
if err != nil {
t.Fatalf("Listen failed: %v", err)
}
defer ln.Close()
s := &Server{}
if !s.IsPortOpen(ln.Addr().String()) {
t.Errorf("Port should be open")
}
if s.IsPortOpen("127.0.0.1:-1") {
t.Errorf("Port should be closed")
}
}
func TestHealthCheckOK(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, client")
}))
defer ts.Close()
s := &Server{}
if !s.HealthCheckOK(ts.URL, 200) {
t.Errorf("Health check should be OK")
}
if s.HealthCheckOK("127.0.0.1:-1", 200) {
t.Errorf("Health check should be NOT OK")
}
}