Skip to content

Commit

Permalink
Add: TestNode_VncProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoalcantara committed Sep 18, 2024
1 parent 8737301 commit f714768
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
40 changes: 40 additions & 0 deletions tests/integration/nodes_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"bytes"
"context"
"fmt"
"strings"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/luthermonson/go-proxmox"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNodes(t *testing.T) {
Expand Down Expand Up @@ -146,3 +148,41 @@ func TestNode_TermProxy(t *testing.T) {
send <- []byte("exit\n")
time.Sleep(1 * time.Second)
}

func TestNode_VncProxy(t *testing.T) {
assert.NotEqual(t, 0, td.vncVmId)

vm, err := td.node.VirtualMachine(context.TODO(), td.vncVmId)
require.NoError(t, err)

vnc, err := vm.VNCProxy(context.TODO(), nil)
require.NoError(t, err)

send, recv, errs, close, err := vm.VNCWebSocket(vnc)
assert.Nil(t, err)
defer close()

go func() {
for {
select {
case msg := <-recv:
if len(msg) > 0 {
fmt.Printf("MSG: %s -> %v\n", string(msg), msg)
if strings.HasPrefix(string(msg), "RFB") {
send <- msg
}
if bytes.Equal(msg, []byte{0x01, 0x02}) {
fmt.Println("Success!")
}
}
case err := <-errs:
if err != nil {
fmt.Println("ERROR: " + err.Error())
return
}
}
}
}()

time.Sleep(5 * time.Second)
}
9 changes: 8 additions & 1 deletion tests/integration/proxmox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/rand"
"net/http"
"os"
"strconv"
"testing"
"time"

Expand All @@ -32,6 +33,7 @@ type TestingData struct {
nodeStorage string
isoURL string
appliancePrefix string
vncVmId int
}

var (
Expand All @@ -52,6 +54,8 @@ var (
)

func init() {
var err error

td.username = os.Getenv("PROXMOX_USERNAME")
td.password = os.Getenv("PROXMOX_PASSWORD")
td.otp = os.Getenv("PROXMOX_OTP")
Expand All @@ -61,14 +65,17 @@ func init() {
td.nodeStorage = os.Getenv("PROXMOX_NODE_STORAGE")
td.isoURL = os.Getenv("PROXMOX_ISO_URL") // https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/x86_64/alpine-virt-3.14.1-x86_64.iso
td.appliancePrefix = "alpine-virt-3.14.1"
vncVmId, err := strconv.Atoi(os.Getenv("PROXMOX_VNC_VMID"))
if err == nil {
td.vncVmId = vncVmId
}

if td.nodeName == "" {
return
}

td.client = ClientFromLogins()
ctx := context.Background()
var err error

td.node, err = td.client.Node(ctx, td.nodeName)
if err != nil {
Expand Down

0 comments on commit f714768

Please sign in to comment.