コード例 #1
0
ファイル: api_linode_test.go プロジェクト: alexsacr/linode
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
ファイル: mocks_test.go プロジェクト: alexsacr/linode
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
ファイル: api_linode_test.go プロジェクト: alexsacr/linode
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
ファイル: api_account_test.go プロジェクト: alexsacr/linode
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
ファイル: api_linode_test.go プロジェクト: alexsacr/linode
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
ファイル: api_dns_test.go プロジェクト: alexsacr/linode
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
ファイル: api_dns_test.go プロジェクト: alexsacr/linode
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
ファイル: api_linode_test.go プロジェクト: alexsacr/linode
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)
}