mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-07 06:25:43 +00:00
Cleanup and refactor.
This commit is contained in:
@@ -22,11 +22,6 @@ type ValidationError struct {
|
||||
Context map[string]string // Additional context information
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ValidationError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// Validator validates configuration files.
|
||||
type Validator struct{}
|
||||
|
||||
|
||||
@@ -621,15 +621,6 @@ func TestFormatValidationErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidationError_Error(t *testing.T) {
|
||||
err := ValidationError{
|
||||
Field: "port",
|
||||
Message: "Invalid port 0",
|
||||
}
|
||||
|
||||
assert.Equal(t, "Invalid port 0", err.Error(), "Error() should return the message")
|
||||
}
|
||||
|
||||
func TestValidator_ValidateStructure(t *testing.T) {
|
||||
validator := NewValidator()
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ type Watcher struct {
|
||||
done chan struct{}
|
||||
verbose bool
|
||||
wg sync.WaitGroup // Ensures watch goroutine exits before Stop returns
|
||||
stopOnce sync.Once // Ensures Stop is safe to call multiple times
|
||||
}
|
||||
|
||||
// NewWatcher creates a new file watcher for the given config file.
|
||||
@@ -61,9 +62,12 @@ func (w *Watcher) Start() {
|
||||
}
|
||||
|
||||
// Stop stops watching the configuration file and waits for the watch goroutine to exit.
|
||||
// Safe to call multiple times.
|
||||
func (w *Watcher) Stop() {
|
||||
close(w.done)
|
||||
_ = w.watcher.Close()
|
||||
w.stopOnce.Do(func() {
|
||||
close(w.done)
|
||||
_ = w.watcher.Close()
|
||||
})
|
||||
w.wg.Wait() // Wait for watch goroutine to exit
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user