|
1 | 1 | package envbuilder_test
|
2 |
| - |
3 |
| -import ( |
4 |
| - "testing" |
5 |
| - |
6 |
| - "github.com/coder/envbuilder" |
7 |
| - "github.com/coder/envbuilder/constants" |
8 |
| - |
9 |
| - "github.com/stretchr/testify/require" |
10 |
| -) |
11 |
| - |
12 |
| -func TestDefaultWorkspaceFolder(t *testing.T) { |
13 |
| - t.Parallel() |
14 |
| - |
15 |
| - successTests := []struct { |
16 |
| - name string |
17 |
| - gitURL string |
18 |
| - expected string |
19 |
| - }{ |
20 |
| - { |
21 |
| - name: "HTTP", |
22 |
| - gitURL: "https://github.com/coder/envbuilder.git", |
23 |
| - expected: "/workspaces/envbuilder", |
24 |
| - }, |
25 |
| - { |
26 |
| - name: "SSH", |
27 |
| - gitURL: "[email protected]:coder/envbuilder.git", |
28 |
| - expected: "/workspaces/envbuilder", |
29 |
| - }, |
30 |
| - { |
31 |
| - name: "username and password", |
32 |
| - gitURL: "https://username:[email protected]/coder/envbuilder.git", |
33 |
| - expected: "/workspaces/envbuilder", |
34 |
| - }, |
35 |
| - { |
36 |
| - name: "fragment", |
37 |
| - gitURL: "https://github.com/coder/envbuilder.git#feature-branch", |
38 |
| - expected: "/workspaces/envbuilder", |
39 |
| - }, |
40 |
| - { |
41 |
| - name: "empty", |
42 |
| - gitURL: "", |
43 |
| - expected: constants.EmptyWorkspaceDir, |
44 |
| - }, |
45 |
| - } |
46 |
| - for _, tt := range successTests { |
47 |
| - t.Run(tt.name, func(t *testing.T) { |
48 |
| - dir, err := envbuilder.DefaultWorkspaceFolder(tt.gitURL) |
49 |
| - require.NoError(t, err) |
50 |
| - require.Equal(t, tt.expected, dir) |
51 |
| - }) |
52 |
| - } |
53 |
| - |
54 |
| - invalidTests := []struct { |
55 |
| - name string |
56 |
| - invalidURL string |
57 |
| - }{ |
58 |
| - { |
59 |
| - name: "simple text", |
60 |
| - invalidURL: "not a valid URL", |
61 |
| - }, |
62 |
| - { |
63 |
| - name: "website URL", |
64 |
| - invalidURL: "www.google.com", |
65 |
| - }, |
66 |
| - } |
67 |
| - for _, tt := range invalidTests { |
68 |
| - t.Run(tt.name, func(t *testing.T) { |
69 |
| - dir, err := envbuilder.DefaultWorkspaceFolder(tt.invalidURL) |
70 |
| - require.NoError(t, err) |
71 |
| - require.Equal(t, constants.EmptyWorkspaceDir, dir) |
72 |
| - }) |
73 |
| - } |
74 |
| -} |
0 commit comments