mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-07 06:25:43 +00:00
style: Extract UI constants and refactor main view rendering (#30)
- [x] Add golangci-lint configuration with gocritic ifElseChain disabled
- [x] Rename error variables to avoid shadowing (createErr, watcherErr, watchErr, etc.)
- [x] Replace `interface{}` with `any` type alias throughout codebase
- [x] Add package-level documentation comments to all internal packages
- [x] Reorder struct fields alphabetically for consistency
- [x] Extract UI constants (terminal dimensions, column widths, colors) to constants.go
- [x] Refactor BubbleTeaUI main view rendering into smaller helper functions
- [x] Simplify nested conditionals and improve code clarity
- [x] Add `isForwardDisabled()` helper method to BubbleTeaUI
- [x] Update file permissions from 0644 to 0600 in config tests
- [x] Add `#nosec` comments and error suppression where appropriate
- [x] Improve test table struct field ordering for readability
- [x] Fix resource parsing in AddForward using strings.SplitN
- [x] Add comprehensive tests for new UI helper functions and constants
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
// Package benchmark provides HTTP benchmarking capabilities for port forwards.
|
||||
// It measures latency, throughput, and reliability of forwarded connections.
|
||||
//
|
||||
// The benchmark runner sends configurable numbers of concurrent requests
|
||||
// and collects statistics including:
|
||||
// - Latency percentiles (P50, P95, P99)
|
||||
// - Request success/failure rates
|
||||
// - Throughput (requests/second)
|
||||
// - Status code distribution
|
||||
//
|
||||
// Results can be displayed in the UI or exported for analysis.
|
||||
package benchmark
|
||||
|
||||
import (
|
||||
@@ -7,17 +18,17 @@ import (
|
||||
|
||||
// Results holds the aggregated results of a benchmark run
|
||||
type Results struct {
|
||||
ForwardID string `json:"forward_id"`
|
||||
URL string `json:"url"`
|
||||
Method string `json:"method"`
|
||||
StartTime time.Time `json:"start_time"`
|
||||
EndTime time.Time `json:"end_time"`
|
||||
StatusCodes map[int]int `json:"status_codes"`
|
||||
Errors map[string]int `json:"errors,omitempty"`
|
||||
Method string `json:"method"`
|
||||
URL string `json:"url"`
|
||||
ForwardID string `json:"forward_id"`
|
||||
Latencies []time.Duration `json:"-"`
|
||||
TotalRequests int `json:"total_requests"`
|
||||
Successful int `json:"successful"`
|
||||
Failed int `json:"failed"`
|
||||
Latencies []time.Duration `json:"-"` // Raw latencies for percentile calculation
|
||||
StatusCodes map[int]int `json:"status_codes"`
|
||||
Errors map[string]int `json:"errors,omitempty"`
|
||||
BytesRead int64 `json:"bytes_read"`
|
||||
BytesWritten int64 `json:"bytes_written"`
|
||||
}
|
||||
|
||||
@@ -16,15 +16,15 @@ type ProgressCallback func(completed, total int)
|
||||
|
||||
// Config holds the benchmark configuration
|
||||
type Config struct {
|
||||
URL string // Target URL
|
||||
Method string // HTTP method
|
||||
Headers map[string]string // Custom headers
|
||||
Body []byte // Request body
|
||||
Concurrency int // Number of concurrent workers
|
||||
Requests int // Total number of requests (0 = use duration)
|
||||
Duration time.Duration // Duration to run (0 = use requests)
|
||||
Timeout time.Duration // Request timeout
|
||||
ProgressCallback ProgressCallback // Optional callback for progress updates
|
||||
Headers map[string]string
|
||||
ProgressCallback ProgressCallback
|
||||
URL string
|
||||
Method string
|
||||
Body []byte
|
||||
Concurrency int
|
||||
Requests int
|
||||
Duration time.Duration
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// Runner executes HTTP benchmarks
|
||||
|
||||
@@ -106,7 +106,7 @@ func TestRunner(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(5 * time.Millisecond) // Simulate some latency
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`{"status":"ok"}`))
|
||||
_, _ = w.Write([]byte(`{"status":"ok"}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -132,7 +132,7 @@ func TestRunner(t *testing.T) {
|
||||
func TestRunnerWithDuration(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`ok`))
|
||||
_, _ = w.Write([]byte(`ok`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -210,7 +210,7 @@ func TestRunnerWithProgressCallback(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(10 * time.Millisecond) // Add small delay so progress ticker can fire
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`ok`))
|
||||
_, _ = w.Write([]byte(`ok`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user