Exemplo n.º 1
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)
}
Exemplo n.º 2
0
func TestAvailStackScriptsIntegration(t *testing.T) {
	c := NewClient(apiKey)

	sscripts, err := c.AvailStackScripts(nil, nil, nil)
	require.NoError(t, err)
	require.NotEmpty(t, sscripts)

	testSSNotEmpty(t, sscripts)

	sscripts, err = c.AvailStackScripts(Int(3133731337), String("bar"), String("baz"))
	require.NoError(t, err)
	require.Empty(t, sscripts)
}
Exemplo n.º 3
0
func TestNodeBalancerDeleteOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerDeleteOK()))
	defer ts.Close()

	err := c.NodeBalancerDelete(13128)
	require.NoError(t, err)
}
Exemplo n.º 4
0
func TestNodeBalancerConfigListOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerConfigListOK()))
	defer ts.Close()

	nbconfs, err := c.NodeBalancerConfigList(13128, Int(14591))
	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, 14591, nbc.ID)
	assert.Equal(t, 15, nbc.CheckAttempts)
	assert.Equal(t, 13128, 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)
}
Exemplo n.º 5
0
func TestLinodeImageDeleteOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockImageDeleteOK()))
	defer ts.Close()

	err := c.ImageDelete(402716)
	require.NoError(t, err)
}
Exemplo n.º 6
0
func TestLinodeImageUpdateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockImageUpdateOK()))
	defer ts.Close()

	err := c.ImageUpdate(402716, String("baz"), String("quux"))
	require.NoError(t, err)
}
Exemplo n.º 7
0
func TestDomainDeleteOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockDomainDeleteOK()))
	defer ts.Close()

	err := c.DomainDelete(716074)
	require.NoError(t, err)
}
Exemplo n.º 8
0
func TestStackScriptDeleteOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockStackScriptDeleteOK()))
	defer ts.Close()

	err := c.StackScriptDelete(12567)
	require.NoError(t, err)
}
Exemplo n.º 9
0
func TestLinodeDiskUpdateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskUpdateOK()))
	defer ts.Close()

	err := c.LinodeDiskUpdate(1139016, 3569577, String("updated-label"), Bool(true))
	require.NoError(t, err)
}
Exemplo n.º 10
0
func TestLinodeIPSwap(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeIPSwapOK()))
	defer ts.Close()

	err := c.LinodeIPSwap(296963, Int(296386), Int(1))
	require.NoError(t, err)
}
Exemplo n.º 11
0
func TestLinodeConfigList(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeConfigListOK()))
	defer ts.Close()

	confs, err := c.LinodeConfigList(1139016, Int(1855685))
	require.NoError(t, err)
	require.Len(t, confs, 1)

	cfg := confs[0]
	assert.Equal(t, "bar", cfg.RootDeviceCustom)
	assert.Equal(t, "foo", cfg.Comments)
	assert.Equal(t, "test-conf1", cfg.Label)
	assert.Equal(t, 1855685, cfg.ID)
	assert.Equal(t, "3569234,3569220,,,,,,,", cfg.DiskList)
	assert.Equal(t, "default", cfg.RunLevel)
	assert.Equal(t, 1, cfg.RootDeviceNum)
	assert.Equal(t, 800, cfg.RAMLimit)
	assert.Equal(t, "paravirt", cfg.VirtMode)
	assert.Equal(t, 1139016, cfg.LinodeID)
	assert.Equal(t, 138, cfg.KernelID)
	assert.True(t, cfg.DevTmpFSAutomount)
	assert.True(t, cfg.HelperDistro)
	assert.True(t, cfg.HelperDisableUpdateDB)
	assert.True(t, cfg.HelperDepmod)
	assert.True(t, cfg.HelperXen)
	assert.True(t, cfg.RootDeviceRO)
	assert.True(t, cfg.HelperNetwork)
	assert.True(t, cfg.IsRescue)
}
Exemplo n.º 12
0
func TestLinodeResizeOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeResizeOK()))
	defer ts.Close()

	err := c.LinodeResize(1139016, 2)
	require.NoError(t, err)
}
Exemplo n.º 13
0
func TestLinodeDeleteOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDeleteOK()))
	defer ts.Close()

	err := c.LinodeDelete(1140616, Bool(true))
	require.NoError(t, err)
}
Exemplo n.º 14
0
func TestWaitForAllJobsOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockWaitForAllJobsOK()))
	defer ts.Close()

	err := c.WaitForAllJobs(1139016, 1*time.Nanosecond, 1*time.Second)
	require.NoError(t, err)
}
Exemplo n.º 15
0
func TestNodeBalancerUpdateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerUpdateOK()))
	defer ts.Close()

	err := c.NodeBalancerUpdate(13128, String("testing-2"), Int(10))
	require.NoError(t, err)
}
Exemplo n.º 16
0
func TestUnmarshalSingleBool(t *testing.T) {
	// doesn't currently get exercised in normal usage
	var out bool
	err := unmarshalSingle(json.RawMessage([]byte(`{"foo": true}`)), "foo", &out)
	require.NoError(t, err)
	assert.True(t, out)
}
Exemplo n.º 17
0
func TestLinodeConfigDeleteOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeConfigDeleteOK()))
	defer ts.Close()

	err := c.LinodeConfigDelete(1146666, 1862591)
	require.NoError(t, err)
}
Exemplo n.º 18
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)
}
Exemplo n.º 19
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.")
}
Exemplo n.º 20
0
func TestEchoOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockTestEchoOK()))
	defer ts.Close()

	err := c.TestEcho()
	require.NoError(t, err)
}
Exemplo n.º 21
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")
}
Exemplo n.º 22
0
func TestStackScriptIntegration(t *testing.T) {
	c := NewClient(apiKey)

	ssID, err := c.StackScriptCreate("test", "130,", "#! /bin/bash foo", String("foo"),
		Bool(false), String("bar"))
	require.NoError(t, err)
	require.NotEmpty(t, ssID)

	ssList, err := c.StackScriptList(Int(ssID))
	require.NoError(t, err)
	require.Len(t, ssList, 1)

	ss := ssList[0]
	assert.Equal(t, "bar", ss.RevNote)
	assert.Equal(t, "#! /bin/bash foo", ss.Script)
	assert.Equal(t, "130,", ss.DistIDList)
	assert.Equal(t, "foo", ss.Description)
	assert.NotEmpty(t, ss.RevDT)
	assert.Equal(t, "test", ss.Label)
	assert.Equal(t, 0, ss.TotalDeploys)
	assert.NotEmpty(t, ss.LatestRev)
	assert.Equal(t, ssID, ss.ID)
	assert.False(t, ss.IsPublic)
	assert.Equal(t, 0, ss.ActiveDeploys)
	assert.NotEmpty(t, ss.CreateDT)
	assert.NotEmpty(t, ss.UserID)

	err = c.StackScriptUpdate(ssID, String("test-2"), String("quux"), String("129,130"), Bool(true),
		String("baz"), String("#! /bin/bash baz"))
	require.NoError(t, err)

	ssList, err = c.StackScriptList(Int(ssID))
	require.NoError(t, err)
	require.Len(t, ssList, 1)

	ss = ssList[0]
	assert.Equal(t, "baz", ss.RevNote)
	assert.Equal(t, "#! /bin/bash baz", ss.Script)
	assert.Equal(t, "129,130", ss.DistIDList)
	assert.Equal(t, "quux", ss.Description)
	assert.Equal(t, "test-2", ss.Label)
	assert.Equal(t, ssID, ss.ID)
	assert.True(t, ss.IsPublic)

	err = c.StackScriptDelete(ssID)
	require.NoError(t, err)
}
Exemplo n.º 23
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))
	}
}
Exemplo n.º 24
0
func TestAccountInfoIntegration(t *testing.T) {
	c := NewClient(apiKey)

	info, err := c.AccountInfo()
	require.NoError(t, err)
	require.NotEmpty(t, info.ActiveSince)
	require.NotEmpty(t, info.TransferPool)
}
Exemplo n.º 25
0
func TestAccountEstimateInvoiceIntegration(t *testing.T) {
	c := NewClient(apiKey)

	inv, err := c.AccountEstimateInvoice("linode_new", Int(1), Int(1), nil)
	require.NoError(t, err)
	require.NotEmpty(t, inv.InvoiceTo)
	require.NotEmpty(t, inv.Price)
}
Exemplo n.º 26
0
func TestNodeBalancerCreateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerCreateOK()))
	defer ts.Close()

	nbID, err := c.NodeBalancerCreate(2, String("testing"), Int(5))
	require.NoError(t, err)
	require.Equal(t, 13128, nbID)
}
Exemplo n.º 27
0
func TestNodeBalancerNodeUpdateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerNodeUpdateOK()))
	defer ts.Close()

	err := c.NodeBalancerNodeUpdate(140574, String("test-2"), String("192.168.202.68:80"),
		Int(60), String("reject"))
	require.NoError(t, err)
}
Exemplo n.º 28
0
func TestAvailLinodePlansEmpty(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailLinodePlansEmpty()))
	defer ts.Close()

	plans, err := c.AvailLinodePlans(Int(3498230))
	require.NoError(t, err)
	require.Len(t, plans, 0)
}
Exemplo n.º 29
0
func TestAvailKernelsEmpty(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailKernelsEmpty()))
	defer ts.Close()

	kerns, err := c.AvailKernels(Int(4389048234), Bool(false))
	require.NoError(t, err)
	require.Len(t, kerns, 0)
}
Exemplo n.º 30
0
func TestAvailDistributionsEmpty(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockAvailDistributionsEmpty()))
	defer ts.Close()

	dists, err := c.AvailDistributions(Int(38201938))
	require.NoError(t, err)
	require.Empty(t, dists)
}