Пример #1
0
func TestSessionGet(t *testing.T) {
	tokn := "eaaafd18-0fed-4b3a-81b4-663c99ec1cbb"
	var apiServer = testUtil.CreateGetJsonTestServer(
		t,
		tokn,
		`{"id":"id1","name":"Chris"}`,
		nil,
	)
	expected := TestStruct{ID: "id1", Name: "Chris"}
	actual := TestStruct{}

	s, _ := openstack.NewSession(nil, nil, nil)
	var headers http.Header = http.Header{}
	headers.Set("X-Auth-Token", tokn)
	headers.Set("Accept", "application/json")
	headers.Set("Etag", "md5hash-blahblah")
	resp, err := s.Get(apiServer.URL, nil, &headers)
	if err != nil {
		t.Error(err)
	}
	testUtil.IsNil(t, err)

	rbody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		t.Error(err)
	}

	if err = json.Unmarshal(rbody, &actual); err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, expected, actual)
}
Пример #2
0
func TestListImageDetails(t *testing.T) {
	anon := func(imageService *image.Service) {
		images, err := imageService.ImagesDetail()
		if err != nil {
			t.Error(err)
		}

		if len(images) != 2 {
			t.Error(errors.New("Incorrect number of images found"))
		}
		createdAt, _ := util.NewDateTime(`"2014-09-29T14:44:31"`)
		updatedAt, _ := util.NewDateTime(`"2014-09-29T15:33:37"`)
		owner := "10014302369510"
		virtualSize := int64(2525125)
		expectedImageDetail := image.DetailResponse{
			Status:          "active",
			Name:            "Ubuntu Server 12.04.5 LTS (amd64 20140927) - Partner Image",
			Deleted:         false,
			ContainerFormat: "bare",
			CreatedAt:       createdAt,
			DiskFormat:      "qcow2",
			UpdatedAt:       updatedAt,
			MinDisk:         8,
			Protected:       false,
			ID:              "8ca068c5-6fde-4701-bab8-322b3e7c8d81",
			MinRAM:          0,
			CheckSum:        "de1831ea85702599a27e7e63a9a444c3",
			Owner:           &owner,
			IsPublic:        true,
			DeletedAt:       nil,
			Properties: map[string]string{
				"com.ubuntu.cloud__1__milestone":    "release",
				"com.hp__1__os_distro":              "com.ubuntu",
				"description":                       "Ubuntu Server 12.04.5 LTS (amd64 20140927) for HP Public Cloud. Ubuntu Server is the world's most popular Linux for cloud environments. Updates and patches for Ubuntu 12.04.5 LTS will be available until 2017-04-26. Ubuntu Server is the perfect platform for all workloads from web applications to NoSQL databases and Hadoop. More information regarding Ubuntu Cloud is available from http://www.ubuntu.com/cloud and instructions for using Juju to deploy workloads are available from http://juju.ubuntu.com EULA: http://www.ubuntu.com/about/about-ubuntu/licensing Privacy Policy: http://www.ubuntu.com/privacy-policy",
				"com.ubuntu.cloud__1__suite":        "precise",
				"com.ubuntu.cloud__1__serial":       "20140927",
				"com.hp__1__bootable_volume":        "True",
				"com.hp__1__vendor":                 "Canonical",
				"com.hp__1__image_lifecycle":        "active",
				"com.hp__1__image_type":             "disk",
				"os_version":                        "12.04",
				"architecture":                      "x86_64",
				"os_type":                           "linux-ext4",
				"com.ubuntu.cloud__1__stream":       "server",
				"com.ubuntu.cloud__1__official":     "True",
				"com.ubuntu.cloud__1__published_at": "2014-09-29T15:33:36"},
			Size:        261423616,
			VirtualSize: &virtualSize}
		testUtil.Equals(t, expectedImageDetail, images[0])
	}

	testImageServiceAction(t, "images/detail", sampleImageDetailsData, anon)
}
Пример #3
0
func TestListImages(t *testing.T) {
	anon := func(imageService *image.Service) {
		images, err := imageService.Images()
		if err != nil {
			t.Error(err)
		}

		if len(images) != 3 {
			t.Error(errors.New("Incorrect number of images found"))
		}
		expectedImage := image.Response{
			Name:            "Ubuntu Server 14.04.1 LTS (amd64 20140927) - Partner Image",
			ContainerFormat: "bare",
			DiskFormat:      "qcow2",
			CheckSum:        "6798a7d67ff0b241b6fe165798914d86",
			ID:              "bec3cab5-4722-40b9-a78a-3489218e22fe",
			Size:            255525376}
		// Verify first one matches expected values
		testUtil.Equals(t, expectedImage, images[0])
	}

	testImageServiceAction(t, "images", sampleImagesData, anon)
}