|
1 | 1 | package sync |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "testing" |
5 | 6 | "time" |
6 | 7 |
|
@@ -158,7 +159,98 @@ func TestNewDBMetricsAdapter(t *testing.T) { |
158 | 159 | t.Parallel() |
159 | 160 |
|
160 | 161 | testDB := db.TestDB(t) |
161 | | - repo := db.NewBroadcastSyncRepo(testDB) |
162 | | - adapter := NewDBMetricsAdapter(repo) |
| 162 | + syncRepo := db.NewBroadcastSyncRepo(testDB) |
| 163 | + repoRepo := db.NewRepoRepository(testDB) |
| 164 | + targetRepo := db.NewTargetRepository(testDB) |
| 165 | + groupRepo := db.NewGroupRepository(testDB) |
| 166 | + adapter := NewDBMetricsAdapter(syncRepo, repoRepo, targetRepo, groupRepo) |
163 | 167 | require.NotNil(t, adapter) |
164 | 168 | } |
| 169 | + |
| 170 | +func TestDBMetricsAdapter_LookupGroupID_NotConfigured(t *testing.T) { |
| 171 | + t.Parallel() |
| 172 | + |
| 173 | + testDB := db.TestDB(t) |
| 174 | + syncRepo := db.NewBroadcastSyncRepo(testDB) |
| 175 | + adapter := NewDBMetricsAdapter(syncRepo, nil, nil, nil) |
| 176 | + |
| 177 | + _, err := adapter.LookupGroupID(context.Background(), "some-group") |
| 178 | + require.Error(t, err) |
| 179 | + assert.Contains(t, err.Error(), "group repository not configured") |
| 180 | +} |
| 181 | + |
| 182 | +func TestDBMetricsAdapter_LookupRepoID_NotConfigured(t *testing.T) { |
| 183 | + t.Parallel() |
| 184 | + |
| 185 | + testDB := db.TestDB(t) |
| 186 | + syncRepo := db.NewBroadcastSyncRepo(testDB) |
| 187 | + adapter := NewDBMetricsAdapter(syncRepo, nil, nil, nil) |
| 188 | + |
| 189 | + _, err := adapter.LookupRepoID(context.Background(), "org/repo") |
| 190 | + require.Error(t, err) |
| 191 | + assert.Contains(t, err.Error(), "repo repository not configured") |
| 192 | +} |
| 193 | + |
| 194 | +func TestDBMetricsAdapter_LookupTargetID_NotConfigured(t *testing.T) { |
| 195 | + t.Parallel() |
| 196 | + |
| 197 | + testDB := db.TestDB(t) |
| 198 | + syncRepo := db.NewBroadcastSyncRepo(testDB) |
| 199 | + adapter := NewDBMetricsAdapter(syncRepo, nil, nil, nil) |
| 200 | + |
| 201 | + _, err := adapter.LookupTargetID(context.Background(), 1, "org/repo") |
| 202 | + require.Error(t, err) |
| 203 | + assert.Contains(t, err.Error(), "target repository not configured") |
| 204 | +} |
| 205 | + |
| 206 | +func TestDBMetricsAdapter_LookupRepoID_InvalidFormat(t *testing.T) { |
| 207 | + t.Parallel() |
| 208 | + |
| 209 | + testDB := db.TestDB(t) |
| 210 | + syncRepo := db.NewBroadcastSyncRepo(testDB) |
| 211 | + repoRepo := db.NewRepoRepository(testDB) |
| 212 | + adapter := NewDBMetricsAdapter(syncRepo, repoRepo, nil, nil) |
| 213 | + |
| 214 | + _, err := adapter.LookupRepoID(context.Background(), "invalid-no-slash") |
| 215 | + require.Error(t, err) |
| 216 | + assert.Contains(t, err.Error(), "invalid repo full name") |
| 217 | +} |
| 218 | + |
| 219 | +func TestDBMetricsAdapter_LookupGroupID_NotFound(t *testing.T) { |
| 220 | + t.Parallel() |
| 221 | + |
| 222 | + testDB := db.TestDB(t) |
| 223 | + syncRepo := db.NewBroadcastSyncRepo(testDB) |
| 224 | + groupRepo := db.NewGroupRepository(testDB) |
| 225 | + adapter := NewDBMetricsAdapter(syncRepo, nil, nil, groupRepo) |
| 226 | + |
| 227 | + _, err := adapter.LookupGroupID(context.Background(), "nonexistent-group") |
| 228 | + require.Error(t, err) |
| 229 | + assert.Contains(t, err.Error(), "failed to look up group") |
| 230 | +} |
| 231 | + |
| 232 | +func TestDBMetricsAdapter_LookupRepoID_NotFound(t *testing.T) { |
| 233 | + t.Parallel() |
| 234 | + |
| 235 | + testDB := db.TestDB(t) |
| 236 | + syncRepo := db.NewBroadcastSyncRepo(testDB) |
| 237 | + repoRepo := db.NewRepoRepository(testDB) |
| 238 | + adapter := NewDBMetricsAdapter(syncRepo, repoRepo, nil, nil) |
| 239 | + |
| 240 | + _, err := adapter.LookupRepoID(context.Background(), "nonexistent/repo") |
| 241 | + require.Error(t, err) |
| 242 | + assert.Contains(t, err.Error(), "failed to look up repo") |
| 243 | +} |
| 244 | + |
| 245 | +func TestDBMetricsAdapter_LookupTargetID_NotFound(t *testing.T) { |
| 246 | + t.Parallel() |
| 247 | + |
| 248 | + testDB := db.TestDB(t) |
| 249 | + syncRepo := db.NewBroadcastSyncRepo(testDB) |
| 250 | + targetRepo := db.NewTargetRepository(testDB) |
| 251 | + adapter := NewDBMetricsAdapter(syncRepo, nil, targetRepo, nil) |
| 252 | + |
| 253 | + _, err := adapter.LookupTargetID(context.Background(), 999, "nonexistent/repo") |
| 254 | + require.Error(t, err) |
| 255 | + assert.Contains(t, err.Error(), "failed to look up target") |
| 256 | +} |
0 commit comments