-
Notifications
You must be signed in to change notification settings - Fork 13
print https:// before public endpoints #1207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ func TestPrintPlaygroundPortalServiceURLs(t *testing.T) { | |
} | ||
} | ||
|
||
func TestPrintServiceStatesAndEndpoints(t *testing.T) { | ||
func TestPrintServiceStatesAndEndpointsAndDomainname(t *testing.T) { | ||
defaultTerm := term.DefaultTerm | ||
t.Cleanup(func() { | ||
term.DefaultTerm = defaultTerm | ||
|
@@ -44,80 +44,102 @@ func TestPrintServiceStatesAndEndpoints(t *testing.T) { | |
var stdout, stderr bytes.Buffer | ||
term.DefaultTerm = term.NewTerm(os.Stdin, &stdout, &stderr) | ||
|
||
_ = printServiceStatesAndEndpoints([]*defangv1.ServiceInfo{ | ||
tests := []struct { | ||
name string | ||
serviceinfos []*defangv1.ServiceInfo | ||
expectedLines []string | ||
}{ | ||
{ | ||
Service: &defangv1.Service{ | ||
Name: "service1", | ||
Ports: []*defangv1.Port{ | ||
{Mode: defangv1.Mode_INGRESS}, | ||
{Mode: defangv1.Mode_HOST}, | ||
name: "empty endpoint list", | ||
serviceinfos: []*defangv1.ServiceInfo{ | ||
{ | ||
Service: &defangv1.Service{ | ||
Name: "service1", | ||
Ports: []*defangv1.Port{ | ||
{Mode: defangv1.Mode_INGRESS}, | ||
{Mode: defangv1.Mode_HOST}, | ||
}, | ||
}, | ||
Status: "UNKNOWN", | ||
Domainname: "example.com", | ||
Endpoints: []string{}, | ||
}, | ||
}, | ||
Status: "UNKNOWN", | ||
Endpoints: []string{ | ||
"example.com", | ||
"service1.internal", | ||
expectedLines: []string{ | ||
"Deployment Name Status Endpoints DomainName", | ||
" service1 NOT_SPECIFIED N/A https://example.com", | ||
" * Run `defang cert generate` to get a TLS certificate for your service(s)", | ||
"", | ||
}, | ||
}}) | ||
const expectedOutput = `Deployment Name Status Endpoints | ||
service1 NOT_SPECIFIED example.com, service1.internal | ||
` | ||
receivedLines := strings.Split(stdout.String(), "\n") | ||
expectedLines := strings.Split(expectedOutput, "\n") | ||
|
||
if len(receivedLines) != len(expectedLines) { | ||
t.Errorf("Expected %v lines, received %v", len(expectedLines), len(receivedLines)) | ||
} | ||
|
||
for i, receivedLine := range receivedLines { | ||
receivedLine = strings.TrimRight(receivedLine, " ") | ||
if receivedLine != expectedLines[i] { | ||
t.Errorf("\n-%v\n+%v", expectedLines[i], receivedLine) | ||
} | ||
} | ||
} | ||
|
||
func TestPrintServiceStatesAndEndpointsAndDomainname(t *testing.T) { | ||
defaultTerm := term.DefaultTerm | ||
t.Cleanup(func() { | ||
term.DefaultTerm = defaultTerm | ||
}) | ||
|
||
var stdout, stderr bytes.Buffer | ||
term.DefaultTerm = term.NewTerm(os.Stdin, &stdout, &stderr) | ||
|
||
_ = printServiceStatesAndEndpoints([]*defangv1.ServiceInfo{ | ||
}, | ||
{ | ||
Service: &defangv1.Service{ | ||
Name: "service1", | ||
Ports: []*defangv1.Port{ | ||
{Mode: defangv1.Mode_INGRESS}, | ||
{Mode: defangv1.Mode_HOST}, | ||
name: "Service with Domainname", | ||
serviceinfos: []*defangv1.ServiceInfo{ | ||
{ | ||
Service: &defangv1.Service{ | ||
Name: "service1", | ||
Ports: []*defangv1.Port{ | ||
{Mode: defangv1.Mode_INGRESS}, | ||
{Mode: defangv1.Mode_HOST}, | ||
}, | ||
}, | ||
Status: "UNKNOWN", | ||
Domainname: "example.com", | ||
Endpoints: []string{ | ||
"example.com", | ||
"service1.internal:80", | ||
}, | ||
}, | ||
}, | ||
Status: "UNKNOWN", | ||
Domainname: "example.com", | ||
Endpoints: []string{ | ||
"example.com", | ||
"service1.internal", | ||
expectedLines: []string{ | ||
"Deployment Name Status Endpoints DomainName", | ||
" service1 NOT_SPECIFIED https://example.com, service1.internal:80 https://example.com", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can't be be right, HTTPS to 80? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not https to 80. it's https to example.com. |
||
" * Run `defang cert generate` to get a TLS certificate for your service(s)", | ||
"", | ||
}, | ||
}}) | ||
expectedLines := []string{ | ||
"Deployment Name Status Endpoints DomainName", | ||
" service1 NOT_SPECIFIED example.com, service1.internal https://example.com", | ||
" * Run `defang cert generate` to get a TLS certificate for your service(s)", | ||
"", | ||
}, | ||
{ | ||
name: "endpoint without port", | ||
serviceinfos: []*defangv1.ServiceInfo{ | ||
{ | ||
Service: &defangv1.Service{ | ||
Name: "service1", | ||
Ports: []*defangv1.Port{ | ||
{Mode: defangv1.Mode_INGRESS}, | ||
{Mode: defangv1.Mode_HOST}, | ||
}, | ||
}, | ||
Status: "UNKNOWN", | ||
Endpoints: []string{ | ||
"service1", | ||
}, | ||
}, | ||
}, | ||
expectedLines: []string{ | ||
"Deployment Name Status Endpoints", | ||
" service1 NOT_SPECIFIED https://service1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lionello what's a good example of an endpoint that doesn't have a port, but which should be prefixed with |
||
"", | ||
}, | ||
}, | ||
} | ||
receivedLines := strings.Split(stdout.String(), "\n") | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Reset stdout before each test | ||
stdout.Reset() | ||
|
||
if len(receivedLines) != len(expectedLines) { | ||
t.Errorf("Expected %v lines, received %v", len(expectedLines), len(receivedLines)) | ||
} | ||
_ = printServiceStatesAndEndpoints(tt.serviceinfos) | ||
receivedLines := strings.Split(stdout.String(), "\n") | ||
|
||
if len(receivedLines) != len(tt.expectedLines) { | ||
t.Errorf("Expected %v lines, received %v", len(tt.expectedLines), len(receivedLines)) | ||
} | ||
|
||
for i, receivedLine := range receivedLines { | ||
receivedLine = strings.TrimRight(receivedLine, " ") | ||
if receivedLine != expectedLines[i] { | ||
t.Errorf("\n-%v\n+%v", expectedLines[i], receivedLine) | ||
} | ||
for i, receivedLine := range receivedLines { | ||
receivedLine = strings.TrimRight(receivedLine, " ") | ||
if receivedLine != tt.expectedLines[i] { | ||
t.Errorf("\n-%v\n+%v", tt.expectedLines[i], receivedLine) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.