forked from scaleway/scaleway-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lb): fix list private network command (scaleway#3537)
- Loading branch information
Showing
7 changed files
with
593 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package lb | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/scaleway/scaleway-cli/v2/internal/human" | ||
"github.com/scaleway/scaleway-sdk-go/api/lb/v1" | ||
) | ||
|
||
func lbPrivateNetworksMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) { | ||
privateNetworks, ok := i.([]*lb.PrivateNetwork) | ||
if !ok { | ||
return "", fmt.Errorf("invalid type: expected []*lb.PrivateNetwork") | ||
} | ||
|
||
type customPrivateNetwork struct { | ||
IpamIDs []string `json:"ipam_ids,omitempty"` | ||
DHCPConfigIPID *string `json:"dhcp_config_ip_id,omitempty"` | ||
StaticConfigIPAddress *[]string `json:"static_config_ip_address,omitempty"` | ||
PrivateNetworkID string `json:"private_network_id"` | ||
Status lb.PrivateNetworkStatus `json:"status"` | ||
CreatedAt *time.Time `json:"created_at"` | ||
UpdatedAt *time.Time `json:"updated_at"` | ||
} | ||
|
||
customPrivateNetworks := make([]customPrivateNetwork, 0, len(privateNetworks)) | ||
for _, pn := range privateNetworks { | ||
if pn == nil { | ||
continue | ||
} | ||
|
||
customPN := customPrivateNetwork{ | ||
IpamIDs: pn.IpamIDs, | ||
PrivateNetworkID: pn.PrivateNetworkID, | ||
Status: pn.Status, | ||
CreatedAt: pn.CreatedAt, | ||
UpdatedAt: pn.UpdatedAt, | ||
} | ||
|
||
//nolint: staticcheck | ||
if pn.DHCPConfig != nil { | ||
customPN.DHCPConfigIPID = pn.DHCPConfig.IPID | ||
} | ||
|
||
//nolint: staticcheck | ||
if pn.StaticConfig != nil { | ||
customPN.StaticConfigIPAddress = pn.StaticConfig.IPAddress | ||
} | ||
|
||
customPrivateNetworks = append(customPrivateNetworks, customPN) | ||
} | ||
|
||
return human.Marshal(customPrivateNetworks, opt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package lb | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/scaleway/scaleway-cli/v2/internal/core" | ||
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/vpc/v2" | ||
) | ||
|
||
func Test_ListLBPrivateNetwork(t *testing.T) { | ||
cmds := GetCommands() | ||
cmds.Merge(vpc.GetCommands()) | ||
|
||
t.Run("Simple", core.Test(&core.TestConfig{ | ||
Commands: cmds, | ||
BeforeFunc: core.BeforeFuncCombine( | ||
createLB(), | ||
createPN(), | ||
attachPN(), | ||
), | ||
Cmd: "scw lb private-network list {{ .LB.ID }}", | ||
Check: core.TestCheckGolden(), | ||
AfterFunc: core.AfterFuncCombine( | ||
detachPN(), | ||
deleteLB(), | ||
core.AfterFuncWhenUpdatingCassette( | ||
func(ctx *core.AfterFuncCtx) error { | ||
time.Sleep(10 * time.Second) | ||
return nil | ||
}, | ||
), | ||
deletePN(), | ||
), | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.