This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
/
util_test.go
85 lines (70 loc) · 2.57 KB
/
util_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
package gophercloud
import (
"os"
"path/filepath"
"strings"
"testing"
th "github.com/rackspace/gophercloud/testhelper"
)
func TestWaitFor(t *testing.T) {
err := WaitFor(5, func() (bool, error) {
return true, nil
})
th.CheckNoErr(t, err)
}
func TestNormalizeURL(t *testing.T) {
urls := []string{
"NoSlashAtEnd",
"SlashAtEnd/",
}
expected := []string{
"NoSlashAtEnd/",
"SlashAtEnd/",
}
for i := 0; i < len(expected); i++ {
th.CheckEquals(t, expected[i], NormalizeURL(urls[i]))
}
}
func TestNormalizePathURL(t *testing.T) {
baseDir, _ := os.Getwd()
rawPath := "template.yaml"
basePath, _ := filepath.Abs(".")
result, _ := NormalizePathURL(basePath, rawPath)
expected := strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "template.yaml"}, "/")
th.CheckEquals(t, expected, result)
rawPath = "http://www.google.com"
basePath, _ = filepath.Abs(".")
result, _ = NormalizePathURL(basePath, rawPath)
expected = "http://www.google.com"
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml"
basePath, _ = filepath.Abs(".")
result, _ = NormalizePathURL(basePath, rawPath)
expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "very/nested/file.yaml"}, "/")
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml"
basePath = "http://www.google.com"
result, _ = NormalizePathURL(basePath, rawPath)
expected = "http://www.google.com/very/nested/file.yaml"
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml/"
basePath = "http://www.google.com/"
result, _ = NormalizePathURL(basePath, rawPath)
expected = "http://www.google.com/very/nested/file.yaml"
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml"
basePath = "http://www.google.com/even/more"
result, _ = NormalizePathURL(basePath, rawPath)
expected = "http://www.google.com/even/more/very/nested/file.yaml"
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml"
basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/")
result, _ = NormalizePathURL(basePath, rawPath)
expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/")
th.CheckEquals(t, expected, result)
rawPath = "very/nested/file.yaml/"
basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/")
result, _ = NormalizePathURL(basePath, rawPath)
expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/")
th.CheckEquals(t, expected, result)
}