-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
121 lines (108 loc) · 2.59 KB
/
utils_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//go:build unit || ci
package docweaver
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
type testStringSet struct {
key string
input []string
expected []string
}
func TestGetLoggerSet(t *testing.T) {
loggerSet := getLoggerSet()
assert.Contains(t, loggerSet.Info.Prefix(), "info")
assert.Contains(t, loggerSet.Err.Prefix(), "err")
assert.Contains(t, loggerSet.Warn.Prefix(), "warn")
}
func TestReplaceLinks(t *testing.T) {
productKey := "prod-up"
testData := []struct {
version string
content string
expected string
}{
{
version: "2.0",
content: "{{docs}}/something/somewhere",
expected: fmt.Sprintf("%s/%s/2.0/something/somewhere", GetRoutePrefix(), productKey),
},
{
version: "2.0",
content: "docs/{{version}}/something/somewhere",
expected: fmt.Sprintf("%s/%s/2.0/something/somewhere", GetRoutePrefix(), productKey),
},
{
version: "v5.0",
content: "{{version}}/some-thing/somewhere",
expected: "v5.0/some-thing/somewhere",
},
{
version: "6.0-alpha",
content: "{{version}}/some-thing/somewhere",
expected: "6.0-alpha/some-thing/somewhere",
},
}
for _, td := range testData {
assert.Equal(t, td.expected, replaceLinks(productKey, td.version, td.content))
}
}
func TestSortVersions(t *testing.T) {
testData := []testStringSet{
{
key: "1",
input: []string{"1.0", "2.0-beta", "master", "main", "10.0", "20", "2"},
expected: []string{"1.0", "2.0-beta", "2", "10.0", "20", "master", "main"},
},
{
key: "2",
input: []string{"1.0", "3.0-beta", "main", "10.0", "20.5", "200"},
expected: []string{"1.0", "3.0-beta", "10.0", "20.5", "200", "main"},
},
{
key: "3",
input: []string{"1.0", "3.0-beta", "main", "10.0", "0.0200"},
expected: []string{"0.0200", "1.0", "3.0-beta", "10.0", "main"},
},
}
for _, td := range testData {
t.Run(td.key, func(t *testing.T) {
sortVersions(td.input)
assert.Equal(t, fmt.Sprintf("%s", td.expected), fmt.Sprintf("%s", td.input))
})
}
}
func TestLatestVersion(t *testing.T) {
testData := []struct {
input []string
expected string
}{
{
[]string{"1.0", "3.0-beta", "main", "10.0", "0.0200"},
"10.0",
},
{
[]string{"feature/foo", "v1.5", "1.0", "1.04", "master", "develop"},
"v1.5",
},
{
[]string{"0.1-beta", "0.1-alpha", "main"},
"0.1-beta",
},
{
[]string{"master", "main"},
"N/A",
},
{
[]string{},
"N/A",
},
}
for _, td := range testData {
t.Run(td.expected, func(t *testing.T) {
result := latestVersion(td.input)
assert.Equal(t, td.expected, result)
})
}
}