Skip to content

Commit d41dad0

Browse files
committed
tabels in status
1 parent 3215197 commit d41dad0

2 files changed

Lines changed: 146 additions & 38 deletions

File tree

internal/cmd/beta/vpn/gateway/status/status.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,21 @@ func outputResult(p *print.Printer, outputFormat, gatewayId, projectLabel string
115115
mainTable,
116116
}
117117
for _, tunnel := range gateway.Tunnels {
118-
ts = append(ts, tunnelTable(tunnel))
118+
ts = append(ts, tunnelTable(tunnel)...)
119119
}
120120

121121
return tables.DisplayTables(p, ts)
122122
})
123123
}
124124

125-
func tunnelTable(tunnel vpn.VPNTunnels) tables.Table {
125+
func tunnelTable(tunnel vpn.VPNTunnels) []tables.Table {
126126
title := "Tunnel"
127127
if tunnel.Name != nil {
128128
title = string(*tunnel.Name)
129129
}
130130

131+
tunnelTables := []tables.Table{}
132+
131133
table := tables.NewTable()
132134
table.SetTitle(title)
133135

@@ -138,44 +140,42 @@ func tunnelTable(tunnel vpn.VPNTunnels) tables.Table {
138140
table.AddSeparator()
139141
table.AddRow("STATE", tunnel.GetInstanceState())
140142

143+
tunnelTables = append(tunnelTables, table)
144+
141145
if tunnel.BgpStatus.IsSet() {
142-
table.AddSeparator()
143-
routeString := ""
146+
bgpRoutesTable := tables.NewTable()
147+
bgpRoutesTable.SetTitle(title + " - BGP Routes")
148+
bgpRoutesTable.SetHeader("Network", "Origin", "Path", "Peer ID", "Weight")
144149
for _, route := range tunnel.BgpStatus.Get().Routes {
145-
if route.Network != "" {
146-
routeString += fmt.Sprintf("Network: %s; ", route.Network)
147-
}
148-
if route.Origin != "" {
149-
routeString += fmt.Sprintf("Origin: %s; ", route.Origin)
150-
}
151-
if route.Path != "" {
152-
routeString += fmt.Sprintf("Path: %s; ", route.Path)
153-
}
154-
if route.PeerId != "" {
155-
routeString += fmt.Sprintf("PeerId: %s; ", route.PeerId)
156-
}
157-
routeString += fmt.Sprintf("Weight: %d\n", route.Weight)
150+
bgpRoutesTable.AddRow(
151+
route.Network,
152+
route.Origin,
153+
route.Path,
154+
route.PeerId,
155+
route.Weight,
156+
)
157+
bgpRoutesTable.AddSeparator()
158158
}
159-
table.AddRow("BGP Routes", routeString)
160-
table.AddSeparator()
161-
bgpPeers := ""
159+
tunnelTables = append(tunnelTables, bgpRoutesTable)
160+
161+
bgpPeersTable := tables.NewTable()
162+
bgpPeersTable.SetTitle(title + " - BGP Peers")
163+
bgpPeersTable.SetHeader("Peer Uptime", "Remote IP", "STATE", "Local ASN", "PfxRcd", "PfxSnt", "RemoteAs")
164+
162165
for _, peer := range tunnel.BgpStatus.Get().Peers {
163-
if peer.PeerUptime != "" {
164-
bgpPeers += fmt.Sprintf("PeerUptime: %s; ", peer.PeerUptime)
165-
}
166-
if peer.RemoteIP != "" {
167-
bgpPeers += fmt.Sprintf("RemoteIP: %s; ", peer.RemoteIP)
168-
}
169-
if peer.State != "" {
170-
bgpPeers += fmt.Sprintf("State: %s; ", peer.State)
171-
}
172-
bgpPeers += fmt.Sprintf("LocalAsn: %d; ", peer.LocalAs)
173-
bgpPeers += fmt.Sprintf("PfxRcd: %d; ", peer.PfxRcd)
174-
bgpPeers += fmt.Sprintf("PfxSnt: %d; ", peer.PfxSnt)
175-
bgpPeers += fmt.Sprintf("RemoteAs: %d\n", peer.RemoteAs)
166+
bgpPeersTable.AddRow(
167+
peer.PeerUptime,
168+
peer.RemoteIP,
169+
peer.State,
170+
peer.LocalAs,
171+
peer.PfxRcd,
172+
peer.PfxSnt,
173+
peer.RemoteAs,
174+
)
175+
bgpPeersTable.AddSeparator()
176176
}
177-
table.AddRow("BGP Peers", bgpPeers)
177+
tunnelTables = append(tunnelTables, bgpPeersTable)
178178
}
179179

180-
return table
180+
return tunnelTables
181181
}

internal/cmd/beta/vpn/gateway/status/status_test.go

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ package status
22

33
import (
44
"context"
5+
"os"
56
"testing"
67

78
"github.com/google/go-cmp/cmp"
89
"github.com/google/go-cmp/cmp/cmpopts"
910
"github.com/google/uuid"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1012
vpn "github.com/stackitcloud/stackit-sdk-go/services/vpn/v1api"
1113

1214
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13-
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1416
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1517
)
1618

@@ -196,12 +198,118 @@ func TestOutputResult(t *testing.T) {
196198
},
197199
wantErr: false,
198200
},
201+
{
202+
name: "set response",
203+
args: args{
204+
gateway: &vpn.GatewayStatusResponse{
205+
Id: utils.Ptr(testGatewayId),
206+
Connections: []vpn.ConnectionStatusResponse{},
207+
DisplayName: utils.Ptr("test"),
208+
ErrorMessage: nil,
209+
GatewayStatus: utils.Ptr(vpn.GATEWAYSTATUS_READY),
210+
Tunnels: []vpn.VPNTunnels{
211+
{
212+
BgpStatus: *vpn.NewNullableBGPStatus(&vpn.BGPStatus{
213+
Peers: []vpn.BGPStatusPeers{
214+
{
215+
LocalAs: 23,
216+
PeerUptime: "~10s",
217+
PfxRcd: 3,
218+
PfxSnt: 5,
219+
RemoteAs: 224,
220+
RemoteIP: "1.1.1.1",
221+
State: "Healthy",
222+
},
223+
{
224+
LocalAs: 25,
225+
PeerUptime: "~14s",
226+
PfxRcd: 1,
227+
PfxSnt: 99,
228+
RemoteAs: 4,
229+
RemoteIP: "2.2.2.2",
230+
State: "Unhealthy",
231+
},
232+
},
233+
Routes: []vpn.BGPStatusRoutes{
234+
{
235+
Network: "home",
236+
Origin: "root",
237+
Path: "~/",
238+
PeerId: "5",
239+
Weight: 1,
240+
},
241+
{
242+
Network: "remote",
243+
Origin: "internet",
244+
Path: "/path/",
245+
PeerId: "3",
246+
Weight: 44,
247+
},
248+
},
249+
}),
250+
InstanceState: utils.Ptr(vpn.GATEWAYSTATUS_READY),
251+
InternalNextHopIP: utils.Ptr("1.2.3.4"),
252+
Name: utils.Ptr(vpn.VPNTUNNELSNAME_TUNNEL1),
253+
PublicIP: utils.Ptr("9.9.9.9"),
254+
},
255+
{
256+
BgpStatus: *vpn.NewNullableBGPStatus(&vpn.BGPStatus{
257+
Peers: []vpn.BGPStatusPeers{
258+
{
259+
LocalAs: 23,
260+
PeerUptime: "~10s",
261+
PfxRcd: 3,
262+
PfxSnt: 5,
263+
RemoteAs: 224,
264+
RemoteIP: "1.1.1.1",
265+
State: "Healthy",
266+
},
267+
{
268+
LocalAs: 25,
269+
PeerUptime: "~14s",
270+
PfxRcd: 1,
271+
PfxSnt: 99,
272+
RemoteAs: 4,
273+
RemoteIP: "2.2.2.2",
274+
State: "Unhealthy",
275+
},
276+
},
277+
Routes: []vpn.BGPStatusRoutes{
278+
{
279+
Network: "home",
280+
Origin: "root",
281+
Path: "~/",
282+
PeerId: "5",
283+
Weight: 1,
284+
},
285+
{
286+
Network: "remote",
287+
Origin: "internet",
288+
Path: "/path/",
289+
PeerId: "3",
290+
Weight: 44,
291+
},
292+
},
293+
}),
294+
InstanceState: utils.Ptr(vpn.GATEWAYSTATUS_PENDING),
295+
InternalNextHopIP: utils.Ptr("4.4.4.4"),
296+
Name: utils.Ptr(vpn.VPNTUNNELSNAME_TUNNEL2),
297+
PublicIP: utils.Ptr("3.3.3.3"),
298+
},
299+
},
300+
},
301+
},
302+
},
199303
}
200-
params := testparams.NewTestParams()
304+
printer := print.NewPrinter(
305+
os.Stdin,
306+
os.Stdout,
307+
os.Stderr,
308+
)
201309

202310
for _, tt := range tests {
203311
t.Run(tt.name, func(t *testing.T) {
204-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.gatewayId, tt.args.gateway); (err != nil) != tt.wantErr {
312+
if err := outputResult(printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.gatewayId, tt.args.gateway); (err != nil) != tt.wantErr {
205313
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
206314
}
207315
})

0 commit comments

Comments
 (0)