TestGetCurrentRepoSlug tests that the cached version calls the underlying function only once
(t *testing.T)
| 8 | |
| 9 | // TestGetCurrentRepoSlug tests that the cached version calls the underlying function only once |
| 10 | func TestGetCurrentRepoSlug(t *testing.T) { |
| 11 | // Clear the cache before testing |
| 12 | ClearCurrentRepoSlugCache() |
| 13 | |
| 14 | // Note: In a real-world scenario, we would use dependency injection or interfaces |
| 15 | // For this test, we'll just verify that multiple calls to GetCurrentRepoSlug |
| 16 | // produce the same result (which implies caching is working) |
| 17 | |
| 18 | // First call |
| 19 | result1, err1 := GetCurrentRepoSlug() |
| 20 | if err1 != nil { |
| 21 | t.Logf("First call error (expected if not in a git repo): %v", err1) |
| 22 | } |
| 23 | |
| 24 | // Second call |
| 25 | result2, err2 := GetCurrentRepoSlug() |
| 26 | if err2 != nil { |
| 27 | t.Logf("Second call error (expected if not in a git repo): %v", err2) |
| 28 | } |
| 29 | |
| 30 | // Both calls should return the same result and same error |
| 31 | if result1 != result2 { |
| 32 | t.Errorf("GetCurrentRepoSlug returned different results on multiple calls: %s vs %s", result1, result2) |
| 33 | } |
| 34 | |
| 35 | if (err1 == nil) != (err2 == nil) { |
| 36 | t.Errorf("GetCurrentRepoSlug returned different error states on multiple calls") |
| 37 | } |
| 38 | |
| 39 | if err1 != nil && err2 != nil && err1.Error() != err2.Error() { |
| 40 | t.Errorf("GetCurrentRepoSlug returned different errors on multiple calls: %v vs %v", err1, err2) |
| 41 | } |
| 42 | |
| 43 | t.Logf("GetCurrentRepoSlug returned consistent results (result: %s, error: %v)", result1, err1) |
| 44 | } |
| 45 | |
| 46 | // TestGetCurrentRepoSlugFormat tests the format validation |
| 47 | func TestGetCurrentRepoSlugFormat(t *testing.T) { |
nothing calls this directly
no test coverage detected