-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathversion_test.go
61 lines (48 loc) · 2.29 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
53
54
55
56
57
58
59
60
61
package gocd_test
import (
_ "embed"
"net/http"
"testing"
"github.com/nikhilsbhat/gocd-sdk-go"
"github.com/stretchr/testify/assert"
)
//go:embed internal/fixtures/version.json
var versionInfo string
func Test_config_GetVersionInfo(t *testing.T) {
correctVersionHeader := map[string]string{"Accept": gocd.HeaderVersionOne}
t.Run("should error out while fetching version information from server", func(t *testing.T) {
client := gocd.NewClient("http://localhost:8156/go", auth, "info", nil)
client.SetRetryCount(1)
client.SetRetryWaitTime(1)
actual, err := client.GetVersionInfo()
assert.EqualError(t, err, "call made to get version information errored with: "+
"Get \"http://localhost:8156/go/api/version\": dial tcp [::1]:8156: connect: connection refused")
assert.Equal(t, gocd.VersionInfo{}, actual)
})
t.Run("should error out while fetching version information as server returned non 200 status code", func(t *testing.T) {
server := mockServer([]byte("backupJSON"), http.StatusBadGateway, correctVersionHeader, false, nil)
client := gocd.NewClient(server.URL, auth, "info", nil)
actual, err := client.GetVersionInfo()
assert.EqualError(t, err, "got 502 from GoCD while making GET call for "+server.URL+"/api/version\nwith BODY:backupJSON")
assert.Equal(t, gocd.VersionInfo{}, actual)
})
t.Run("should error out while fetching version information as server returned malformed response", func(t *testing.T) {
server := mockServer([]byte(`{"email_on_failure"}`), http.StatusOK, correctVersionHeader, false, nil)
client := gocd.NewClient(server.URL, auth, "info", nil)
actual, err := client.GetVersionInfo()
assert.EqualError(t, err, "reading response body errored with: invalid character '}' after object key")
assert.Equal(t, gocd.VersionInfo{}, actual)
})
t.Run("should be able to fetch the version info", func(t *testing.T) {
server := mockServer([]byte(versionInfo), http.StatusOK, correctVersionHeader, false, nil)
client := gocd.NewClient(server.URL, auth, "info", nil)
expected := gocd.VersionInfo{
Version: "16.6.0",
FullVersion: "16.6.0 (3348-a7a5717cbd60c30006314fb8dd529796c93adaf0)",
GitSHA: "a7a5717cbd60c30006314fb8dd529796c93adaf0",
}
actual, err := client.GetVersionInfo()
assert.NoError(t, err)
assert.Equal(t, expected, actual)
})
}