| Jon Perritt | 59c68fc | 2014-10-06 17:32:15 -0500 | [diff] [blame] | 1 | package gophercloud | 
 | 2 |  | 
 | 3 | import ( | 
| Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 4 | 	"os" | 
 | 5 | 	"path/filepath" | 
 | 6 | 	"strings" | 
| Jon Perritt | 59c68fc | 2014-10-06 17:32:15 -0500 | [diff] [blame] | 7 | 	"testing" | 
 | 8 |  | 
| Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 9 | 	th "github.com/gophercloud/gophercloud/testhelper" | 
| Jon Perritt | 59c68fc | 2014-10-06 17:32:15 -0500 | [diff] [blame] | 10 | ) | 
 | 11 |  | 
 | 12 | func TestWaitFor(t *testing.T) { | 
| Jamie Hannaford | 3586db1 | 2014-10-28 17:29:00 +0100 | [diff] [blame] | 13 | 	err := WaitFor(5, func() (bool, error) { | 
| Jon Perritt | 59c68fc | 2014-10-06 17:32:15 -0500 | [diff] [blame] | 14 | 		return true, nil | 
 | 15 | 	}) | 
 | 16 | 	th.CheckNoErr(t, err) | 
 | 17 | } | 
| Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 18 |  | 
 | 19 | func 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 |  | 
 | 34 | func 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 | } |