MCPcopy Index your code
hub / github.com/coder/coder / TestURLGenerationVsParsing

Function TestURLGenerationVsParsing

coderd/workspaceapps/appurl/appurl_test.go:587–642  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

585}
586
587func TestURLGenerationVsParsing(t *testing.T) {
588 t.Parallel()
589
590 testCases := []struct {
591 Name string
592 AppSlugOrPort string
593 AgentName string
594 ExpectedParsed string
595 }{
596 {
597 Name: "AppSlug_AgentOmittedInParsing",
598 AppSlugOrPort: "myapp",
599 AgentName: "agent",
600 ExpectedParsed: "",
601 },
602 {
603 Name: "4DigitPort_AgentPreserved",
604 AppSlugOrPort: "8080",
605 AgentName: "agent",
606 ExpectedParsed: "agent",
607 },
608 {
609 Name: "5DigitAppSlug_AgentOmittedInParsing",
610 AppSlugOrPort: "30000",
611 AgentName: "agent",
612 ExpectedParsed: "agent",
613 },
614 {
615 // 6 digits is not a valid port, so it is treated as an app slug.
616 // App slugs do not require the agent name, so it is dropped
617 Name: "6DigitAppSlug_AgentOmittedInParsing",
618 AppSlugOrPort: "300000",
619 AgentName: "agent",
620 ExpectedParsed: "",
621 },
622 }
623
624 for _, tc := range testCases {
625 t.Run(tc.Name, func(t *testing.T) {
626 t.Parallel()
627 original := appurl.ApplicationURL{
628 AppSlugOrPort: tc.AppSlugOrPort,
629 AgentName: tc.AgentName,
630 WorkspaceName: "workspace",
631 Username: "user",
632 }
633
634 urlString := original.String()
635 parsed, err := appurl.ParseSubdomainAppURL(urlString)
636 require.NoError(t, err)
637
638 require.Equal(t, tc.ExpectedParsed, parsed.AgentName,
639 "Agent name should be '%s' after parsing", tc.ExpectedParsed)
640 })
641 }
642}

Callers

nothing calls this directly

Calls 4

StringMethod · 0.95
ParseSubdomainAppURLFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected