@@ -35,7 +35,7 @@ func TestPrintPlaygroundPortalServiceURLs(t *testing.T) {
35
35
}
36
36
}
37
37
38
- func TestPrintServiceStatesAndEndpoints (t * testing.T ) {
38
+ func TestPrintServiceStatesAndEndpointsAndDomainname (t * testing.T ) {
39
39
defaultTerm := term .DefaultTerm
40
40
t .Cleanup (func () {
41
41
term .DefaultTerm = defaultTerm
@@ -44,80 +44,102 @@ func TestPrintServiceStatesAndEndpoints(t *testing.T) {
44
44
var stdout , stderr bytes.Buffer
45
45
term .DefaultTerm = term .NewTerm (os .Stdin , & stdout , & stderr )
46
46
47
- _ = printServiceStatesAndEndpoints ([]* defangv1.ServiceInfo {
47
+ tests := []struct {
48
+ name string
49
+ serviceinfos []* defangv1.ServiceInfo
50
+ expectedLines []string
51
+ }{
48
52
{
49
- Service : & defangv1.Service {
50
- Name : "service1" ,
51
- Ports : []* defangv1.Port {
52
- {Mode : defangv1 .Mode_INGRESS },
53
- {Mode : defangv1 .Mode_HOST },
53
+ name : "empty endpoint list" ,
54
+ serviceinfos : []* defangv1.ServiceInfo {
55
+ {
56
+ Service : & defangv1.Service {
57
+ Name : "service1" ,
58
+ Ports : []* defangv1.Port {
59
+ {Mode : defangv1 .Mode_INGRESS },
60
+ {Mode : defangv1 .Mode_HOST },
61
+ },
62
+ },
63
+ Status : "UNKNOWN" ,
64
+ Domainname : "example.com" ,
65
+ Endpoints : []string {},
54
66
},
55
67
},
56
- Status : "UNKNOWN" ,
57
- Endpoints : []string {
58
- "example.com" ,
59
- "service1.internal" ,
68
+ expectedLines : []string {
69
+ "Deployment Name Status Endpoints DomainName" ,
70
+ " service1 NOT_SPECIFIED N/A https://example.com" ,
71
+ " * Run `defang cert generate` to get a TLS certificate for your service(s)" ,
72
+ "" ,
60
73
},
61
- }})
62
- const expectedOutput = `Deployment Name Status Endpoints
63
- service1 NOT_SPECIFIED example.com, service1.internal
64
- `
65
- receivedLines := strings .Split (stdout .String (), "\n " )
66
- expectedLines := strings .Split (expectedOutput , "\n " )
67
-
68
- if len (receivedLines ) != len (expectedLines ) {
69
- t .Errorf ("Expected %v lines, received %v" , len (expectedLines ), len (receivedLines ))
70
- }
71
-
72
- for i , receivedLine := range receivedLines {
73
- receivedLine = strings .TrimRight (receivedLine , " " )
74
- if receivedLine != expectedLines [i ] {
75
- t .Errorf ("\n -%v\n +%v" , expectedLines [i ], receivedLine )
76
- }
77
- }
78
- }
79
-
80
- func TestPrintServiceStatesAndEndpointsAndDomainname (t * testing.T ) {
81
- defaultTerm := term .DefaultTerm
82
- t .Cleanup (func () {
83
- term .DefaultTerm = defaultTerm
84
- })
85
-
86
- var stdout , stderr bytes.Buffer
87
- term .DefaultTerm = term .NewTerm (os .Stdin , & stdout , & stderr )
88
-
89
- _ = printServiceStatesAndEndpoints ([]* defangv1.ServiceInfo {
74
+ },
90
75
{
91
- Service : & defangv1.Service {
92
- Name : "service1" ,
93
- Ports : []* defangv1.Port {
94
- {Mode : defangv1 .Mode_INGRESS },
95
- {Mode : defangv1 .Mode_HOST },
76
+ name : "Service with Domainname" ,
77
+ serviceinfos : []* defangv1.ServiceInfo {
78
+ {
79
+ Service : & defangv1.Service {
80
+ Name : "service1" ,
81
+ Ports : []* defangv1.Port {
82
+ {Mode : defangv1 .Mode_INGRESS },
83
+ {Mode : defangv1 .Mode_HOST },
84
+ },
85
+ },
86
+ Status : "UNKNOWN" ,
87
+ Domainname : "example.com" ,
88
+ Endpoints : []string {
89
+ "example.com" ,
90
+ "service1.internal:80" ,
91
+ },
96
92
},
97
93
},
98
- Status : "UNKNOWN" ,
99
- Domainname : "example.com " ,
100
- Endpoints : [] string {
101
- "example.com " ,
102
- "service1.internal " ,
94
+ expectedLines : [] string {
95
+ "Deployment Name Status Endpoints DomainName " ,
96
+ " service1 NOT_SPECIFIED https://example.com, service1.internal:80 https://example.com" ,
97
+ " * Run `defang cert generate` to get a TLS certificate for your service(s) " ,
98
+ "" ,
103
99
},
104
- }})
105
- expectedLines := []string {
106
- "Deployment Name Status Endpoints DomainName" ,
107
- " service1 NOT_SPECIFIED example.com, service1.internal https://example.com" ,
108
- " * Run `defang cert generate` to get a TLS certificate for your service(s)" ,
109
- "" ,
100
+ },
101
+ {
102
+ name : "endpoint without port" ,
103
+ serviceinfos : []* defangv1.ServiceInfo {
104
+ {
105
+ Service : & defangv1.Service {
106
+ Name : "service1" ,
107
+ Ports : []* defangv1.Port {
108
+ {Mode : defangv1 .Mode_INGRESS },
109
+ {Mode : defangv1 .Mode_HOST },
110
+ },
111
+ },
112
+ Status : "UNKNOWN" ,
113
+ Endpoints : []string {
114
+ "service1" ,
115
+ },
116
+ },
117
+ },
118
+ expectedLines : []string {
119
+ "Deployment Name Status Endpoints" ,
120
+ " service1 NOT_SPECIFIED https://service1" ,
121
+ "" ,
122
+ },
123
+ },
110
124
}
111
- receivedLines := strings .Split (stdout .String (), "\n " )
125
+ for _ , tt := range tests {
126
+ t .Run (tt .name , func (t * testing.T ) {
127
+ // Reset stdout before each test
128
+ stdout .Reset ()
112
129
113
- if len (receivedLines ) != len (expectedLines ) {
114
- t .Errorf ("Expected %v lines, received %v" , len (expectedLines ), len (receivedLines ))
115
- }
130
+ _ = printServiceStatesAndEndpoints (tt .serviceinfos )
131
+ receivedLines := strings .Split (stdout .String (), "\n " )
132
+
133
+ if len (receivedLines ) != len (tt .expectedLines ) {
134
+ t .Errorf ("Expected %v lines, received %v" , len (tt .expectedLines ), len (receivedLines ))
135
+ }
116
136
117
- for i , receivedLine := range receivedLines {
118
- receivedLine = strings .TrimRight (receivedLine , " " )
119
- if receivedLine != expectedLines [i ] {
120
- t .Errorf ("\n -%v\n +%v" , expectedLines [i ], receivedLine )
121
- }
137
+ for i , receivedLine := range receivedLines {
138
+ receivedLine = strings .TrimRight (receivedLine , " " )
139
+ if receivedLine != tt .expectedLines [i ] {
140
+ t .Errorf ("\n -%v\n +%v" , tt .expectedLines [i ], receivedLine )
141
+ }
142
+ }
143
+ })
122
144
}
123
145
}
0 commit comments