generated from gleich/go_template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
release_test.go
44 lines (36 loc) · 1.33 KB
/
release_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
package release
import (
"errors"
"strings"
"testing"
"github.com/tj/assert"
)
func TestCheckConnection(t *testing.T) {
instance := checkConnection()
assert.True(t, instance)
}
func TestConvertURL(t *testing.T) {
instance1 := convertURL("https://github.com/gleich/nuke")
assert.Equal(t, "https://api.github.com/repos/gleich/nuke/releases/latest", instance1)
instance2 := convertURL("https://github.com/gleich/nuke/")
assert.Equal(t, "https://api.github.com/repos/gleich/nuke/releases/latest", instance2)
}
func TestGetVersion(t *testing.T) {
instance, err := getVersion("https://api.github.com/repos/gleich/nuke/releases/latest")
assert.Nil(t, err)
if instance[:1] != "v" || !strings.Contains(instance, ".") {
t.Error("instance looks like this:", instance)
}
}
func TestCheck(t *testing.T) {
successInstance, successVersion, successErr := Check("v1.0.0", "https://github.com/gleich/nuke")
assert.Nil(t, successErr)
assert.True(t, successInstance)
if successVersion[:1] != "v" || !strings.Contains(successVersion, ".") {
t.Error("instance looks like this:", successVersion)
}
failedInstance, failedVersion, failedErr := Check("", "https://github.com/repos/gleich/nuke")
assert.False(t, failedInstance)
assert.Equal(t, "", failedVersion)
assert.Equal(t, errors.New("Latest release not found for given repo URL"), failedErr)
}