1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
package integration
import (
"context"
"testing"
"github.com/linode/linodego"
)
func TestLongviewClient_Get_smoke(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLongviewClient_Get")
defer teardown()
createOptions := linodego.LongviewClientCreateOptions{Label: "testing"}
// Create a longview client to later fetch using get
testingLongviewClient, createErr := client.CreateLongviewClient(context.TODO(), createOptions)
if createErr != nil {
t.Errorf("Error creating longview client:%s", createErr)
}
defer func() {
if err := client.DeleteLongviewClient(context.Background(), testingLongviewClient.ID); err != nil {
t.Fatal(err)
}
}()
// Fetch the ID of the newly created longview client
testingID := testingLongviewClient.ID
// If there is no error, then GetLongviewClient works properly
longviewClient, getErr := client.GetLongviewClient(context.Background(), testingID)
if getErr != nil {
t.Errorf("Error getting longview client:%s", getErr)
}
longviewClientList, listErr := client.ListLongviewClients(context.Background(), nil)
if listErr != nil {
t.Errorf("Error listing longview clients:%s", listErr)
}
found := false
for _, element := range longviewClientList {
if element.ID == longviewClient.ID {
found = true
}
}
if !found {
t.Errorf("Longview client not found in list.")
}
}
func TestLongviewClient_Create_smoke(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLongviewClient_Create")
defer teardown()
createOptions := linodego.LongviewClientCreateOptions{Label: "testing"}
// Create a longview client to later fetch using get
testingLongviewClient, createErr := client.CreateLongviewClient(context.TODO(), createOptions)
if createErr != nil {
t.Errorf("Error creating longview client:%s", createErr)
}
defer func() {
if err := client.DeleteLongviewClient(context.Background(), testingLongviewClient.ID); err != nil {
t.Fatal(err)
}
}()
testingID := testingLongviewClient.ID
// If there is no error, then TestLongviewClient_Create works properly
_, getErr := client.GetLongviewClient(context.Background(), testingID)
if getErr != nil {
t.Errorf("Error getting longview client:%s", getErr)
}
}
func TestLongviewClient_Delete(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLongviewClient_Delete")
defer teardown()
createOptions := linodego.LongviewClientCreateOptions{Label: "testing"}
// Create a longview client to later delete
testingLongviewClient, createErr := client.CreateLongviewClient(context.TODO(), createOptions)
if createErr != nil {
t.Errorf("Error creating longview client:%s", createErr)
}
// Fetch the ID of the newly created longview client
testingID := testingLongviewClient.ID
// Make sure the longview client exists
longviewClient, getErr := client.GetLongviewClient(context.Background(), testingID)
if getErr != nil {
t.Errorf("Error getting longview client:%s", getErr)
}
// If there is no error, the longview client was deleted properly
if err := client.DeleteLongviewClient(context.Background(), testingLongviewClient.ID); err != nil {
t.Fatal(err)
}
longviewClientList, listErr := client.ListLongviewClients(context.Background(), nil)
if listErr != nil {
t.Errorf("Error listing longview clients:%s", listErr)
}
found := false
for _, element := range longviewClientList {
if element.ID == longviewClient.ID {
found = true
}
}
// If the longview client still appears in the list, then it was not deleted properly
if found {
t.Errorf("Longview client was found in list.")
}
}
func TestLongviewClient_Update(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLongviewClient_Update")
defer teardown()
createOptions := linodego.LongviewClientCreateOptions{Label: "testing"}
// Create a longview client to later update
testingLongviewClient, createErr := client.CreateLongviewClient(context.TODO(), createOptions)
if createErr != nil {
t.Errorf("Error creating longview client:%s", createErr)
}
// Fetch the ID of the newly created longview client
testingID := testingLongviewClient.ID
updateOptions := linodego.LongviewClientUpdateOptions{Label: "testing_updated"}
// Update the longview client
updatedTestingLongviewClient, updateErr := client.UpdateLongviewClient(context.TODO(), testingID, updateOptions)
if createErr != nil {
t.Errorf("Error updating longview client:%s", updateErr)
}
defer func() {
if err := client.DeleteLongviewClient(context.Background(), updatedTestingLongviewClient.ID); err != nil {
t.Fatal(err)
}
}()
// If the label does not match what it was updated to, the update was not successful
if updatedTestingLongviewClient.Label != "testing_updated" {
t.Errorf("Longview client was not updated.")
}
}
func TestLongviewPlan_Get(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLongviewPlan_Get")
defer teardown()
// Get the current longview plan
testingLongviewPlan, err := client.GetLongviewPlan(context.Background())
if err != nil {
t.Errorf("Error getting longview plan:%s", err)
}
// Ensure that a plan was returned
if testingLongviewPlan == nil {
t.Errorf("Expected a longview plan, recieved nil")
}
validIDs := []string{"longview-3", "longview-10", "longview-40", "longview-100", ""}
// Ensure that the id of the longview plan is a valid one
if !contains(validIDs, testingLongviewPlan.ID) {
t.Errorf("Invalid longview plan ID:%s", testingLongviewPlan.ID)
}
}
func TestLongviewPlan_Update(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLongviewPlan_Update")
defer teardown()
// Get the current longview plan
testingLongviewPlan, getErr := client.GetLongviewPlan(context.Background())
if getErr != nil {
t.Errorf("Error getting longview plan:%s", getErr)
}
testingID := testingLongviewPlan.ID
updateOptions := linodego.LongviewPlanUpdateOptions{LongviewSubscription: "longview-10"}
// Update the longview plan
updatedLongviewPlan, updateErr := client.UpdateLongviewPlan(context.Background(), updateOptions)
if updateErr != nil {
t.Errorf("Error updating longview plan:%s", updateErr)
}
// Set the longview plan to what it was before (after the test)
defer func() {
resetOptions := linodego.LongviewPlanUpdateOptions{LongviewSubscription: testingID}
if _, err := client.UpdateLongviewPlan(context.Background(), resetOptions); err != nil {
t.Fatal(err)
}
}()
// Ensure the longview plan was updated correctly
if updatedLongviewPlan.ID != "longview-10" {
t.Errorf("Longview plan not updated")
}
}
func contains(arr []string, elem string) bool {
for _, curr := range arr {
if curr == elem {
return true
}
}
return false
}
|