|
| 1 | +package rest |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "github.com/sp-yduck/proxmox-go/api" |
| 7 | +) |
| 8 | + |
| 9 | +func (s *TestSuite) TestGetStorages() { |
| 10 | + storages, err := s.restclient.GetStorages() |
| 11 | + if err != nil { |
| 12 | + s.T().Fatalf("failed to get storages: %v", err) |
| 13 | + } |
| 14 | + s.T().Logf("get storages: %v", storages) |
| 15 | +} |
| 16 | + |
| 17 | +func (s *TestSuite) GetTestStorage() *api.Storage { |
| 18 | + storages, err := s.restclient.GetStorages() |
| 19 | + if err != nil { |
| 20 | + s.T().Fatalf("failed to get storages: %v", err) |
| 21 | + } |
| 22 | + return storages[0] |
| 23 | +} |
| 24 | + |
| 25 | +func (s *TestSuite) TestGetStorage() { |
| 26 | + testStorageName := s.GetTestStorage().Storage |
| 27 | + |
| 28 | + storage, err := s.restclient.GetStorage(testStorageName) |
| 29 | + if err != nil { |
| 30 | + s.T().Fatalf("failed to get storage(name=%s): %v", testStorageName, err) |
| 31 | + } |
| 32 | + s.T().Logf("get storage: %v", *storage) |
| 33 | +} |
| 34 | + |
| 35 | +func (s *TestSuite) EnsureNoStorage(name string) { |
| 36 | + storage, err := s.restclient.GetStorage(name) |
| 37 | + if err == nil { |
| 38 | + s.T().Logf("error: %v", err) |
| 39 | + if err := s.restclient.DeleteStorage(storage.Storage); err != nil { |
| 40 | + s.T().Fatalf("failed to ensure no storage (name=%s): %v", storage.Storage, err) |
| 41 | + } |
| 42 | + time.Sleep(2 * time.Second) |
| 43 | + } |
| 44 | + if err != nil && !IsNotFound(err) { |
| 45 | + s.T().Logf("failed to get storage(name=%s): %v", name, err) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +func (s *TestSuite) TestCreateDeleteStorage() { |
| 50 | + testStorageName := "test-proxmox-go" |
| 51 | + s.EnsureNoStorage(testStorageName) |
| 52 | + |
| 53 | + // create |
| 54 | + testOptions := api.StorageCreateOptions{ |
| 55 | + Content: "images", |
| 56 | + Mkdir: true, |
| 57 | + Path: "/var/lib/vz/test", |
| 58 | + } |
| 59 | + storage, err := s.restclient.CreateStorage(testStorageName, "dir", testOptions) |
| 60 | + if err != nil { |
| 61 | + s.T().Fatalf("failed to create storage(name=%s): %v", testStorageName, err) |
| 62 | + } |
| 63 | + s.T().Logf("create storage: %v", *storage) |
| 64 | + time.Sleep(2 * time.Second) |
| 65 | + |
| 66 | + // delete |
| 67 | + err = s.restclient.DeleteStorage(testStorageName) |
| 68 | + if err != nil { |
| 69 | + s.T().Fatalf("failed to delete storage(name=%s): %v", testStorageName, err) |
| 70 | + } |
| 71 | +} |
0 commit comments