2019-01-23 08:04:05 -05:00
|
|
|
package hyperone
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-03-22 09:53:28 -04:00
|
|
|
openapi "github.com/hyperonecom/h1-client-go"
|
2019-01-23 08:04:05 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPickNetAdapter(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
Config Config
|
|
|
|
Expected openapi.VmCreateNetadp
|
|
|
|
}{
|
|
|
|
{
|
2019-02-02 08:03:44 -05:00
|
|
|
Name: "no_network",
|
|
|
|
Config: Config{
|
|
|
|
PublicNetAdpService: "public",
|
|
|
|
},
|
2019-01-23 08:04:05 -05:00
|
|
|
Expected: openapi.VmCreateNetadp{
|
|
|
|
Service: "public",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "no_network_public_ip",
|
|
|
|
Config: Config{
|
2019-02-02 08:03:44 -05:00
|
|
|
PublicIP: "some-public-ip",
|
|
|
|
PublicNetAdpService: "public",
|
2019-01-23 08:04:05 -05:00
|
|
|
},
|
|
|
|
Expected: openapi.VmCreateNetadp{
|
|
|
|
Service: "public",
|
|
|
|
Ip: []string{"some-public-ip"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "no_network_private_ip",
|
|
|
|
Config: Config{
|
2019-02-02 08:03:44 -05:00
|
|
|
PrivateIP: "some-private-ip",
|
|
|
|
PublicNetAdpService: "public",
|
2019-01-23 08:04:05 -05:00
|
|
|
},
|
|
|
|
Expected: openapi.VmCreateNetadp{
|
|
|
|
Service: "public",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "no_network_both_ip",
|
|
|
|
Config: Config{
|
2019-02-02 08:03:44 -05:00
|
|
|
PublicIP: "some-public-ip",
|
|
|
|
PrivateIP: "some-private-ip",
|
|
|
|
PublicNetAdpService: "public",
|
2019-01-23 08:04:05 -05:00
|
|
|
},
|
|
|
|
Expected: openapi.VmCreateNetadp{
|
|
|
|
Service: "public",
|
|
|
|
Ip: []string{"some-public-ip"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "network_no_ip",
|
|
|
|
Config: Config{
|
2019-02-02 08:03:44 -05:00
|
|
|
Network: "some-network",
|
|
|
|
PublicNetAdpService: "public",
|
2019-01-23 08:04:05 -05:00
|
|
|
},
|
|
|
|
Expected: openapi.VmCreateNetadp{
|
|
|
|
Service: "private",
|
|
|
|
Network: "some-network",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "network_public_ip",
|
|
|
|
Config: Config{
|
2019-02-02 08:03:44 -05:00
|
|
|
Network: "some-network",
|
|
|
|
PublicIP: "some-public-ip",
|
|
|
|
PublicNetAdpService: "public",
|
2019-01-23 08:04:05 -05:00
|
|
|
},
|
|
|
|
Expected: openapi.VmCreateNetadp{
|
|
|
|
Service: "private",
|
|
|
|
Network: "some-network",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "network_private_ip",
|
|
|
|
Config: Config{
|
2019-02-02 08:03:44 -05:00
|
|
|
Network: "some-network",
|
|
|
|
PrivateIP: "some-private-ip",
|
|
|
|
PublicNetAdpService: "public",
|
2019-01-23 08:04:05 -05:00
|
|
|
},
|
|
|
|
Expected: openapi.VmCreateNetadp{
|
|
|
|
Service: "private",
|
|
|
|
Network: "some-network",
|
|
|
|
Ip: []string{"some-private-ip"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "network_both_ip",
|
|
|
|
Config: Config{
|
2019-02-02 08:03:44 -05:00
|
|
|
Network: "some-network",
|
|
|
|
PublicIP: "some-public-ip",
|
|
|
|
PrivateIP: "some-private-ip",
|
|
|
|
PublicNetAdpService: "public",
|
2019-01-23 08:04:05 -05:00
|
|
|
},
|
|
|
|
Expected: openapi.VmCreateNetadp{
|
|
|
|
Service: "private",
|
|
|
|
Network: "some-network",
|
|
|
|
Ip: []string{"some-private-ip"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
t.Run(c.Name, func(t *testing.T) {
|
|
|
|
result := pickNetAdapter(&c.Config)
|
|
|
|
assert.Equal(t, c.Expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|