Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions internal/cmd/beta/vpn/gateway/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,21 @@ func outputResult(p *print.Printer, outputFormat, gatewayId, projectLabel string
mainTable,
}
for _, tunnel := range gateway.Tunnels {
ts = append(ts, tunnelTable(tunnel))
ts = append(ts, tunnelTable(tunnel)...)
}

return tables.DisplayTables(p, ts)
})
}

func tunnelTable(tunnel vpn.VPNTunnels) tables.Table {
func tunnelTable(tunnel vpn.VPNTunnels) []tables.Table {
title := "Tunnel"
if tunnel.Name != nil {
title = string(*tunnel.Name)
}

tunnelTables := []tables.Table{}

table := tables.NewTable()
table.SetTitle(title)

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

tunnelTables = append(tunnelTables, table)

if tunnel.BgpStatus.IsSet() {
table.AddSeparator()
routeString := ""
bgpRoutesTable := tables.NewTable()
bgpRoutesTable.SetTitle(title + " - BGP Routes")
bgpRoutesTable.SetHeader("Network", "Origin", "Path", "Peer ID", "Weight")
for _, route := range tunnel.BgpStatus.Get().Routes {
if route.Network != "" {
routeString += fmt.Sprintf("Network: %s; ", route.Network)
}
if route.Origin != "" {
routeString += fmt.Sprintf("Origin: %s; ", route.Origin)
}
if route.Path != "" {
routeString += fmt.Sprintf("Path: %s; ", route.Path)
}
if route.PeerId != "" {
routeString += fmt.Sprintf("PeerId: %s; ", route.PeerId)
}
routeString += fmt.Sprintf("Weight: %d\n", route.Weight)
bgpRoutesTable.AddRow(
route.Network,
route.Origin,
route.Path,
route.PeerId,
route.Weight,
)
bgpRoutesTable.AddSeparator()
}
Comment thread
Manuelvaas marked this conversation as resolved.
table.AddRow("BGP Routes", routeString)
table.AddSeparator()
bgpPeers := ""
tunnelTables = append(tunnelTables, bgpRoutesTable)

bgpPeersTable := tables.NewTable()
bgpPeersTable.SetTitle(title + " - BGP Peers")
bgpPeersTable.SetHeader("Peer Uptime", "Remote IP", "STATE", "Local ASN", "PfxRcd", "PfxSnt", "RemoteAs")

for _, peer := range tunnel.BgpStatus.Get().Peers {
if peer.PeerUptime != "" {
bgpPeers += fmt.Sprintf("PeerUptime: %s; ", peer.PeerUptime)
}
if peer.RemoteIP != "" {
bgpPeers += fmt.Sprintf("RemoteIP: %s; ", peer.RemoteIP)
}
if peer.State != "" {
bgpPeers += fmt.Sprintf("State: %s; ", peer.State)
}
bgpPeers += fmt.Sprintf("LocalAsn: %d; ", peer.LocalAs)
bgpPeers += fmt.Sprintf("PfxRcd: %d; ", peer.PfxRcd)
bgpPeers += fmt.Sprintf("PfxSnt: %d; ", peer.PfxSnt)
bgpPeers += fmt.Sprintf("RemoteAs: %d\n", peer.RemoteAs)
bgpPeersTable.AddRow(
peer.PeerUptime,
peer.RemoteIP,
peer.State,
peer.LocalAs,
peer.PfxRcd,
peer.PfxSnt,
peer.RemoteAs,
)
bgpPeersTable.AddSeparator()
}
table.AddRow("BGP Peers", bgpPeers)
tunnelTables = append(tunnelTables, bgpPeersTable)
}

return table
return tunnelTables
}
114 changes: 111 additions & 3 deletions internal/cmd/beta/vpn/gateway/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import (
"context"
"os"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

Check failure on line 11 in internal/cmd/beta/vpn/gateway/status/status_test.go

View workflow job for this annotation

GitHub Actions / CI

File is not properly formatted (goimports)
vpn "github.com/stackitcloud/stackit-sdk-go/services/vpn/v1api"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
)

Expand Down Expand Up @@ -196,12 +198,118 @@
},
wantErr: false,
},
{
name: "set response",
args: args{
gateway: &vpn.GatewayStatusResponse{
Id: utils.Ptr(testGatewayId),
Connections: []vpn.ConnectionStatusResponse{},
DisplayName: utils.Ptr("test"),
ErrorMessage: nil,
GatewayStatus: utils.Ptr(vpn.GATEWAYSTATUS_READY),
Tunnels: []vpn.VPNTunnels{
{
BgpStatus: *vpn.NewNullableBGPStatus(&vpn.BGPStatus{
Peers: []vpn.BGPStatusPeers{
{
LocalAs: 23,
PeerUptime: "~10s",
PfxRcd: 3,
PfxSnt: 5,
RemoteAs: 224,
RemoteIP: "1.1.1.1",
State: "Healthy",
},
{
LocalAs: 25,
PeerUptime: "~14s",
PfxRcd: 1,
PfxSnt: 99,
RemoteAs: 4,
RemoteIP: "2.2.2.2",
State: "Unhealthy",
},
},
Routes: []vpn.BGPStatusRoutes{
{
Network: "home",
Origin: "root",
Path: "~/",
PeerId: "5",
Weight: 1,
},
{
Network: "remote",
Origin: "internet",
Path: "/path/",
PeerId: "3",
Weight: 44,
},
},
}),
InstanceState: utils.Ptr(vpn.GATEWAYSTATUS_READY),
InternalNextHopIP: utils.Ptr("1.2.3.4"),
Name: utils.Ptr(vpn.VPNTUNNELSNAME_TUNNEL1),
PublicIP: utils.Ptr("9.9.9.9"),
},
{
BgpStatus: *vpn.NewNullableBGPStatus(&vpn.BGPStatus{
Peers: []vpn.BGPStatusPeers{
{
LocalAs: 23,
PeerUptime: "~10s",
PfxRcd: 3,
PfxSnt: 5,
RemoteAs: 224,
RemoteIP: "1.1.1.1",
State: "Healthy",
},
{
LocalAs: 25,
PeerUptime: "~14s",
PfxRcd: 1,
PfxSnt: 99,
RemoteAs: 4,
RemoteIP: "2.2.2.2",
State: "Unhealthy",
},
},
Routes: []vpn.BGPStatusRoutes{
{
Network: "home",
Origin: "root",
Path: "~/",
PeerId: "5",
Weight: 1,
},
{
Network: "remote",
Origin: "internet",
Path: "/path/",
PeerId: "3",
Weight: 44,
},
},
}),
InstanceState: utils.Ptr(vpn.GATEWAYSTATUS_PENDING),
InternalNextHopIP: utils.Ptr("4.4.4.4"),
Name: utils.Ptr(vpn.VPNTUNNELSNAME_TUNNEL2),
PublicIP: utils.Ptr("3.3.3.3"),
},
},
},
},
},
}
params := testparams.NewTestParams()
printer := print.NewPrinter(
os.Stdin,
os.Stdout,
os.Stderr,
)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.gatewayId, tt.args.gateway); (err != nil) != tt.wantErr {
if err := outputResult(printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.gatewayId, tt.args.gateway); (err != nil) != tt.wantErr {
Comment thread
Manuelvaas marked this conversation as resolved.
Outdated
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
Loading