package profile import "testing" func TestValidateAndNormalizeDefaultsSchemeLessURLsToHTTP(t *testing.T) { tests := []struct { name string input Profile want map[string]string }{ { name: "bare single URL", input: Profile{Name: "office", SingleURL: "proxy.example:8080"}, want: map[string]string{"single": "http://proxy.example:8080"}, }, { name: "bare single URL with userinfo", input: Profile{Name: "office", SingleURL: "alice:secret@proxy.example:8080"}, want: map[string]string{"single": "http://alice:secret@proxy.example:8080"}, }, { name: "bare IPv6 single URL", input: Profile{Name: "office", SingleURL: "[::1]:8888"}, want: map[string]string{"single": "http://[::1]:8888"}, }, { name: "bare advanced URLs", input: Profile{Name: "office", Mode: AdvancedMode, HTTPURL: "proxy.example:8080", HTTPSURL: "secure.example:8443", AllURL: "socks.example:1080"}, want: map[string]string{ "http": "http://proxy.example:8080", "https": "http://secure.example:8443", "all": "http://socks.example:1080"}, }, { name: "explicit schemes untouched", input: Profile{Name: "office", Mode: AdvancedMode, HTTPURL: "https://proxy.example:8443", AllURL: "socks5h://socks.example:1080"}, want: map[string]string{"http": "https://proxy.example:8443", "all": "socks5h://socks.example:1080"}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := ValidateAndNormalize(tt.input) if err != nil { t.Fatalf("ValidateAndNormalize returned error: %v", err) } values := map[string]string{ "single": got.SingleURL, "http": got.HTTPURL, "https": got.HTTPSURL, "all": got.AllURL, } for field, want := range tt.want { if values[field] != want { t.Fatalf("%s = %q, want %q", field, values[field], want) } } }) } } func TestValidateAndNormalizeSchemeLessSingleURLExpandsToAllProtocols(t *testing.T) { got, err := ValidateAndNormalize(Profile{Name: "office", SingleURL: "localhost:8888"}) if err != nil { t.Fatalf("ValidateAndNormalize returned error: %v", err) } if got.SingleURL != "http://localhost:8888" { t.Fatalf("SingleURL = %q, want http://localhost:8888", got.SingleURL) } if got.HTTPURL != got.SingleURL || got.HTTPSURL != got.SingleURL || got.AllURL != got.SingleURL { t.Fatalf("Single mode did not expand: %#v", got) } }