jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 1 | package testing |
Jon Perritt | 59c68fc | 2014-10-06 17:32:15 -0500 | [diff] [blame] | 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 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 10 | th "github.com/gophercloud/gophercloud/testhelper" |
Jon Perritt | 59c68fc | 2014-10-06 17:32:15 -0500 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestWaitFor(t *testing.T) { |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 14 | err := gophercloud.WaitFor(5, func() (bool, error) { |
Jon Perritt | 59c68fc | 2014-10-06 17:32:15 -0500 | [diff] [blame] | 15 | return true, nil |
| 16 | }) |
| 17 | th.CheckNoErr(t, err) |
| 18 | } |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 19 | |
| 20 | func 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++ { |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 30 | th.CheckEquals(t, expected[i], gophercloud.NormalizeURL(urls[i])) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | } |
| 34 | |
| 35 | func TestNormalizePathURL(t *testing.T) { |
| 36 | baseDir, _ := os.Getwd() |
| 37 | |
| 38 | rawPath := "template.yaml" |
| 39 | basePath, _ := filepath.Abs(".") |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 40 | result, _ := gophercloud.NormalizePathURL(basePath, rawPath) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 41 | 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(".") |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 46 | result, _ = gophercloud.NormalizePathURL(basePath, rawPath) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 47 | expected = "http://www.google.com" |
| 48 | th.CheckEquals(t, expected, result) |
| 49 | |
| 50 | rawPath = "very/nested/file.yaml" |
| 51 | basePath, _ = filepath.Abs(".") |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 52 | result, _ = gophercloud.NormalizePathURL(basePath, rawPath) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 53 | 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" |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 58 | result, _ = gophercloud.NormalizePathURL(basePath, rawPath) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 59 | 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/" |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 64 | result, _ = gophercloud.NormalizePathURL(basePath, rawPath) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 65 | 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" |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 70 | result, _ = gophercloud.NormalizePathURL(basePath, rawPath) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 71 | 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"}, "/") |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 76 | result, _ = gophercloud.NormalizePathURL(basePath, rawPath) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 77 | 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"}, "/") |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 82 | result, _ = gophercloud.NormalizePathURL(basePath, rawPath) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 83 | expected = strings.Join([]string{"file:/", filepath.ToSlash(baseDir), "only/file/even/more/very/nested/file.yaml"}, "/") |
| 84 | th.CheckEquals(t, expected, result) |
| 85 | |
| 86 | } |