Skip to content

Commit c64be2a

Browse files
committed
chore: remove unused code
1 parent 4cdbcc1 commit c64be2a

16 files changed

Lines changed: 88 additions & 626 deletions

File tree

internal/cli/report.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,4 @@ func Report(_ context.Context, coverageFile string, format string, outputPath st
6060
return nil
6161
}
6262

63-
// ReportSummary prints a human-readable summary of coverage
64-
func ReportSummary(coverageFile string) error {
65-
store := coverage.NewStore(coverageFile)
66-
if !store.Exists() {
67-
return fmt.Errorf("coverage file not found: %s", coverageFile)
68-
}
69-
70-
cov, err := store.Load()
71-
if err != nil {
72-
return fmt.Errorf("failed to load coverage data: %w", err)
73-
}
7463

75-
// Print overall coverage
76-
fmt.Printf("Overall Coverage: %.2f%%\n\n", cov.TotalPositionCoveragePercent())
77-
78-
// Print per-file coverage
79-
fmt.Println("File Coverage:")
80-
for file, posHits := range cov.Positions {
81-
covered := 0
82-
for _, count := range posHits {
83-
if count > 0 {
84-
covered++
85-
}
86-
}
87-
total := len(posHits)
88-
percent := cov.PositionCoveragePercent(file)
89-
90-
fmt.Printf(" %s: %.2f%% (%d/%d positions)\n", file, percent, covered, total)
91-
}
92-
93-
return nil
94-
}

internal/cli/run.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,4 @@ func Run(ctx context.Context, config *Config, searchPath string) (int, error) {
129129
return summary.ExitCode(), nil
130130
}
131131

132-
// PrintVerbose prints a message if verbose mode is enabled
133-
func PrintVerbose(config *Config, format string, args ...any) {
134-
if config.Verbose {
135-
fmt.Printf(format+"\n", args...)
136-
}
137-
}
132+

internal/coverage/collector.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,6 @@ func (c *Collector) Reset() {
8585
c.coverage = NewCoverage()
8686
}
8787

88-
// Merge merges another coverage collector's data into this one
89-
func (c *Collector) Merge(other *Collector) error {
90-
c.mu.Lock()
91-
defer c.mu.Unlock()
92-
other.mu.Lock()
93-
defer other.mu.Unlock()
94-
95-
// Merge position hit counts only
96-
for file, otherPosHits := range other.coverage.Positions {
97-
for posKey, count := range otherPosHits {
98-
// Parse position key to get startPos and length
99-
var startPos, length int
100-
_, err := fmt.Sscanf(posKey, "%d:%d", &startPos, &length)
101-
if err != nil {
102-
continue // Skip invalid keys
103-
}
104-
105-
if existingCount, exists := c.coverage.Positions[file][posKey]; exists {
106-
c.coverage.AddPosition(file, startPos, length, existingCount+count)
107-
} else {
108-
c.coverage.AddPosition(file, startPos, length, count)
109-
}
110-
}
111-
}
112-
113-
return nil
114-
}
115-
11688
// GetFilePositionCoverage returns a copy of position coverage data for a specific file
11789
func (c *Collector) GetFilePositionCoverage(filePath string) PositionHits {
11890
c.mu.Lock()

internal/coverage/collector_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
package coverage
22

33
import (
4+
"fmt"
45
"sync"
56
"testing"
67
"time"
78

89
"github.com/cybertec-postgresql/pgcov/internal/runner"
910
)
1011

12+
// merge merges another coverage collector's data into c. Used only in tests.
13+
func (c *Collector) merge(other *Collector) error {
14+
c.mu.Lock()
15+
defer c.mu.Unlock()
16+
other.mu.Lock()
17+
defer other.mu.Unlock()
18+
19+
for file, otherPosHits := range other.coverage.Positions {
20+
for posKey, count := range otherPosHits {
21+
var startPos, length int
22+
_, err := fmt.Sscanf(posKey, "%d:%d", &startPos, &length)
23+
if err != nil {
24+
continue
25+
}
26+
if existingCount, exists := c.coverage.Positions[file][posKey]; exists {
27+
c.coverage.AddPosition(file, startPos, length, existingCount+count)
28+
} else {
29+
c.coverage.AddPosition(file, startPos, length, count)
30+
}
31+
}
32+
}
33+
34+
return nil
35+
}
36+
1137
func TestNewCollector(t *testing.T) {
1238
c := NewCollector()
1339
if c == nil {
@@ -203,7 +229,7 @@ func TestCollector_Merge(t *testing.T) {
203229
_ = c2.AddSignal(runner.CoverageSignal{SignalID: "test.sql:300:70", Timestamp: now.Add(3 * time.Second)})
204230

205231
// Merge c2 into c1
206-
err := c1.Merge(c2)
232+
err := c1.merge(c2)
207233
if err != nil {
208234
t.Fatalf("Merge() error = %v", err)
209235
}

internal/coverage/store.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,4 @@ func (s *Store) Path() string {
8787
return s.filePath
8888
}
8989

90-
// SaveCollector is a convenience method to save from a collector
91-
func SaveCollector(collector *Collector, filePath string) error {
92-
store := NewStore(filePath)
93-
return store.Save(collector.Coverage())
94-
}
95-
96-
// LoadToCollector is a convenience method to load into a new collector
97-
func LoadToCollector(filePath string) (*Collector, error) {
98-
store := NewStore(filePath)
99-
coverage, err := store.Load()
100-
if err != nil {
101-
return nil, err
102-
}
103-
104-
collector := NewCollector()
105-
collector.coverage = coverage
10690

107-
return collector, nil
108-
}

internal/database/listener.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,6 @@ func (l *Listener) Close(ctx context.Context) error {
131131
return nil
132132
}
133133

134-
// WaitForSignal waits for a specific signal with timeout
135-
func (l *Listener) WaitForSignal(ctx context.Context, timeout time.Duration) (*types.CoverageSignal, error) {
136-
timer := time.NewTimer(timeout)
137-
defer timer.Stop()
138-
139-
select {
140-
case signal := <-l.signals:
141-
return &signal, nil
142-
case err := <-l.errors:
143-
return nil, err
144-
case <-timer.C:
145-
return nil, fmt.Errorf("timeout waiting for signal")
146-
case <-ctx.Done():
147-
return nil, ctx.Err()
148-
}
149-
}
150-
151134
// CollectSignals collects all signals until context is cancelled or timeout
152135
func (l *Listener) CollectSignals(ctx context.Context, timeout time.Duration) ([]types.CoverageSignal, error) {
153136
var signals []types.CoverageSignal
@@ -173,17 +156,4 @@ func (l *Listener) CollectSignals(ctx context.Context, timeout time.Duration) ([
173156
}
174157
}
175158

176-
// Ping verifies the listener connection is alive
177-
func (l *Listener) Ping(ctx context.Context) error {
178-
if l.conn == nil || l.conn.IsClosed() {
179-
return fmt.Errorf("connection is closed")
180-
}
181-
return l.conn.Ping(ctx)
182-
}
183159

184-
// SendTestNotification sends a test notification (for debugging)
185-
func SendTestNotification(ctx context.Context, conn *pgconn.PgConn, channel string, payload string) error {
186-
sql := fmt.Sprintf("NOTIFY %s, '%s'", channel, payload)
187-
_, err := conn.Exec(ctx, sql).ReadAll()
188-
return err
189-
}

internal/database/pool.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ func (e *ConnectionError) Error() string {
2727
return msg
2828
}
2929

30-
// NewConnectionError creates a new ConnectionError
31-
func NewConnectionError(host string, port int, message string) *ConnectionError {
32-
return &ConnectionError{
33-
Host: host,
34-
Port: port,
35-
Message: message,
36-
}
37-
}
38-
3930
// Pool wraps pgxpool.Pool with additional functionality
4031
type Pool struct {
4132
*pgxpool.Pool
@@ -108,11 +99,6 @@ func NewPool(ctx context.Context, config *types.Config) (*Pool, error) {
10899
}, nil
109100
}
110101

111-
// Config returns the configuration used by this pool
112-
func (p *Pool) Config() *types.Config {
113-
return p.config
114-
}
115-
116102
// Close closes the connection pool
117103
func (p *Pool) Close() {
118104
if p.Pool != nil {

internal/discovery/classifier.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,4 @@ func ClassifyPath(path string) FileType {
2929
return ClassifyFile(filepath.Base(path))
3030
}
3131

32-
// IsTestFile returns true if the file is a test file
33-
func IsTestFile(filename string) bool {
34-
return ClassifyFile(filename) == FileTypeTest
35-
}
3632

37-
// IsSourceFile returns true if the file is a source file
38-
func IsSourceFile(filename string) bool {
39-
return ClassifyFile(filename) == FileTypeSource
40-
}

internal/instrument/instrumenter.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ func GenerateCoverageInstruments(parsedFiles []*parser.ParsedSQL) ([]*Instrument
2323
return instrumented, nil
2424
}
2525

26-
// GetCoveragePointBySignal finds a coverage point by its signal ID
27-
func GetCoveragePointBySignal(instrumented *InstrumentedSQL, signalID string) *CoveragePoint {
28-
for i := range instrumented.Locations {
29-
if instrumented.Locations[i].SignalID == signalID {
30-
return &instrumented.Locations[i]
31-
}
32-
}
33-
return nil
34-
}
35-
3626
// InstrumentWithNotify instruments SQL by injecting NOTIFY calls for coverage tracking
3727
func GenerateCoverageInstrument(parsed *parser.ParsedSQL) (*InstrumentedSQL, error) {
3828
if parsed == nil || parsed.File == nil {
@@ -324,7 +314,6 @@ func findTerminalPos(segmentContent string) int {
324314
switch next.Type {
325315
case pglex.KNotice, pglex.KWarning, pglex.KInfo, pglex.KLog, pglex.KDebug:
326316
// Non-fatal RAISE; continue scanning for a later terminal.
327-
break
328317
default:
329318
return pos // RAISE EXCEPTION, RAISE 'msg', etc.
330319
}

internal/instrument/instrumenter_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import (
1010
"github.com/cybertec-postgresql/pgcov/internal/parser"
1111
)
1212

13+
// getCoveragePointBySignal finds a coverage point by its signal ID. Used only in tests.
14+
func getCoveragePointBySignal(instrumented *InstrumentedSQL, signalID string) *CoveragePoint {
15+
for i := range instrumented.Locations {
16+
if instrumented.Locations[i].SignalID == signalID {
17+
return &instrumented.Locations[i]
18+
}
19+
}
20+
return nil
21+
}
22+
1323
func TestInstrumentWithLexer(t *testing.T) {
1424
sql := `CREATE OR REPLACE FUNCTION get_grade(score INT)
1525
RETURNS TEXT AS $$
@@ -423,21 +433,21 @@ func TestGetCoveragePointBySignal(t *testing.T) {
423433

424434
// Test finding a coverage point by signal
425435
signal := instrumented.Locations[0].SignalID
426-
cp := GetCoveragePointBySignal(instrumented, signal)
436+
cp := getCoveragePointBySignal(instrumented, signal)
427437
if cp == nil {
428438
t.Errorf("GetCoveragePointBySignal() returned nil for signal %q", signal)
429439
} else if cp.SignalID != signal {
430440
t.Errorf("GetCoveragePointBySignal() got signal %q, want %q", cp.SignalID, signal)
431441
}
432442

433443
// Test non-existent signal
434-
cp = GetCoveragePointBySignal(instrumented, "nonexistent:signal")
444+
cp = getCoveragePointBySignal(instrumented, "nonexistent:signal")
435445
if cp != nil {
436446
t.Errorf("GetCoveragePointBySignal() expected nil for nonexistent signal, got %v", cp)
437447
}
438448

439449
// Test returned pointer refers to actual slice element, not a loop-copy
440-
cp = GetCoveragePointBySignal(instrumented, signal)
450+
cp = getCoveragePointBySignal(instrumented, signal)
441451
if cp != &instrumented.Locations[0] {
442452
t.Error("GetCoveragePointBySignal() returned pointer to copy, not to original slice element")
443453
}

0 commit comments

Comments
 (0)