Something went wrong. Try again.
bluesky viewer in the terminal
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768package utils
import ( "bytes" "database/sql" "io" "os" "path/filepath" "testing"
_ "github.com/mattn/go-sqlite3")
// CaptureOutput captures stdout during function executionfunc CaptureOutput(f func()) string { old := os.Stdout r, w, _ := os.Pipe() os.Stdout = w
f()
w.Close() os.Stdout = old
var buf bytes.Buffer io.Copy(&buf, r) return buf.String()}
// NewTestDB creates an in-memory SQLite database for testing.// Returns the database connection and a cleanup function.// The cleanup function should be called with defer to ensure proper cleanup.func NewTestDB(t *testing.T) (*sql.DB, func()) { t.Helper()
db, err := sql.Open("sqlite3", ":memory:") if err != nil { t.Fatalf("failed to open in-memory database: %v", err) }
cleanup := func() { if err := db.Close(); err != nil { t.Errorf("failed to close test database: %v", err) } }
return db, cleanup}
// setupTestConfig creates a test config directory and returns cleanup functionfunc SetupTestConfig(t *testing.T) (string, func()) { tmpDir := t.TempDir() originalHome := os.Getenv("HOME")
os.Setenv("HOME", tmpDir)
configDir := filepath.Join(tmpDir, ".skycli") if err := os.MkdirAll(configDir, 0755); err != nil { t.Fatalf("failed to create test config dir: %v", err) }
cleanup := func() { os.Setenv("HOME", originalHome) }
return configDir, cleanup}