scooter  ·  2026-04-13

shortid_integration_test.go

 1//go:build integration
 2// +build integration
 3
 4package main
 5
 6import (
 7	"testing"
 8)
 9
10// TestGenerate_Integration tests the Generate method with a real git-bug repo.
11// This test requires a git repository with git-bug data at the specified path.
12// Run with: go test -tags=integration -v ./...
13func TestGenerate_Integration(t *testing.T) {
14	// This is a placeholder - in practice, you'd need to set up a test repo
15	// or use an environment variable to specify the repo path
16	repoPath := "."
17
18	gen := NewShortIDGenerator(repoPath)
19	m, err := gen.Generate()
20	if err != nil {
21		// It's okay if there's no git-bug data, just skip
22		t.Skipf("Skipping integration test - no git-bug data: %v", err)
23	}
24
25	// Verify we can get short IDs for all full IDs
26	for fullID, shortID := range m.fullToShort {
27		gotShortID, err := m.GetShortID(fullID)
28		if err != nil {
29			t.Errorf("GetShortID(%q) failed: %v", fullID, err)
30			continue
31		}
32		if gotShortID != shortID {
33			t.Errorf("GetShortID(%q) = %q, want %q", fullID, gotShortID, shortID)
34		}
35
36		// Verify we can reverse it
37		gotFullID, err := m.GetFullID(shortID)
38		if err != nil {
39			t.Errorf("GetFullID(%q) failed: %v", shortID, err)
40			continue
41		}
42		if gotFullID != fullID {
43			t.Errorf("GetFullID(%q) = %q, want %q", shortID, gotFullID, fullID)
44		}
45	}
46}