blob: 6b0d734efca686595f866959da597a4476d4c6bd [file] [log] [blame]
Jon Perritt59c68fc2014-10-06 17:32:15 -05001package gophercloud
2
3import (
Pratik Mallya5fddb2a2015-09-14 14:04:49 -05004 "os"
5 "path/filepath"
6 "strings"
Jon Perritt59c68fc2014-10-06 17:32:15 -05007 "testing"
8
Jon Perritt27249f42016-02-18 10:35:59 -06009 th "github.com/gophercloud/gophercloud/testhelper"
Jon Perritt59c68fc2014-10-06 17:32:15 -050010)
11
12func TestWaitFor(t *testing.T) {
Jamie Hannaford3586db12014-10-28 17:29:00 +010013 err := WaitFor(5, func() (bool, error) {
Jon Perritt59c68fc2014-10-06 17:32:15 -050014 return true, nil
15 })
16 th.CheckNoErr(t, err)
17}
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050018
19func TestNormalizeURL(t *testing.T) {
20 urls := []string{
21 "NoSlashAtEnd",
22 "SlashAtEnd/",
23 }
24 expected := []string{
25 "NoSlashAtEnd/",
26 "SlashAtEnd/",
27 }
28 for i := 0; i < len(expected); i++ {
29 th.CheckEquals(t, expected[i], NormalizeURL(urls[i]))
30 }
31
32}
33
34func TestNormalizePathURL(t *testing.T) {
35 baseDir, _ := os.Getwd()
36
37 rawPath := "template.yaml"
38 basePath, _ := filepath.Abs(".")
39 result, _ := NormalizePathURL(basePath, rawPath)
40 expected := strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "template.yaml"}, "/")
41 th.CheckEquals(t, expected, result)
42
43 rawPath = "http://www.google.com"
44 basePath, _ = filepath.Abs(".")
45 result, _ = NormalizePathURL(basePath, rawPath)
46 expected = "http://www.google.com"
47 th.CheckEquals(t, expected, result)
48
49 rawPath = "very/nested/file.yaml"
50 basePath, _ = filepath.Abs(".")
51 result, _ = NormalizePathURL(basePath, rawPath)
52 expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "very/nested/file.yaml"}, "/")
53 th.CheckEquals(t, expected, result)
54
55 rawPath = "very/nested/file.yaml"
56 basePath = "http://www.google.com"
57 result, _ = NormalizePathURL(basePath, rawPath)
58 expected = "http://www.google.com/very/nested/file.yaml"
59 th.CheckEquals(t, expected, result)
60
61 rawPath = "very/nested/file.yaml/"
62 basePath = "http://www.google.com/"
63 result, _ = NormalizePathURL(basePath, rawPath)
64 expected = "http://www.google.com/very/nested/file.yaml"
65 th.CheckEquals(t, expected, result)
66
67 rawPath = "very/nested/file.yaml"
68 basePath = "http://www.google.com/even/more"
69 result, _ = NormalizePathURL(basePath, rawPath)
70 expected = "http://www.google.com/even/more/very/nested/file.yaml"
71 th.CheckEquals(t, expected, result)
72
73 rawPath = "very/nested/file.yaml"
74 basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/")
75 result, _ = NormalizePathURL(basePath, rawPath)
76 expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/")
77 th.CheckEquals(t, expected, result)
78
79 rawPath = "very/nested/file.yaml/"
80 basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/")
81 result, _ = NormalizePathURL(basePath, rawPath)
82 expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/")
83 th.CheckEquals(t, expected, result)
84
85}