|
8 | 8 | "testing"
|
9 | 9 | )
|
10 | 10 |
|
11 |
| -func TestRemote(t *testing.T) { |
| 11 | +func TestRemote_HttpsGitHub(t *testing.T) { |
12 | 12 | cleanfs := map[string]string{
|
13 | 13 | "path/to/home": "",
|
14 | 14 | }
|
@@ -85,6 +85,77 @@ func TestRemote(t *testing.T) {
|
85 | 85 | }
|
86 | 86 | }
|
87 | 87 |
|
| 88 | +func TestRemote_SShGitHub(t *testing.T) { |
| 89 | + cleanfs := map[string]string{ |
| 90 | + "path/to/home": "", |
| 91 | + } |
| 92 | + cachefs := map[string]string{ |
| 93 | + "path/to/home/.helmfile/cache/ssh_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml": "foo: bar", |
| 94 | + } |
| 95 | + |
| 96 | + type testcase struct { |
| 97 | + files map[string]string |
| 98 | + expectCacheHit bool |
| 99 | + } |
| 100 | + |
| 101 | + testcases := []testcase{ |
| 102 | + {files: cleanfs, expectCacheHit: false}, |
| 103 | + {files: cachefs, expectCacheHit: true}, |
| 104 | + } |
| 105 | + |
| 106 | + for i := range testcases { |
| 107 | + testcase := testcases[i] |
| 108 | + |
| 109 | + t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) { |
| 110 | + testfs := testhelper.NewTestFs(testcase.files) |
| 111 | + |
| 112 | + hit := true |
| 113 | + |
| 114 | + get := func(wd, src, dst string) error { |
| 115 | + if wd != "path/to/home" { |
| 116 | + return fmt.Errorf("unexpected wd: %s", wd) |
| 117 | + } |
| 118 | + if src != "git::ssh://[email protected]/cloudposse/helmfiles.git?ref=0.40.0" { |
| 119 | + return fmt.Errorf("unexpected src: %s", src) |
| 120 | + } |
| 121 | + |
| 122 | + hit = false |
| 123 | + |
| 124 | + return nil |
| 125 | + } |
| 126 | + |
| 127 | + getter := &testGetter{ |
| 128 | + get: get, |
| 129 | + } |
| 130 | + remote := &Remote{ |
| 131 | + Logger: helmexec.NewLogger(os.Stderr, "debug"), |
| 132 | + Home: "path/to/home", |
| 133 | + Getter: getter, |
| 134 | + ReadFile: testfs.ReadFile, |
| 135 | + FileExists: testfs.FileExistsAt, |
| 136 | + DirExists: testfs.DirectoryExistsAt, |
| 137 | + } |
| 138 | + |
| 139 | + url := "git::ssh://[email protected]/cloudposse/helmfiles.git@releases/kiam.yaml?ref=0.40.0" |
| 140 | + file, err := remote.Locate(url) |
| 141 | + if err != nil { |
| 142 | + t.Fatalf("unexpected error: %v", err) |
| 143 | + } |
| 144 | + |
| 145 | + if file != "path/to/home/.helmfile/cache/ssh_github_com_cloudposse_helmfiles_git.ref=0.40.0/releases/kiam.yaml" { |
| 146 | + t.Errorf("unexpected file located: %s", file) |
| 147 | + } |
| 148 | + |
| 149 | + if testcase.expectCacheHit && !hit { |
| 150 | + t.Errorf("unexpected result: unexpected cache miss") |
| 151 | + } |
| 152 | + if !testcase.expectCacheHit && hit { |
| 153 | + t.Errorf("unexpected result: unexpected cache hit") |
| 154 | + } |
| 155 | + }) |
| 156 | + } |
| 157 | +} |
| 158 | + |
88 | 159 | type testGetter struct {
|
89 | 160 | get func(wd, src, dst string) error
|
90 | 161 | }
|
|
0 commit comments