Beispiel #1
0
func TestUnmarshalSingleErrs(t *testing.T) {
	err := unmarshalSingle(json.RawMessage{}, "", "foo")
	assert.Error(t, err)

	var foo string
	err = unmarshalSingle(json.RawMessage([]byte(`{"bar":"baz"}`)), "foo", &foo)
	assert.Error(t, err)

	var outInt int
	var outStr string
	var outBool bool
	var outSlice []struct{}

	err = unmarshalSingle(json.RawMessage([]byte(`{"foo": "bar"}`)), "foo", &outInt)
	assert.Error(t, err)
	assert.Empty(t, outInt)
	err = unmarshalSingle(json.RawMessage([]byte(`{"foo": 1}`)), "foo", &outStr)
	assert.Error(t, err)
	assert.Empty(t, outStr)
	err = unmarshalSingle(json.RawMessage([]byte(`{"foo": "bar"}`)), "foo", &outBool)
	assert.Error(t, err)
	assert.Empty(t, outBool)
	err = unmarshalSingle(json.RawMessage([]byte(`{"foo": "bar"}`)), "foo", &outSlice)
	assert.Error(t, err)
	assert.Empty(t, outSlice)
}
Beispiel #2
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)
}
Beispiel #3
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)
}