Skip to content

Commit

Permalink
test floatingip v6
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Jul 11, 2024
1 parent b8325da commit 3da6a85
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions e2e_tests/floatingip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e_tests

import (
"fmt"
"net"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -178,6 +179,57 @@ $`, out)
out, err = runCommand(t, "floating-ip", "delete", strconv.Itoa(floatingIPId))
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("Floating IP %d deleted\n", floatingIPId), out)

floatingIPId, err = createFloatingIP(t, "test-floating-ip", "ipv6", "--home-location", "fsn1")
if err != nil {
t.Fatal(err)
}

out, err = runCommand(t, "floating-ip", "describe", strconv.Itoa(floatingIPId))
assert.NoError(t, err)
assert.Regexp(t, `ID:\s+[0-9]+
Type:\s+ipv6
Name:\s+test-floating-ip
Description:\s+-
Created:.*?
IP:\s+[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+::\/64
Blocked:\s+no
Home Location:\s+fsn1
Server:
\s+Not assigned
DNS:
\s+No reverse DNS entries
Protection:
\s+Delete:\s+no
Labels:
\s+No labels
`, out)

out, err = runCommand(t, "floating-ip", "describe", strconv.Itoa(floatingIPId), "--output", "format={{.IP}}")
assert.NoError(t, err)
out = strings.TrimSpace(out)
ipv6 := net.ParseIP(out)
if ipv6 != nil {
out, err = runCommand(t, "floating-ip", "set-rdns", strconv.Itoa(floatingIPId), "--ip", ipv6.String()+"1", "--hostname", "s1.example.com")
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("Reverse DNS of Floating IP %d changed\n", floatingIPId), out)

out, err = runCommand(t, "floating-ip", "set-rdns", strconv.Itoa(floatingIPId), "--ip", ipv6.String()+"2", "--hostname", "s2.example.com")
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("Reverse DNS of Floating IP %d changed\n", floatingIPId), out)
} else {
t.Errorf("invalid IPv6 address: %s", out)
}

out, err = runCommand(t, "floating-ip", "list", "-o", "columns=ip,dns")
assert.NoError(t, err)
assert.Regexp(t, fmt.Sprintf(`^IP +DNS
%s\/64 +2 entries
`, ipv6), out)

out, err = runCommand(t, "floating-ip", "delete", strconv.Itoa(floatingIPId))
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("Floating IP %d deleted\n", floatingIPId), out)
}

func createFloatingIP(t *testing.T, name, ipType string, args ...string) (int, error) {
Expand Down

0 comments on commit 3da6a85

Please sign in to comment.