cleanup: remove unused functions and fix tests
Remove unused Go code identified through systematic analysis:
Removed Functions:
- BashRun() in claudetool/bash.go - legacy testing function
- ContentToString() in claudetool/util.go - unused utility function
- GetActiveTunnels() in dockerimg/tunnel_manager.go - unused getter method
Removed Types:
- baseResponse struct in claudetool/browse/browse.go - unused response type
Test Updates:
- Replaced BashRun tests with direct Bash.Run calls in bash_test.go
- Removed ContentToString test from agent_test.go (testing unused function)
- Updated tunnel manager tests to access internal activeTunnels map directly
- Fixed all compilation errors caused by removed functions
All tests now pass and the codebase is cleaner with reduced maintenance burden.
The removed functions had no references in production code and were only
used in tests, which have been updated or removed as appropriate.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s2cac4b024f877682k
diff --git a/dockerimg/tunnel_manager.go b/dockerimg/tunnel_manager.go
index 2b01f8a..89512d4 100644
--- a/dockerimg/tunnel_manager.go
+++ b/dockerimg/tunnel_manager.go
@@ -246,15 +246,3 @@
delete(tm.activeTunnels, port)
}
}
-
-// GetActiveTunnels returns a list of currently active tunnels
-func (tm *TunnelManager) GetActiveTunnels() map[string]string {
- tm.mu.Lock()
- defer tm.mu.Unlock()
-
- result := make(map[string]string)
- for containerPort, tunnel := range tm.activeTunnels {
- result[containerPort] = tunnel.hostPort
- }
- return result
-}
diff --git a/dockerimg/tunnel_manager_test.go b/dockerimg/tunnel_manager_test.go
index f430559..6408ce5 100644
--- a/dockerimg/tunnel_manager_test.go
+++ b/dockerimg/tunnel_manager_test.go
@@ -16,10 +16,9 @@
t.Errorf("Expected maxActiveTunnels to be 2, got %d", tm.maxActiveTunnels)
}
- // Test that GetActiveTunnels returns empty initially
- activeTunnels := tm.GetActiveTunnels()
- if len(activeTunnels) != 0 {
- t.Errorf("Expected 0 active tunnels initially, got %d", len(activeTunnels))
+ // Test that active tunnels map is empty initially
+ if len(tm.activeTunnels) != 0 {
+ t.Errorf("Expected 0 active tunnels initially, got %d", len(tm.activeTunnels))
}
// Simulate adding tunnels beyond the limit by directly manipulating the internal map
@@ -29,9 +28,8 @@
tm.activeTunnels["9090"] = &sshTunnel{containerPort: "9090", hostPort: "9090"}
// Verify we have 2 active tunnels
- activeTunnels = tm.GetActiveTunnels()
- if len(activeTunnels) != 2 {
- t.Errorf("Expected 2 active tunnels, got %d", len(activeTunnels))
+ if len(tm.activeTunnels) != 2 {
+ t.Errorf("Expected 2 active tunnels, got %d", len(tm.activeTunnels))
}
// Now test that the limit check works - attempt to add a third tunnel
@@ -49,9 +47,8 @@
}
// Verify we still have only 2 active tunnels (didn't exceed limit)
- activeTunnels = tm.GetActiveTunnels()
- if len(activeTunnels) != 2 {
- t.Errorf("Expected exactly 2 active tunnels after limit enforcement, got %d", len(activeTunnels))
+ if len(tm.activeTunnels) != 2 {
+ t.Errorf("Expected exactly 2 active tunnels after limit enforcement, got %d", len(tm.activeTunnels))
}
}
@@ -136,8 +133,8 @@
tm.activeTunnels["9090"] = &sshTunnel{containerPort: "9090", hostPort: "9090"}
// Verify we're now at the limit
- if len(tm.GetActiveTunnels()) != 2 {
- t.Fatalf("Setup failed: expected 2 active tunnels, got %d", len(tm.GetActiveTunnels()))
+ if len(tm.activeTunnels) != 2 {
+ t.Fatalf("Setup failed: expected 2 active tunnels, got %d", len(tm.activeTunnels))
}
// Now test that createTunnel respects the limit by calling it directly
@@ -146,13 +143,13 @@
tm.createTunnel(ctx, "4000")
// Verify no additional tunnels were added (limit enforcement worked)
- if len(tm.GetActiveTunnels()) != 2 {
- t.Errorf("createTunnel should have been blocked by limit, but tunnel count changed from 2 to %d", len(tm.GetActiveTunnels()))
+ if len(tm.activeTunnels) != 2 {
+ t.Errorf("createTunnel should have been blocked by limit, but tunnel count changed from 2 to %d", len(tm.activeTunnels))
}
// Verify we're at the limit
- if len(tm.GetActiveTunnels()) != 2 {
- t.Fatalf("Expected 2 active tunnels, got %d", len(tm.GetActiveTunnels()))
+ if len(tm.activeTunnels) != 2 {
+ t.Fatalf("Expected 2 active tunnels, got %d", len(tm.activeTunnels))
}
// Now try to process more port events that would create additional tunnels
@@ -173,24 +170,23 @@
tm.processPortEvent(ctx, portEvent2)
// Verify that no additional tunnels were created
- activeTunnels := tm.GetActiveTunnels()
- if len(activeTunnels) != 2 {
- t.Errorf("Expected exactly 2 active tunnels after limit enforcement, got %d", len(activeTunnels))
+ if len(tm.activeTunnels) != 2 {
+ t.Errorf("Expected exactly 2 active tunnels after limit enforcement, got %d", len(tm.activeTunnels))
}
// Verify the original tunnels are still there
- if _, exists := activeTunnels["8080"]; !exists {
+ if _, exists := tm.activeTunnels["8080"]; !exists {
t.Error("Expected original tunnel for port 8080 to still exist")
}
- if _, exists := activeTunnels["9090"]; !exists {
+ if _, exists := tm.activeTunnels["9090"]; !exists {
t.Error("Expected original tunnel for port 9090 to still exist")
}
// Verify the new tunnels were NOT created
- if _, exists := activeTunnels["3000"]; exists {
+ if _, exists := tm.activeTunnels["3000"]; exists {
t.Error("Expected tunnel for port 3000 to NOT be created due to limit")
}
- if _, exists := activeTunnels["4000"]; exists {
+ if _, exists := tm.activeTunnels["4000"]; exists {
t.Error("Expected tunnel for port 4000 to NOT be created due to limit")
}
}