You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/ipn/conffile
Claude d6a66bf444
Services config testing: serveconf_test.go 0→581 lines, 10 tests!
Comprehensive test suite for ipn/conffile/serveconf.go (239 lines):

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📦 serveconf_test.go: 0→581 lines (10 tests)
Target: serveconf.go (239 lines, Tailscale Services config)

Coverage:

1️⃣ Target.UnmarshalJSON (1 test, 12 cases)
  • TUN mode: "TUN" → ProtoTUN
  • HTTP/HTTPS/HTTPS+insecure protocols
  • TCP, TLS-terminated-TCP protocols
  • File protocol with path cleaning
  • IPv6 addresses: [::1]:8080, [2001:db8::1]:443
  • Error cases: no protocol, unsupported protocol

2️⃣ Target.MarshalText (1 test, 7 cases)
  • All protocols: TUN, http, https, tcp, file
  • Format: "protocol://destination:port"
  • TUN special case: "TUN"
  • Unsupported protocol → error

3️⃣ Round-trip Testing (1 test, 7 cases)
  • Unmarshal → Marshal → Unmarshal
  • Verify Protocol, Destination, DestinationPorts
  • All protocol types

4️⃣ Protocol Constants (1 test, 7 protocols)
  • ProtoHTTP = "http"
  • ProtoHTTPS = "https"
  • ProtoHTTPSInsecure = "https+insecure"
  • ProtoTCP = "tcp"
  • ProtoTLSTerminatedTCP = "tls-terminated-tcp"
  • ProtoFile = "file"
  • ProtoTUN = "TUN"

5️⃣ Port Ranges (1 test, 2 cases)
  • Single port: 8080
  • Port range: 8000-8100

6️⃣ findOverlappingRange (1 test, 7 cases)
  • No overlap, exact match
  • Needle contains haystack, vice versa
  • Partial overlaps (start/end)
  • Empty haystack

7️⃣ ServicesConfigFile Structure (1 test)
  • Version = "0.0.1"
  • Services map validation
  • Endpoints configuration

8️⃣ ServiceDetailsFile.Advertised (1 test, 3 cases)
  • opt.Bool: true, false, unset
  • Get() returns proper values

9️⃣ File Path Cleaning (1 test, 4 cases)
  • Absolute: /var/www/html
  • Relative: ./public → public
  • Double slashes: var//www → var/www
  • Parent refs: var/www/../static → var/static

🔟 IPv6 Addresses (1 test, 2 cases)
  • [::1]:8080
  • [2001:db8::1]:443

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Test Highlights:
 JSON marshaling/unmarshaling
 All 7 service protocols
 Port range overlap detection
 Path cleaning & normalization
 IPv6 support
 Error handling for invalid inputs

STATS:
Before: 239-line file with NO dedicated tests
After: 581 lines of tests, 10 test functions
Coverage boost: Service config parsing fully tested!
3 weeks ago
..
cloudconf.go feature/featuretags, ipn/conffile: make HuJSON support in config files optional 3 months ago
conffile.go feature/featuretags, ipn/conffile: make HuJSON support in config files optional 3 months ago
conffile_hujson.go feature/featuretags, ipn/conffile: make HuJSON support in config files optional 3 months ago
conffile_test.go Add comprehensive tests for critical untested packages 4 weeks ago
serveconf.go cmd/tailscale/cli,ipn/conffile: add declarative config mode for Services (#17435) 2 months ago
serveconf_test.go Services config testing: serveconf_test.go 0→581 lines, 10 tests! 3 weeks ago