-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
173 additions
and
9 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,44 @@ | ||
package proxmox | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sp-yduck/proxmox-go/api" | ||
) | ||
|
||
func (s *TestSuite) TestVirtualMachine() { | ||
_, testVM := s.getTestVirtualMachine() | ||
vm, err := s.service.VirtualMachine(context.TODO(), testVM.VM.VMID) | ||
if err != nil { | ||
s.T().Fatalf("failed to get vm(vmid=%d): %v", testVM.VM.VMID, err) | ||
} | ||
s.Assert().Equal(*vm, *testVM) | ||
} | ||
|
||
func (s *TestSuite) TestStop() { | ||
_, testVM := s.getTestVirtualMachine() | ||
if err := testVM.Stop(context.TODO(), api.VirtualMachineStopOption{}); err != nil { | ||
s.T().Fatalf("failed to stop vm: %v", err) | ||
} | ||
} | ||
|
||
func (s *TestSuite) getTestNode() *api.Node { | ||
nodes, err := s.service.restclient.GetNodes(context.TODO()) | ||
if err != nil { | ||
s.T().Fatalf("failed to get nodes: %v", err) | ||
} | ||
return nodes[0] | ||
} | ||
|
||
func (s *TestSuite) getTestVirtualMachine() (*api.Node, *VirtualMachine) { | ||
node := s.getTestNode() | ||
vms, err := s.service.restclient.GetVirtualMachines(context.TODO(), node.Node) | ||
if err != nil { | ||
s.T().Fatalf("failed to get vms: %v", err) | ||
} | ||
vm, err := s.service.VirtualMachine(context.TODO(), vms[0].VMID) | ||
if err != nil { | ||
s.T().Fatalf("failed to get vm: %v", err) | ||
} | ||
return node, vm | ||
} |
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,41 @@ | ||
package proxmox | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type TestSuite struct { | ||
suite.Suite | ||
service Service | ||
} | ||
|
||
func (s *TestSuite) SetupSuite() { | ||
url := os.Getenv("PROXMOX_URL") | ||
user := os.Getenv("PROXMOX_USERNAME") | ||
password := os.Getenv("PROXMOX_PASSWORD") | ||
tokeid := os.Getenv("PROXMOX_TOKENID") | ||
secret := os.Getenv("PROXMOX_SECRET") | ||
if url == "" { | ||
s.T().Fatal("url must not be empty") | ||
} | ||
|
||
authConfig := AuthConfig{ | ||
Username: user, | ||
Password: password, | ||
TokenID: tokeid, | ||
Secret: secret, | ||
} | ||
|
||
service, err := NewService(url, authConfig, true) | ||
if err != nil { | ||
s.T().Fatalf("failed to create new service: %v", err) | ||
} | ||
s.service = *service | ||
} | ||
|
||
func TestSuiteIntegration(t *testing.T) { | ||
suite.Run(t, new(TestSuite)) | ||
} |
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,33 @@ | ||
package proxmox | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sp-yduck/proxmox-go/api" | ||
) | ||
|
||
func (s *TestSuite) TestMustGetTask() { | ||
testNode, testTask := s.getTestTask() | ||
task, err := s.service.MustGetTask(context.TODO(), testNode.Node, testTask.UPID) | ||
if err != nil { | ||
s.T().Fatalf("failed to get task: %v", err) | ||
} | ||
s.Assert().Equal(*task, *testTask) | ||
} | ||
|
||
func (s *TestSuite) TestEnsureTaskDone() { | ||
testNode, testTask := s.getTestTask() | ||
err := s.service.EnsureTaskDone(context.TODO(), testNode.Node, testTask.UPID) | ||
if err != nil { | ||
s.T().Fatalf("failed to get task: %v", err) | ||
} | ||
} | ||
|
||
func (s *TestSuite) getTestTask() (*api.Node, *api.Task) { | ||
node := s.getTestNode() | ||
tasks, err := s.service.restclient.GetTasks(context.TODO(), node.Node) | ||
if err != nil { | ||
s.T().Fatalf("failed to get tasks: %v", err) | ||
} | ||
return node, tasks[0] | ||
} |
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