-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathversion_test.go
52 lines (43 loc) · 1.06 KB
/
version_test.go
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
package gorillaz
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"reflect"
"testing"
)
func TestVersionInfo(t *testing.T) {
description := "wonderful_application"
name := "srv-tasty"
version := "v0.3.1-rc1"
// in a normal setup, these values will be set at build time
ApplicationDescription = description
ApplicationName = name
ApplicationVersion = version
g := New(WithServiceName("tasty-service"))
<-g.Run()
url := fmt.Sprintf("http://localhost:%d/info", g.HttpPort())
resp, err := http.Get(url)
if err != nil {
t.Fatalf("unexpected error, %+v", err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatalf("failed to read body payload, %+v", err)
}
expectedInfo := Info{App: App{
Description: description,
Name: name,
Version: version,
}}
var info Info
err = json.Unmarshal(b, &info)
if err != nil {
t.Fatalf("failed to unmarshal response into Json, %+v", err)
}
if !reflect.DeepEqual(info, expectedInfo) {
t.Errorf("expected response %+v but got %+v", expectedInfo, info)
}
}