blob: 5985bc3ab29d9ecbe9034576da244f251285fc84 [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
Jon Perritt59c68fc2014-10-06 17:32:15 -05002
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
jrperritt3d966162016-06-06 14:08:54 -05009 "github.com/gophercloud/gophercloud"
Jon Perritt27249f42016-02-18 10:35:59 -060010 th "github.com/gophercloud/gophercloud/testhelper"
Jon Perritt59c68fc2014-10-06 17:32:15 -050011)
12
13func TestWaitFor(t *testing.T) {
jrperritt3d966162016-06-06 14:08:54 -050014 err := gophercloud.WaitFor(5, func() (bool, error) {
Jon Perritt59c68fc2014-10-06 17:32:15 -050015 return true, nil
16 })
17 th.CheckNoErr(t, err)
18}
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050019
20func TestNormalizeURL(t *testing.T) {
21 urls := []string{
22 "NoSlashAtEnd",
23 "SlashAtEnd/",
24 }
25 expected := []string{
26 "NoSlashAtEnd/",
27 "SlashAtEnd/",
28 }
29 for i := 0; i < len(expected); i++ {
jrperritt3d966162016-06-06 14:08:54 -050030 th.CheckEquals(t, expected[i], gophercloud.NormalizeURL(urls[i]))
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050031 }
32
33}
34
35func TestNormalizePathURL(t *testing.T) {
36 baseDir, _ := os.Getwd()
37
38 rawPath := "template.yaml"
39 basePath, _ := filepath.Abs(".")
jrperritt3d966162016-06-06 14:08:54 -050040 result, _ := gophercloud.NormalizePathURL(basePath, rawPath)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050041 expected := strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "template.yaml"}, "/")
42 th.CheckEquals(t, expected, result)
43
44 rawPath = "http://www.google.com"
45 basePath, _ = filepath.Abs(".")
jrperritt3d966162016-06-06 14:08:54 -050046 result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050047 expected = "http://www.google.com"
48 th.CheckEquals(t, expected, result)
49
50 rawPath = "very/nested/file.yaml"
51 basePath, _ = filepath.Abs(".")
jrperritt3d966162016-06-06 14:08:54 -050052 result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050053 expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "very/nested/file.yaml"}, "/")
54 th.CheckEquals(t, expected, result)
55
56 rawPath = "very/nested/file.yaml"
57 basePath = "http://www.google.com"
jrperritt3d966162016-06-06 14:08:54 -050058 result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050059 expected = "http://www.google.com/very/nested/file.yaml"
60 th.CheckEquals(t, expected, result)
61
62 rawPath = "very/nested/file.yaml/"
63 basePath = "http://www.google.com/"
jrperritt3d966162016-06-06 14:08:54 -050064 result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050065 expected = "http://www.google.com/very/nested/file.yaml"
66 th.CheckEquals(t, expected, result)
67
68 rawPath = "very/nested/file.yaml"
69 basePath = "http://www.google.com/even/more"
jrperritt3d966162016-06-06 14:08:54 -050070 result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050071 expected = "http://www.google.com/even/more/very/nested/file.yaml"
72 th.CheckEquals(t, expected, result)
73
74 rawPath = "very/nested/file.yaml"
75 basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/")
jrperritt3d966162016-06-06 14:08:54 -050076 result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050077 expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/")
78 th.CheckEquals(t, expected, result)
79
80 rawPath = "very/nested/file.yaml/"
81 basePath = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more"}, "/")
jrperritt3d966162016-06-06 14:08:54 -050082 result, _ = gophercloud.NormalizePathURL(basePath, rawPath)
Pratik Mallya5fddb2a2015-09-14 14:04:49 -050083 expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/")
84 th.CheckEquals(t, expected, result)
85
86}