TestCheckRemoteSymlink verifies that checkRemoteSymlink correctly classifies directories, files, and nonexistent paths when called against the GitHub Contents API.
(t *testing.T)
| 162 | // TestCheckRemoteSymlink verifies that checkRemoteSymlink correctly classifies |
| 163 | // directories, files, and nonexistent paths when called against the GitHub Contents API. |
| 164 | func TestCheckRemoteSymlink(t *testing.T) { |
| 165 | client, err := api.DefaultRESTClient() |
| 166 | if err != nil { |
| 167 | skipOnAuthError(t, err) |
| 168 | t.Fatalf("Failed to create REST client: %v", err) |
| 169 | } |
| 170 | |
| 171 | tests := []struct { |
| 172 | name string |
| 173 | dirPath string |
| 174 | wantSymlink bool |
| 175 | wantErr bool |
| 176 | }{ |
| 177 | { |
| 178 | name: "directory is not a symlink", |
| 179 | dirPath: "Global", |
| 180 | wantSymlink: false, |
| 181 | wantErr: false, |
| 182 | }, |
| 183 | { |
| 184 | name: "regular file is not a symlink", |
| 185 | dirPath: "Go.gitignore", |
| 186 | wantSymlink: false, |
| 187 | wantErr: false, |
| 188 | }, |
| 189 | { |
| 190 | name: "nonexistent path returns error", |
| 191 | dirPath: "nonexistent-path-xyz", |
| 192 | wantSymlink: false, |
| 193 | wantErr: true, |
| 194 | }, |
| 195 | } |
| 196 | |
| 197 | for _, tt := range tests { |
| 198 | t.Run(tt.name, func(t *testing.T) { |
| 199 | target, isSymlink, err := checkRemoteSymlink(client, "github", "gitignore", tt.dirPath, "main") |
| 200 | if err != nil { |
| 201 | skipOnAuthError(t, err) |
| 202 | if !tt.wantErr { |
| 203 | t.Fatalf("Unexpected error for path %q: %v", tt.dirPath, err) |
| 204 | } |
| 205 | if tt.dirPath == "nonexistent-path-xyz" { |
| 206 | assert.True(t, errorutil.IsNotFoundError(err), "Expected a not-found error, got: %v", err) |
| 207 | } |
| 208 | return |
| 209 | } |
| 210 | |
| 211 | assert.False(t, tt.wantErr, "Expected error for path %q but got none", tt.dirPath) |
| 212 | assert.Equal(t, tt.wantSymlink, isSymlink, "Symlink mismatch for path %q (target=%q)", tt.dirPath, target) |
| 213 | }) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // TestResolveRemoteSymlinksNoSymlinks verifies that resolveRemoteSymlinks walks all |
| 218 | // directory components of a real path and returns "no symlinks found" when none exist. |
nothing calls this directly
no test coverage detected