示例#1
0
func TestLinodeDiskCreateFromDistributionOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeDiskCreateFromDistributionOK()))
	defer ts.Close()

	jobID, diskID, err := c.LinodeDiskCreateFromDistribution(1139016, 130, "test-dist", 600,
		rootPass, String(rootSSHKey))
	require.NoError(t, err)
	require.Equal(t, 25088891, jobID)
	require.Equal(t, 3569234, diskID)
}
示例#2
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
}
示例#3
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)
}
示例#4
0
func TestLinodeCreateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeCreateOK()))
	defer ts.Close()

	id, err := c.LinodeCreate(2, 1, nil)
	require.NoError(t, err)
	require.Equal(t, 1139016, id)
}
示例#5
0
func TestUserGetAPIKeyOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockUserGetAPIKeyOK()))
	defer ts.Close()

	key, err := c.UserGetAPIKey("foo", "bar", String("baz"), Int(1), String("test"))
	require.NoError(t, err)
	require.Equal(t, "foo", key)
}
示例#6
0
func TestNodeBalancerNodeCreateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerNodeCreateOK()))
	defer ts.Close()

	nbNodeID, err := c.NodeBalancerNodeCreate(14591, "test", "192.168.202.68:90", Int(50),
		String("accept"))
	require.NoError(t, err)
	require.Equal(t, 140574, nbNodeID)
}
示例#7
0
func TestStackScriptCreatePublicOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockStackScriptCreatePublicOK()))
	defer ts.Close()

	ssID, err := c.StackScriptCreate("test", "130,", "#! /bin/bash foo", String("foo"),
		Bool(true), String("bar"))
	require.NoError(t, err)
	require.Equal(t, 12567, ssID)
}
示例#8
0
func TestLinodeCloneOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeCloneOK()))
	defer ts.Close()

	cloneID, err := c.LinodeClone(1139016, 2, 1, nil, nil)
	require.NoError(t, err)
	require.NotEmpty(t, cloneID)
	require.Equal(t, 1140616, cloneID, "cloneID")
}
示例#9
0
func TestDomainResourceCreateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockDomainResourceCreateOK()))
	defer ts.Close()

	drco := DomainResourceCreateOpts{
		Name:     String("_foo._tcp"),
		Target:   String("bar.baz.com"),
		Priority: Int(5),
		Weight:   Int(10),
		Port:     Int(15),
		Protocol: String("bar"),
		TTLSec:   Int(20),
	}

	rID, err := c.DomainResourceCreate(716074, "srv", drco)
	require.NoError(t, err)
	require.Equal(t, 5337468, rID)
}
示例#10
0
func TestDomainCreateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockDomainCreateOK()))
	defer ts.Close()

	dco := DomainCreateOpts{
		Description:  String("foo"),
		SOAEmail:     String("*****@*****.**"),
		RefreshSec:   Int(20),
		RetrySec:     Int(30),
		ExpireSec:    Int(40),
		TTLSec:       Int(50),
		DisplayGroup: String("test"),
		Status:       Int(1),
	}

	dID, err := c.DomainCreate("foo.com", "master", dco)
	require.NoError(t, err)
	require.Equal(t, 716074, dID)
}
示例#11
0
func TestNodeBalancerConfigCreateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockNodeBalancerConfigCreateOK()))
	defer ts.Close()

	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(13128, nbcco)
	require.NoError(t, err)
	require.Equal(t, 14591, confID)
}
示例#12
0
func TestLinodeConfigCreateOK(t *testing.T) {
	c, ts := clientFor(newMockAPIServer(t, mockLinodeConfigCreateOK()))
	defer ts.Close()

	lcco := LinodeConfigCreateOpts{
		Comments:              String("foo"),
		RAMLimit:              Int(800),
		VirtMode:              String("paravirt"),
		RunLevel:              String("default"),
		RootDeviceNum:         Int(1),
		RootDeviceRO:          Bool(true),
		HelperDisableUpdateDB: Bool(true),
		HelperDistro:          Bool(true),
		HelperXen:             Bool(true),
		HelperDepmod:          Bool(true),
		HelperNetwork:         Bool(true),
		DevTmpFSAutomount:     Bool(true),
	}

	confID, err := c.LinodeConfigCreate(1139016, 138, "test-conf1", "3569234,3569220,", lcco)
	require.NoError(t, err)
	require.Equal(t, 1855685, confID)
}