mirror of
https://github.com/nabbar/golib.git
synced 2025-12-24 11:51:02 +08:00
- config Server: change time duration to golib duration to simplify marshal string form - adjust test following update of config server - fix test in socket package to use BDD framework & gherkin form - adjust documentation & test Package HTTPServer: - Fix bug in PortUse & PortNotUse - Move function PortUse & PortNotUse as alone function - Add test & documentation - Unify test & documentation following other packages
760 lines
19 KiB
Go
760 lines
19 KiB
Go
/*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2025 Nicolas JUHEL
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
*
|
|
*/
|
|
|
|
// Robustness Tests - Socket Configuration Package
|
|
//
|
|
// This file contains robustness and error recovery tests to verify that the
|
|
// socket/config package handles unusual, malformed, or pathological inputs gracefully.
|
|
//
|
|
// Test Coverage:
|
|
// - Edge case addresses: Very long hostnames, unusual characters, malformed input
|
|
// - Special characters: Unicode, null bytes, control characters in addresses
|
|
// - Empty and whitespace: Empty strings, whitespace-only values, padding
|
|
// - Extreme values: Very large ports (>65535), negative values, overflow conditions
|
|
// - Invalid TLS configurations: Missing certificates, incomplete configurations
|
|
// - Unix socket specifics: Non-existent paths, permission conflicts, path length limits
|
|
// - Platform-specific behavior: Cross-platform validation consistency
|
|
// - Error message clarity: Meaningful errors for common mistakes
|
|
// - Recovery: Ability to fix and revalidate after errors
|
|
//
|
|
// Robustness Philosophy:
|
|
// The package should never panic or produce undefined behavior. All invalid
|
|
// inputs should result in clear error messages that help users diagnose and
|
|
// fix configuration problems. The tests verify that the package degrades
|
|
// gracefully and provides actionable feedback.
|
|
package config_test
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
libtls "github.com/nabbar/golib/certificates"
|
|
libdur "github.com/nabbar/golib/duration"
|
|
libprm "github.com/nabbar/golib/file/perm"
|
|
libptc "github.com/nabbar/golib/network/protocol"
|
|
"github.com/nabbar/golib/socket/config"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Client Robustness", func() {
|
|
Context("Edge case addresses", func() {
|
|
It("should handle very long addresses", func() {
|
|
longAddr := strings.Repeat("a", 1000) + ":8080"
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: longAddr,
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should handle addresses with special characters", func() {
|
|
specialAddrs := []string{
|
|
"localhost:808\x00",
|
|
"localhost:808\n",
|
|
"localhost:808\t",
|
|
}
|
|
|
|
for _, addr := range specialAddrs {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: addr,
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred(), "Address with special char should be invalid: %q", addr)
|
|
}
|
|
})
|
|
|
|
It("should handle Unicode in addresses", func() {
|
|
unicodeAddrs := []string{
|
|
"localhost™:8080",
|
|
"本地主机:8080",
|
|
"localhost:808😀",
|
|
}
|
|
|
|
for _, addr := range unicodeAddrs {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: addr,
|
|
}
|
|
// May succeed or fail depending on DNS resolution
|
|
_ = c.Validate()
|
|
}
|
|
})
|
|
})
|
|
|
|
Context("Port boundary cases", func() {
|
|
It("should reject client address string", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "abc",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject client address string", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "abc",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should accept client port 1", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:1",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should accept client port 1", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:1",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should accept client port 65535", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:65535",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should accept client port 65535", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:65535",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should reject client port 0", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:0",
|
|
}
|
|
err := c.Validate()
|
|
// Port 0 may be valid in some contexts (OS assigns port)
|
|
_ = err
|
|
})
|
|
|
|
It("should reject client port 0", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:0",
|
|
}
|
|
err := c.Validate()
|
|
// Port 0 may be valid in some contexts (OS assigns port)
|
|
_ = err
|
|
})
|
|
|
|
It("should reject client port -1", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:-1",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject client port -1", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:-1",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject client port 65536", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:65536",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject client port 65536", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:65536",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject server address string", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "abc",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject server address string", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "abc",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should accept server port 1", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:1",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should accept server port 1", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:1",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should accept server port 65535", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:65535",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should accept server port 65535", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:65535",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should reject server port 0", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:0",
|
|
}
|
|
err := c.Validate()
|
|
// Port 0 may be valid in some contexts (OS assigns port)
|
|
_ = err
|
|
})
|
|
|
|
It("should reject server port 0", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:0",
|
|
}
|
|
err := c.Validate()
|
|
// Port 0 may be valid in some contexts (OS assigns port)
|
|
_ = err
|
|
})
|
|
|
|
It("should reject server port -1", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:-1",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject server port -1", func() {
|
|
c := config.Server{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:-1",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject port 65536", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:65536",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should reject port 65536", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkUDP,
|
|
Address: "localhost:65536",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
})
|
|
|
|
Context("IPv6 edge cases", func() {
|
|
It("should handle IPv6 loopback", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP6,
|
|
Address: "[::1]:8080",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should handle IPv6 any address", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP6,
|
|
Address: "[::]:8080",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should handle full IPv6 address", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP6,
|
|
Address: "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("should handle compressed IPv6 address", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP6,
|
|
Address: "[2001:db8::1]:8080",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
})
|
|
|
|
Context("TLS edge cases", func() {
|
|
It("should handle TLS with nil config", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:8080",
|
|
}
|
|
c.TLS.Enabled = true
|
|
c.TLS.Config = libtls.Config{}
|
|
c.TLS.ServerName = ""
|
|
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should handle TLS with empty server name", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:8080",
|
|
}
|
|
c.TLS.Enabled = true
|
|
c.TLS.ServerName = ""
|
|
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
})
|
|
|
|
Context("Zero value handling", func() {
|
|
It("should handle zero-value client", func() {
|
|
var c config.Client
|
|
err := c.Validate()
|
|
expectValidationError(err, config.ErrInvalidProtocol)
|
|
})
|
|
|
|
It("should handle partially initialized client", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
}
|
|
err := c.Validate()
|
|
// Empty address may be accepted by net.ResolveTCPAddr in some cases
|
|
// We document the behavior without strict assertion
|
|
_ = err
|
|
})
|
|
})
|
|
|
|
Context("bad TCP address", func() {
|
|
It("should trigger error on validate client", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "abc",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
It("should trigger error on validate server", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "abc",
|
|
}
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
})
|
|
})
|
|
|
|
var _ = Describe("Server Robustness", func() {
|
|
Context("Unix socket edge cases", func() {
|
|
BeforeEach(func() {
|
|
skipIfWindows("Unix sockets not supported")
|
|
})
|
|
|
|
It("should handle very long Unix socket paths", func() {
|
|
longPath := "/tmp/" + strings.Repeat("a", 200) + ".sock"
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: longPath,
|
|
}
|
|
err := s.Validate()
|
|
// May fail due to OS path length limits
|
|
_ = err
|
|
})
|
|
|
|
It("should handle relative Unix socket paths", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: "./test.sock",
|
|
}
|
|
err := s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should handle Unix socket paths with special characters", func() {
|
|
specialPaths := []string{
|
|
"/tmp/test socket.sock", // Space
|
|
"/tmp/test-socket.sock", // Dash
|
|
"/tmp/test_socket.sock", // Underscore
|
|
"/tmp/test.socket.sock", // Multiple dots
|
|
}
|
|
|
|
for _, path := range specialPaths {
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: path,
|
|
}
|
|
err := s.Validate()
|
|
Expect(err).NotTo(HaveOccurred(), "Path should be valid: %s", path)
|
|
}
|
|
})
|
|
})
|
|
|
|
Context("Group permission edge cases", func() {
|
|
BeforeEach(func() {
|
|
skipIfWindows("Unix sockets not supported")
|
|
})
|
|
|
|
It("should accept -1 as group permission", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: "/tmp/test.sock",
|
|
GroupPerm: -1,
|
|
}
|
|
err := s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should accept 0 as group permission", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: "/tmp/test.sock",
|
|
GroupPerm: 0,
|
|
}
|
|
err := s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should accept MaxGID as group permission", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: "/tmp/test.sock",
|
|
GroupPerm: config.MaxGID,
|
|
}
|
|
err := s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should reject MaxGID+1 as group permission", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: "/tmp/test.sock",
|
|
GroupPerm: config.MaxGID + 1,
|
|
}
|
|
err := s.Validate()
|
|
expectValidationError(err, config.ErrInvalidGroup)
|
|
})
|
|
})
|
|
|
|
Context("File permission edge cases", func() {
|
|
BeforeEach(func() {
|
|
skipIfWindows("Unix sockets not supported")
|
|
})
|
|
|
|
It("should accept zero file permission", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: "/tmp/test.sock",
|
|
PermFile: 0,
|
|
}
|
|
err := s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should accept various valid permissions", func() {
|
|
permissions := []libprm.Perm{
|
|
0400, 0600, 0644, 0660, 0666,
|
|
0700, 0750, 0755, 0770, 0777,
|
|
}
|
|
|
|
for _, perm := range permissions {
|
|
s := config.Server{
|
|
Network: libptc.NetworkUnix,
|
|
Address: "/tmp/test.sock",
|
|
PermFile: perm,
|
|
}
|
|
err := s.Validate()
|
|
Expect(err).NotTo(HaveOccurred(), "Permission %o should be valid", perm)
|
|
}
|
|
})
|
|
})
|
|
|
|
Context("Idle timeout edge cases", func() {
|
|
It("should accept zero timeout", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: ":8080",
|
|
ConIdleTimeout: 0,
|
|
}
|
|
err := s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should accept very large timeout", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: ":8080",
|
|
ConIdleTimeout: libdur.Days(999999),
|
|
}
|
|
err := s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should accept negative timeout", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: ":8080",
|
|
ConIdleTimeout: libdur.Seconds(-1),
|
|
}
|
|
err := s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should accept various timeout durations", func() {
|
|
timeouts := []time.Duration{
|
|
1 * time.Nanosecond,
|
|
1 * time.Microsecond,
|
|
1 * time.Millisecond,
|
|
1 * time.Second,
|
|
1 * time.Minute,
|
|
1 * time.Hour,
|
|
}
|
|
|
|
for _, timeout := range timeouts {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: ":8080",
|
|
ConIdleTimeout: libdur.ParseDuration(timeout),
|
|
}
|
|
err := s.Validate()
|
|
Expect(err).NotTo(HaveOccurred(), "Timeout %v should be valid", timeout)
|
|
}
|
|
})
|
|
})
|
|
|
|
Context("Server TLS methods robustness", func() {
|
|
It("should handle GetTLS on zero-value server", func() {
|
|
var s config.Server
|
|
enabled, tlsCfg := s.GetTLS()
|
|
Expect(enabled).To(BeFalse())
|
|
Expect(tlsCfg).To(BeNil())
|
|
})
|
|
|
|
It("should handle DefaultTLS with nil config", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: ":8080",
|
|
}
|
|
s.DefaultTLS(nil)
|
|
// Should not panic
|
|
Succeed()
|
|
})
|
|
|
|
It("should handle multiple DefaultTLS calls", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: ":8080",
|
|
}
|
|
s.DefaultTLS(nil)
|
|
s.DefaultTLS(nil)
|
|
s.DefaultTLS(nil)
|
|
// Should not panic
|
|
Succeed()
|
|
})
|
|
})
|
|
|
|
Context("Client TLS methods robustness", func() {
|
|
It("should handle GetTLS on zero-value client", func() {
|
|
var c config.Client
|
|
enabled, tlsCfg, serverName := c.GetTLS()
|
|
Expect(enabled).To(BeFalse())
|
|
Expect(tlsCfg).To(BeNil())
|
|
Expect(serverName).To(BeEmpty())
|
|
})
|
|
|
|
It("should handle DefaultTLS with nil config for client", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:8080",
|
|
}
|
|
c.DefaultTLS(nil)
|
|
// Should not panic
|
|
Succeed()
|
|
})
|
|
|
|
It("should handle multiple DefaultTLS calls for client", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:8080",
|
|
}
|
|
c.DefaultTLS(nil)
|
|
c.DefaultTLS(nil)
|
|
c.DefaultTLS(nil)
|
|
// Should not panic
|
|
Succeed()
|
|
})
|
|
})
|
|
|
|
Context("Zero value handling", func() {
|
|
It("should handle zero-value server", func() {
|
|
var s config.Server
|
|
err := s.Validate()
|
|
expectValidationError(err, config.ErrInvalidProtocol)
|
|
})
|
|
|
|
It("should handle partially initialized server", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
}
|
|
err := s.Validate()
|
|
// Empty address may be accepted by net.ResolveTCPAddr in some cases
|
|
// We document the behavior without strict assertion
|
|
_ = err
|
|
})
|
|
})
|
|
})
|
|
|
|
var _ = Describe("Error Recovery", func() {
|
|
Context("Validation after errors", func() {
|
|
It("should allow re-validation after fixing client errors", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "invalid",
|
|
}
|
|
|
|
// First validation should fail
|
|
err := c.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
// Fix the address
|
|
c.Address = "localhost:8080"
|
|
|
|
// Second validation should succeed
|
|
err = c.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
|
|
It("should allow re-validation after fixing server errors", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "invalid",
|
|
}
|
|
|
|
// First validation should fail
|
|
err := s.Validate()
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
// Fix the address
|
|
s.Address = ":8080"
|
|
|
|
// Second validation should succeed
|
|
err = s.Validate()
|
|
expectNoValidationError(err)
|
|
})
|
|
})
|
|
|
|
Context("Multiple validation calls", func() {
|
|
It("should handle repeated client validation", func() {
|
|
c := config.Client{
|
|
Network: libptc.NetworkTCP,
|
|
Address: "localhost:8080",
|
|
}
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
err := c.Validate()
|
|
Expect(err).NotTo(HaveOccurred(), "Validation %d should succeed", i)
|
|
}
|
|
})
|
|
|
|
It("should handle repeated server validation", func() {
|
|
s := config.Server{
|
|
Network: libptc.NetworkTCP,
|
|
Address: ":8080",
|
|
}
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
err := s.Validate()
|
|
Expect(err).NotTo(HaveOccurred(), "Validation %d should succeed", i)
|
|
}
|
|
})
|
|
})
|
|
})
|