Пример #1
0
func TestAvailDatacentersIntegration(t *testing.T) {
	c := NewClient(apiKey)

	datacenters, err := c.AvailDatacenters()
	require.NoError(t, err)
	require.NotEmpty(t, datacenters)

	// Test subset
	var foundDallas bool
	var foundFremont bool

	for _, dc := range datacenters {
		switch dc.ID {
		case 2:
			assert.Equal(t, "Dallas, TX, USA", dc.Location, "dc.Location")
			assert.Equal(t, "dallas", dc.Abbr, "dc.Abbr")
			foundDallas = true
		case 3:
			assert.Equal(t, "Fremont, CA, USA", dc.Location, "dc.Location")
			assert.Equal(t, "fremont", dc.Abbr, "dc.Abbr")
			foundFremont = true
		}
	}

	assert.True(t, foundDallas, "Dallas not returned.")
	assert.True(t, foundFremont, "Fremont not returned.")
}
Пример #2
0
func TestAvailKernelsOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailKernelsOK()))
	defer ts.Close()

	kerns, err := c.AvailKernels(nil, nil)
	require.NoError(t, err)
	require.Len(t, kerns, 135)

	var sample Kernel
	var everXen bool
	var everPVOps bool

	for _, k := range kerns {
		if k.IsXen {
			everXen = true
		}
		if k.IsPVOps {
			everPVOps = true
		}
		assert.NotEmpty(t, k.Label, "k.Label")
		assert.NotEmpty(t, k.ID, "k.ID")

		if k.ID == 138 {
			sample = k
		}
	}
	assert.True(t, everXen, "everXen")
	assert.True(t, everPVOps, "everPVOps")

	assert.Equal(t, "Latest 64 bit (4.1.0-x86_64-linode59)", sample.Label, "sample.Label")
	assert.True(t, sample.IsXen, "sample.IsXen")
	assert.True(t, sample.IsPVOps, "sample.IsPVOps")
	assert.Equal(t, 138, sample.ID, "sample.ID")
}
Пример #3
0
func TestLinodeIPAddPrivateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeIPAddPrivateOK()))
	defer ts.Close()

	id, addr, err := c.LinodeIPAddPrivate(1146420)
	require.NoError(t, err)
	assert.Equal(t, 374332, id)
	assert.Equal(t, "192.168.199.65", addr)
}
Пример #4
0
func TestLinodeDiskDuplicateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskDuplicateOK()))
	defer ts.Close()

	jobID, dupeDiskID, err := c.LinodeDiskDuplicate(1139016, 3569220)
	require.NoError(t, err)
	assert.Equal(t, 25090699, jobID)
	assert.Equal(t, 3569577, dupeDiskID)
}
Пример #5
0
func TestLinodeDiskCreateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskCreateOK()))
	defer ts.Close()

	jobID, diskID, err := c.LinodeDiskCreate(1139016, "test-swap", "swap", 256)
	require.NoError(t, err)
	assert.Equal(t, 3568984, diskID)
	assert.Equal(t, 25087627, jobID)
}
Пример #6
0
func TestAccountEstimateInvoiceOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAccountEstimateInvoiceOK()))
	defer ts.Close()

	inv, err := c.AccountEstimateInvoice("linode_new", Int(1), Int(1), Int(1))
	require.NoError(t, err)
	assert.Equal(t, "2015-07-31 23:59:59", inv.InvoiceTo)
	assert.Equal(t, 8.07, inv.Price)
}
Пример #7
0
func TestLinodeDiskCreateFromImageOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskCreateFromImageOK()))
	defer ts.Close()

	jobID, imgDiskID, err := c.LinodeDiskCreateFromImage(396235, 1139016, "test-image", Int(800),
		String(rootPass), String(rootSSHKey))
	require.NoError(t, err)
	assert.Equal(t, 25090431, jobID)
	assert.Equal(t, 3569532, imgDiskID)
}
Пример #8
0
func TestLinodeDiskImagizeOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskImagizeOK()))
	defer ts.Close()

	jobID, imgID, err := c.LinodeDiskImagize(1139016, 3569234, String("test-image desc"),
		String("test-image label"))

	require.NoError(t, err)
	assert.Equal(t, 25090408, jobID)
	assert.Equal(t, 396235, imgID)
}
Пример #9
0
func TestAvailLinodePlansIntegration(t *testing.T) {
	c := NewClient(apiKey)

	plans, err := c.AvailLinodePlans(nil)
	require.NoError(t, err)
	require.NotEmpty(t, plans)

	testPlanNotEmpty(t, plans)

	// Spot check
	plans, err = c.AvailLinodePlans(Int(1))
	require.NoError(t, err)
	require.Len(t, plans, 1)

	p := plans[0]

	assert.Equal(t, 1, p.Cores)
	assert.Equal(t, 10.00, p.Price)
	assert.Equal(t, 1024, p.RAM)
	assert.Equal(t, 2000, p.Xfer)
	assert.Equal(t, 1, p.ID)
	assert.Equal(t, "Linode 1024", p.Label)
	assert.Equal(t, 24, p.Disk)
	assert.Equal(t, 0.015, p.Hourly)

	plans, err = c.AvailLinodePlans(Int(3498230))
	require.NoError(t, err)
	require.Empty(t, plans)
}
Пример #10
0
func TestAvailKernelsSingle(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailKernelsSingle()))
	defer ts.Close()

	kerns, err := c.AvailKernels(Int(138), Bool(true))
	require.NoError(t, err)
	require.Len(t, kerns, 1)

	k := kerns[0]

	assert.Equal(t, "Latest 64 bit (4.1.0-x86_64-linode59)", k.Label, "k.Label")
	assert.True(t, k.IsXen, "k.IsXen")
	assert.True(t, k.IsPVOps, "k.IsPVOps")
	assert.Equal(t, 138, k.ID, "k.ID")
}
Пример #11
0
func TestLinodeIPListOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeIPListOK()))
	defer ts.Close()

	IPList, err := c.LinodeIPList(Int(1146420), Int(1))
	require.NoError(t, err)
	require.Len(t, IPList, 1)

	IP := IPList[0]
	assert.Equal(t, 296963, IP.ID)
	assert.Equal(t, "li959-147.members.linode.com", IP.RDNSName)
	assert.Equal(t, 1146420, IP.LinodeID)
	assert.True(t, IP.IsPublic)
	assert.Equal(t, "45.33.5.147", IP.Address)
}
Пример #12
0
func newMockAPIServer(t *testing.T, responses []mockAPIResponse) *httptest.Server {
	var reqCount int

	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if len(responses) < reqCount {
			msg := fmt.Sprintf("Request count: %d len(responses): %d", reqCount+1, len(responses))
			require.FailNow(t, msg)
		}

		resp := responses[reqCount]

		action := r.FormValue("api_action")
		require.NotEmpty(t, action, fmt.Sprintf("%d", reqCount+1))

		require.Equal(t, resp.action, action, fmt.Sprintf("%d", reqCount+1))

		for k, v := range resp.params {
			assert.Equal(t, v, r.FormValue(k), fmt.Sprintf("params: %s - %d", k, reqCount+1))
		}

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(200)
		_, _ = w.Write([]byte(resp.output()))

		reqCount++
	}))

	return ts
}
Пример #13
0
func TestAvailDatacentersOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailDatacentersOK()))
	defer ts.Close()

	datacenters, err := c.AvailDatacenters()
	require.NoError(t, err)
	require.NotEmpty(t, datacenters)

	expected := []Datacenter{
		{
			Location: "Dallas, TX, USA",
			ID:       2,
			Abbr:     "dallas",
		},
		{
			Location: "Fremont, CA, USA",
			ID:       3,
			Abbr:     "fremont",
		},
		{
			Location: "Atlanta, GA, USA",
			ID:       4,
			Abbr:     "atlanta",
		},
		{
			Location: "Newark, NJ, USA",
			ID:       6,
			Abbr:     "newark",
		},
		{
			Location: "London, England, UK",
			ID:       7,
			Abbr:     "london",
		},
		{
			Location: "Tokyo, JP",
			ID:       8,
			Abbr:     "tokyo",
		},
		{
			Location: "Singapore, SG",
			ID:       9,
			Abbr:     "singapore",
		},
	}

	for i, eDC := range expected {
		for _, aDC := range datacenters {
			if reflect.DeepEqual(aDC, eDC) {
				expected[i] = Datacenter{}
				break
			}
		}
	}

	for _, dc := range expected {
		assert.Equal(t, Datacenter{}, dc, fmt.Sprintf("%+v not returned.", dc))
	}
}
Пример #14
0
func TestLinodeShutdownOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeShutdownOK()))
	defer ts.Close()

	jobID, err := c.LinodeShutdown(1146420)
	require.NoError(t, err)
	assert.Equal(t, 25167147, jobID)
}
Пример #15
0
func TestLinodeRebootOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeRebootOK()))
	defer ts.Close()

	jobID, err := c.LinodeReboot(1146420, Int(1862370))
	require.NoError(t, err)
	assert.Equal(t, jobID, 25167140)
}
Пример #16
0
func TestLinodeDiskResizeOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskResizeOK()))
	defer ts.Close()

	jobID, err := c.LinodeDiskResize(1139016, 3569577, 512)
	require.NoError(t, err)
	assert.Equal(t, 25090703, jobID)
}
Пример #17
0
func TestDomainResourceListOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockDomainResourceListOK()))
	defer ts.Close()

	resources, err := c.DomainResourceList(716074, Int(5337468))
	require.NoError(t, err)
	require.Len(t, resources, 1)
	r := resources[0]

	assert.Equal(t, 716074, r.DomainID)
	assert.Equal(t, 15, r.Port)
	assert.Equal(t, 5337468, r.ID)
	assert.Equal(t, "_foo._tcp", r.Name)
	assert.Equal(t, 10, r.Weight)
	assert.Equal(t, 300, r.TTLSec)
	assert.Equal(t, "bar.baz.com", r.Target)
	assert.Equal(t, 5, r.Priority)
	assert.Equal(t, "tcp", r.Protocol)
	assert.Equal(t, "srv", r.Type)
}
Пример #18
0
func TestImageListOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockImageListOK()))
	defer ts.Close()

	imgs, err := c.ImageList(Int(402716), Bool(false))
	require.NoError(t, err)
	require.Len(t, imgs, 1)

	i := imgs[0]
	assert.Equal(t, "baz", i.LastUsedDT)
	assert.Equal(t, 600, i.MinSize)
	assert.Equal(t, "foo", i.Description)
	assert.Equal(t, "bar", i.Label)
	assert.Equal(t, "quux", i.Creator)
	assert.Equal(t, "available", i.Status)
	assert.True(t, i.IsPublic)
	assert.Equal(t, "2015-07-07 23:55:59.0", i.CreateDT)
	assert.Equal(t, "manual", i.Type)
	assert.Equal(t, "ext4", i.FSType)
	assert.Equal(t, 402716, i.ID)
}
Пример #19
0
func TestAvailDistributionsIntegration(t *testing.T) {
	c := NewClient(apiKey)

	dists, err := c.AvailDistributions(nil)
	require.NoError(t, err)
	require.NotEmpty(t, dists)

	testDistsNotEmpty(t, dists)

	dists, err = c.AvailDistributions(Int(130))
	assert.NoError(t, err)
	assert.Len(t, dists, 1)

	d := dists[0]
	assert.Equal(t, true, d.RequiresPVOps, "d.RequiresPVOps")
	assert.Equal(t, 130, d.ID, "d.ID")
	assert.Equal(t, true, d.Is64Bit, "d.Is64Bit")
	assert.Equal(t, "Debian 7", d.Label, "d.Label")
	assert.Equal(t, 600, d.MinImageSize, "d.MinImageSize")
	assert.Equal(t, "2014-09-24 13:59:32.0", d.CreateDT, "d.CreateDT")

	dists, err = c.AvailDistributions(Int(38201938))
	assert.NoError(t, err)
	assert.Empty(t, dists)
}
Пример #20
0
func TestAvailStackScriptsOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailStackScriptsOK()))
	defer ts.Close()

	scripts, err := c.AvailStackScripts(Int(1), String("bar"), String("baz"))
	require.NoError(t, err)
	require.Len(t, scripts, 1)

	s := scripts[0]
	assert.Equal(t, "Professional Services", s.RevNote)
	assert.Contains(t, s.Script, "#!/bin/bash")
	assert.Equal(t, "127", s.DistIDList)
	assert.Contains(t, s.Description, "cPanel takes an hour to install.")
	assert.Equal(t, "2015-01-07 15:48:57.0", s.RevDT)
	assert.Equal(t, "cPanel", s.Label)
	assert.Equal(t, 207, s.TotalDeploys)
	assert.Equal(t, 53081, s.LatestRev)
	assert.Equal(t, 11078, s.ID)
	assert.True(t, s.IsPublic)
	assert.Equal(t, 125, s.ActiveDeploys)
	assert.Equal(t, "2015-01-07 15:48:57.0", s.CreateDT)
	assert.Equal(t, 307510, s.UserID)
}
Пример #21
0
func TestLinodeJobListFinishedOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeJobListFinishedOK()))
	defer ts.Close()

	jobs, err := c.LinodeJobList(1139016, Int(25088076), Bool(false))
	require.NoError(t, err)
	require.Len(t, jobs, 1)

	j := jobs[0]

	assert.True(t, j.Done())
	assert.True(t, j.Success())

	assert.Equal(t, "2015-07-03 23:51:41.0", j.EnteredDT)
	assert.Equal(t, "fs.create", j.Action)
	assert.Equal(t, "Create Filesystem - test-swap", j.Label)
	assert.Equal(t, "2015-07-03 23:51:51.0", j.HostStartDT)
	assert.Equal(t, 1139016, j.LinodeID)
	assert.Equal(t, "2015-07-03 23:51:51.0", j.HostFinishDT)
	assert.Equal(t, 5, j.Duration)
	assert.Equal(t, "foo", j.HostMessage)
	assert.Equal(t, 25088076, j.ID)
	assert.Equal(t, true, j.HostSuccess)
}
Пример #22
0
func TestLinodeDiskCreateFromStackScriptOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskCreateFromStackScriptOK()))
	defer ts.Close()

	ssOpts := struct {
		DBPassword    string `json:"db_password"`
		DBName        string `json:"db_name"`
		MySQLUsername string `json:"db_user"`
		MySQLUserpass string `json:"db_user_password"`
	}{
		"foo",
		"bar",
		"baz",
		"quux",
	}
	ssUDFResp, err := json.Marshal(ssOpts)
	require.NoError(t, err)

	jobID, diskID, err := c.LinodeDiskCreateFromStackScript(1146420, 10, string(ssUDFResp),
		130, "test-ss", 600, rootPass, String(rootSSHKey))
	require.NoError(t, err)
	assert.Equal(t, 25166896, jobID)
	assert.Equal(t, 3582660, diskID)
}
Пример #23
0
func TestNodeBalancerNodeListOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerNodeListOK()))
	defer ts.Close()

	nbNodes, err := c.NodeBalancerNodeList(14591, Int(140574))
	require.NoError(t, err)
	require.Len(t, nbNodes, 1)

	node := nbNodes[0]
	assert.Equal(t, 50, node.Weight)
	assert.Equal(t, "192.168.202.68:90", node.Address)
	assert.Equal(t, "test", node.Label)
	assert.Equal(t, 140574, node.ID)
	assert.Equal(t, "accept", node.Mode)
	assert.Equal(t, 14591, node.ConfigID)
	assert.Equal(t, "Unknown", node.Status)
	assert.Equal(t, 13128, node.NodeBalancerID)
}
Пример #24
0
func TestAvailLinodePlansSingle(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailLinodePlansSingle()))
	defer ts.Close()

	plans, err := c.AvailLinodePlans(Int(1))
	require.NoError(t, err)
	require.Len(t, plans, 1)

	p := plans[0]

	assert.Equal(t, 1, p.Cores)
	assert.Equal(t, 10.00, p.Price)
	assert.Equal(t, 1024, p.RAM)
	assert.Equal(t, 2000, p.Xfer)
	assert.Equal(t, 1, p.ID)
	assert.Equal(t, "Linode 1024", p.Label)
	assert.Equal(t, 24, p.Disk)
	assert.Equal(t, 0.015, p.Hourly)
}
Пример #25
0
func TestNodeBalancerListOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerListOK()))
	defer ts.Close()

	nbList, err := c.NodeBalancerList(Int(13128))
	require.NoError(t, err)
	require.Len(t, nbList, 1)

	n := nbList[0]
	assert.Equal(t, "nb-198-58-121-23.dallas.nodebalancer.linode.com", n.Hostname)
	assert.Equal(t, "testing", n.Label)
	assert.Equal(t, 5, n.Throttle)
	assert.Equal(t, 2, n.DatacenterID)
	assert.Equal(t, "198.58.121.23", n.IPv4Addr)
	assert.Equal(t, "2600:3c00:1::c63a:7917", n.IPv6Addr)
	assert.Equal(t, 13128, n.ID)
}
Пример #26
0
func TestMockAccountInfoOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAccountInfo()))
	defer ts.Close()

	i, err := c.AccountInfo()
	require.NoError(t, err)
	assert.Equal(t, 1, i.TransferUsed)
	assert.Equal(t, -4.8200, i.Balance)
	assert.Equal(t, 2, i.TransferBillable)
	assert.Equal(t, "metered", i.BillingMethod)
	assert.Equal(t, 104, i.TransferPool)
	assert.Equal(t, "2015-06-25 23:52:06.0", i.ActiveSince)
	assert.True(t, i.Managed)
}
Пример #27
0
func TestAvailDistributionsSingle(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailDistributionsSingle()))
	defer ts.Close()

	dists, err := c.AvailDistributions(Int(130))
	require.NoError(t, err)
	require.Len(t, dists, 1)

	d := dists[0]
	assert.Equal(t, true, d.RequiresPVOps, "d.RequiresPVOps")
	assert.Equal(t, 130, d.ID, "d.ID")
	assert.Equal(t, true, d.Is64Bit, "d.Is64Bit")
	assert.Equal(t, "Debian 7", d.Label, "d.Label")
	assert.Equal(t, 600, d.MinImageSize, "d.MinImageSize")
	assert.Equal(t, "2014-09-24 13:59:32.0", d.CreateDT, "d.CreateDT")
}
Пример #28
0
func TestLinodeDiskListOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskListOK()))
	defer ts.Close()

	disks, err := c.LinodeDiskList(1146420, Int(1))
	require.NoError(t, err)
	require.Len(t, disks, 3)

	var foundTestSwap bool
	var foundTestDist bool
	var foundUpdatedLabel bool

	for _, d := range disks {
		if d.ID == 3582351 {
			foundTestSwap = true

			assert.True(t, d.IsReadOnly)
			assert.Equal(t, "test-swap", d.Label)
			assert.Equal(t, "2015-07-06 23:30:13.0", d.UpdateDT)
			assert.Equal(t, 1, d.Status)
			assert.Equal(t, 256, d.Size)
			assert.Equal(t, 1146420, d.LinodeID)
			assert.Equal(t, "2015-07-06 23:29:37.0", d.CreateDT)
			assert.Equal(t, "swap", d.Type)
		}
		if d.ID == 3582352 {
			foundTestDist = true
		}
		if d.ID == 3582356 {
			foundUpdatedLabel = true
		}
	}

	assert.True(t, foundTestSwap)
	assert.True(t, foundTestDist)
	assert.True(t, foundUpdatedLabel)
}
Пример #29
0
func TestNodeBalancerIntegration(t *testing.T) {
	c := NewClient(apiKey)

	t.Log("creating test linode...")
	linodeID, err := c.LinodeCreate(2, 1, nil)
	require.NoError(t, err)
	require.NotEmpty(t, linodeID)

	err = c.WaitForAllJobs(linodeID, 3*time.Second, 60*time.Second)
	require.NoError(t, err)

	t.Log("assigning private IP...")
	_, linodeIP, err := c.LinodeIPAddPrivate(linodeID)
	require.NoError(t, err)
	require.NotEmpty(t, linodeIP)

	t.Log("nodebalancer.create...")
	nbID, err := c.NodeBalancerCreate(2, String("testing"), Int(5))
	require.NoError(t, err)
	require.NotEmpty(t, nbID)

	t.Log("nodebalancer.list...")
	nbList, err := c.NodeBalancerList(Int(nbID))
	require.NoError(t, err)
	require.Len(t, nbList, 1)

	n := nbList[0]
	assert.NotEmpty(t, n.Hostname)
	assert.Equal(t, "testing", n.Label)
	assert.Equal(t, 5, n.Throttle)
	assert.Equal(t, 2, n.DatacenterID)
	assert.NotEmpty(t, n.IPv4Addr)
	assert.NotEmpty(t, n.IPv6Addr)
	assert.Equal(t, nbID, n.ID)

	t.Log("nodebalancer.update...")
	err = c.NodeBalancerUpdate(nbID, String("testing-2"), Int(10))
	require.NoError(t, err)

	t.Log("nodebalancer.list...")
	nbList, err = c.NodeBalancerList(Int(nbID))
	require.NoError(t, err)
	require.Len(t, nbList, 1)

	n = nbList[0]
	assert.Equal(t, "testing-2", n.Label)
	assert.Equal(t, 10, n.Throttle)
	assert.Equal(t, nbID, n.ID)

	nbcco := NodeBalancerConfigCreateOpts{
		Port:          Int(80),
		Protocol:      String("http"),
		Algorithm:     String("roundrobin"),
		Stickiness:    String("http_cookie"),
		Check:         String("http"),
		CheckInterval: Int(30),
		CheckTimeout:  Int(29),
		CheckAttempts: Int(15),
		CheckPath:     String("/foo"),
		CheckBody:     String("bar"),
		CheckPassive:  Bool(false),
	}

	t.Log("nodebalancer.config.create...")
	confID, err := c.NodeBalancerConfigCreate(nbID, nbcco)
	require.NoError(t, err)
	require.NotEmpty(t, confID)

	t.Log("nodebalancer.config.list...")
	nbconfs, err := c.NodeBalancerConfigList(nbID, Int(confID))
	require.NoError(t, err)
	require.Len(t, nbconfs, 1)

	nbc := nbconfs[0]
	assert.Equal(t, "http_cookie", nbc.Stickiness)
	assert.Equal(t, "", nbc.SSLCommonName)
	assert.Equal(t, "/foo", nbc.CheckPath)
	assert.Equal(t, "bar", nbc.CheckBody)
	assert.Equal(t, 30, nbc.CheckInterval)
	assert.Equal(t, "", nbc.SSLFingerprint)
	assert.Equal(t, "roundrobin", nbc.Algorithm)
	assert.Equal(t, confID, nbc.ID)
	assert.Equal(t, 15, nbc.CheckAttempts)
	assert.Equal(t, nbID, nbc.NodeBalancerID)
	assert.Equal(t, 80, nbc.Port)
	assert.Equal(t, "http", nbc.Check)
	assert.False(t, nbc.CheckPassive)
	assert.Equal(t, "http", nbc.Protocol)
	assert.Equal(t, 29, nbc.CheckTimeout)

	nbcuo := NodeBalancerConfigUpdateOpts{
		Port:          Int(90),
		Protocol:      String("https"),
		Algorithm:     String("leastconn"),
		Stickiness:    String("table"),
		Check:         String("http_body"),
		CheckInterval: Int(24),
		CheckTimeout:  Int(23),
		CheckAttempts: Int(20),
		CheckPath:     String("/bar"),
		CheckBody:     String("quux"),
		CheckPassive:  Bool(true),
		SSLCert:       String(sslCert),
		SSLKey:        String(sslKey),
	}

	t.Log("nodebalancer.config.update...")
	err = c.NodeBalancerConfigUpdate(confID, nbcuo)
	require.NoError(t, err)

	t.Log("nodebalancer.config.list...")
	nbconfs, err = c.NodeBalancerConfigList(nbID, Int(confID))
	require.NoError(t, err)
	require.Len(t, nbconfs, 1)

	nbc = nbconfs[0]
	assert.Equal(t, "table", nbc.Stickiness)
	assert.Equal(t, "foo.com", nbc.SSLCommonName)
	assert.Equal(t, "/bar", nbc.CheckPath)
	assert.Equal(t, "quux", nbc.CheckBody)
	assert.Equal(t, 24, nbc.CheckInterval)
	assert.Equal(t, "0B:40:09:0C:4E:DA:5B:FB:2A:31:69:C9:4D:80:AE:CE:76:8F:DA:60", nbc.SSLFingerprint)
	assert.Equal(t, "leastconn", nbc.Algorithm)
	assert.Equal(t, confID, nbc.ID)
	assert.Equal(t, 20, nbc.CheckAttempts)
	assert.Equal(t, nbID, nbc.NodeBalancerID)
	assert.Equal(t, 90, nbc.Port)
	assert.Equal(t, "http_body", nbc.Check)
	assert.True(t, nbc.CheckPassive)
	assert.Equal(t, "https", nbc.Protocol)
	assert.Equal(t, 23, nbc.CheckTimeout)

	t.Log("nodebalancer.node.create...")
	nbNodeID, err := c.NodeBalancerNodeCreate(confID, "test", linodeIP+":90", Int(50),
		String("accept"))
	require.NoError(t, err)
	require.NotEmpty(t, nbNodeID)

	t.Log("nodebalancer.node.list...")
	nbNodes, err := c.NodeBalancerNodeList(confID, Int(nbNodeID))
	require.NoError(t, err)
	require.Len(t, nbNodes, 1)

	node := nbNodes[0]
	assert.Equal(t, 50, node.Weight)
	assert.Equal(t, linodeIP+":90", node.Address)
	assert.Equal(t, "test", node.Label)
	assert.Equal(t, nbNodeID, node.ID)
	assert.Equal(t, "accept", node.Mode)
	assert.Equal(t, confID, node.ConfigID)
	assert.NotEmpty(t, node.Status)
	assert.Equal(t, nbID, node.NodeBalancerID)

	t.Log("nodebalancer.node.update...")
	err = c.NodeBalancerNodeUpdate(nbNodeID, String("test-2"), String(linodeIP+":80"),
		Int(60), String("reject"))
	require.NoError(t, err)

	t.Log("nodebalancer.node.list...")
	nbNodes, err = c.NodeBalancerNodeList(confID, Int(nbNodeID))
	require.NoError(t, err)
	require.Len(t, nbNodes, 1)

	node = nbNodes[0]
	assert.Equal(t, 60, node.Weight)
	assert.Equal(t, linodeIP+":80", node.Address)
	assert.Equal(t, "test-2", node.Label)
	assert.Equal(t, nbNodeID, node.ID)
	assert.Equal(t, "reject", node.Mode)
	assert.Equal(t, confID, node.ConfigID)
	assert.NotEmpty(t, node.Status)
	assert.Equal(t, nbID, node.NodeBalancerID)

	t.Log("nodebalancer.node.delete...")
	err = c.NodeBalancerNodeDelete(nbNodeID)
	require.NoError(t, err)

	t.Log("nodebalancer.config.delete...")
	err = c.NodeBalancerConfigDelete(nbID, confID)
	require.NoError(t, err)

	t.Log("nodebalancer.delete...")
	err = c.NodeBalancerDelete(nbID)
	require.NoError(t, err)

	t.Log("deleting test linode...")
	err = c.LinodeDelete(linodeID, Bool(true))
	require.NoError(t, err)
}
Пример #30
0
func TestImageIntegration(t *testing.T) {
	c := NewClient(apiKey)

	t.Log("creating test linode...")
	linodeID, err := c.LinodeCreate(2, 1, nil)
	require.NoError(t, err)
	require.NotEmpty(t, linodeID)

	err = c.WaitForAllJobs(linodeID, 3*time.Second, 60*time.Second)
	require.NoError(t, err)

	t.Log("creating test disk...")
	jobID, dDiskID, err := c.LinodeDiskCreateFromDistribution(linodeID, 130, "test-image", 600,
		rootPass, nil)
	require.NoError(t, err)
	require.NotEmpty(t, dDiskID)
	require.NotEmpty(t, jobID)

	ok, err := c.WaitForJob(linodeID, jobID, 3*time.Second, 60*time.Second)
	require.NoError(t, err)
	require.True(t, ok)

	t.Log("converting test disk to image...")
	jobID, imageID, err := c.LinodeDiskImagize(linodeID, dDiskID, String("foo"), String("bar"))
	require.NoError(t, err)
	require.NotEmpty(t, imageID)
	require.NotEmpty(t, jobID)

	ok, err = c.WaitForJob(linodeID, jobID, 3*time.Second, 120*time.Second)
	require.NoError(t, err)
	require.True(t, ok)

	t.Log("image.list...")
	images, err := c.ImageList(&imageID, Bool(false))
	require.NoError(t, err)
	require.Len(t, images, 1)

	i := images[0]
	assert.Empty(t, i.LastUsedDT)
	assert.Equal(t, 600, i.MinSize)
	assert.Equal(t, "foo", i.Description)
	assert.Equal(t, "bar", i.Label)
	assert.NotEmpty(t, i.Creator)
	assert.Equal(t, "available", i.Status)
	assert.False(t, i.IsPublic)
	assert.NotEmpty(t, i.CreateDT)
	assert.Equal(t, "manual", i.Type)
	assert.Equal(t, "ext4", i.FSType)
	assert.Equal(t, imageID, i.ID)

	t.Log("image.update...")
	err = c.ImageUpdate(imageID, String("baz"), String("quux"))
	require.NoError(t, err)

	t.Log("image.list...")
	images, err = c.ImageList(&imageID, Bool(false))
	require.NoError(t, err)
	require.Len(t, images, 1)

	i = images[0]
	assert.Equal(t, "baz", i.Label)
	assert.Equal(t, "quux", i.Description)

	t.Log("image.delete...")
	err = c.ImageDelete(imageID)
	require.NoError(t, err)

	t.Log("cleaning up linode...")
	err = c.LinodeDelete(linodeID, Bool(true))
	require.NoError(t, err)
}