-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_test.go
87 lines (75 loc) · 2.18 KB
/
github_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"context"
"testing"
"github.com/google/go-github/v65/github"
"github.com/hashicorp/go-version"
)
func TestGetCurrentHugoVersion(t *testing.T) {
t.Parallel()
expected := "0.81.0"
var client *github.Client
var ctx = context.Background()
// for public repo, you don't need credentials
client = github.NewClient(nil)
// public repo as source
sourceOwner := "gohugoio"
sourceRepo := "hugo"
real, _, _, err := getCurrentHugoVersion(ctx, client, sourceOwner, sourceRepo)
if err != nil {
t.Fatalf("Get error %v", err)
}
expectedVersion, _ := version.NewVersion(expected)
realVersion, _ := version.NewVersion(real)
if expectedVersion.GreaterThanOrEqual(realVersion) {
t.Errorf("Real version %v is greater than expected %v)", realVersion, expectedVersion)
}
}
func TestGetCurrentDeployedVersion(t *testing.T) {
t.Parallel()
expected := "0.83.1"
var client *github.Client
var ctx = context.Background()
client = github.NewClient(nil)
real, _, err := getCurrentDeployedVersion(ctx, client, "abtris", "12ApiaryTest", "netlify.toml", "master")
if err != nil {
t.Fatalf("Get error %v", err)
}
if real != expected {
t.Errorf("Expected %v and real %v)", expected, real)
}
}
func TestIsNewVersion(t *testing.T) {
t.Parallel()
tests := []struct {
name string
hugoVersion string
netlifyVersion string
result bool
}{
{name: "Equal", hugoVersion: "0.10.1", netlifyVersion: "0.10.1", result: false},
{name: "Lower", hugoVersion: "0.10.1", netlifyVersion: "0.10.2", result: false},
{name: "New", hugoVersion: "0.10.2", netlifyVersion: "0.10.1", result: true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := isNewVersion(test.hugoVersion, test.netlifyVersion)
if result != test.result {
t.Errorf("Expected %v and real %v)", test.result, result)
}
})
}
}
func TestGetRepoPath(t *testing.T) {
t.Parallel()
input := "owner/repo"
expectedOwner := "owner"
expectedRepo := "repo"
owner, repo := getRepoPath(input)
if owner != expectedOwner {
t.Errorf("Expected %v and real %v)", expectedOwner, owner)
}
if repo != expectedRepo {
t.Errorf("Expected %v and real %v)", expectedRepo, repo)
}
}