Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #576 from kaccardi/topic/enable-os-image-tests
Browse files Browse the repository at this point in the history
Enable unit testing for openstack image package
  • Loading branch information
mcastelino authored Sep 16, 2016
2 parents 45d5548 + c185451 commit 53c686c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ script:
- sudo mkdir -p /var/lib/ciao/instances
- sudo chmod 0777 /var/lib/ciao/instances
- test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -short github.com/01org/ciao/ciao-controller/...
- test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -append-profile -short github.com/01org/ciao/ciao-launcher github.com/01org/ciao/ciao-scheduler github.com/01org/ciao/payloads github.com/01org/ciao/configuration github.com/01org/ciao/testutil github.com/01org/ciao/ssntp/uuid github.com/01org/ciao/qemu github.com/01org/ciao/openstack/block github.com/01org/ciao/openstack/identity
- test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -append-profile -short github.com/01org/ciao/ciao-launcher github.com/01org/ciao/ciao-scheduler github.com/01org/ciao/payloads github.com/01org/ciao/configuration github.com/01org/ciao/testutil github.com/01org/ciao/ssntp/uuid github.com/01org/ciao/qemu github.com/01org/ciao/openstack/...
- export GOROOT=`go env GOROOT` && sudo -E PATH=$PATH:$GOROOT/bin $GOPATH/bin/test-cases -v -timeout 9 -text -coverprofile /tmp/cover.out -append-profile github.com/01org/ciao/ssntp
- export GOROOT=`go env GOROOT` && export SNNET_ENV=198.51.100.0/24 && sudo -E PATH=$PATH:$GOROOT/bin $GOPATH/bin/test-cases -v -timeout 9 -text -short -tags travis -coverprofile /tmp/cover.out -append-profile github.com/01org/ciao/networking/libsnnet
# API Documentation is automated by swagger, every PR will verify the documentation can be generated
Expand Down
58 changes: 53 additions & 5 deletions openstack/image/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package image
import (
"bytes"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -59,6 +60,14 @@ var tests = []test{
http.StatusOK,
`{"images":[{"status":"queued","container_format":"bare","min_ram":0,"updated_at":"2015-11-29T22:21:42Z","owner":"bab7d5c60cd041a0a36f7c4b6e1dd978","min_disk":0,"tags":[],"locations":[],"visibility":"private","id":"b2173dd3-7ad6-4362-baa6-a68bce3565cb","size":null,"virtual_size":null,"name":"Ubuntu","checksum":null,"created_at":"2015-11-29T22:21:42Z","disk_format":"raw","properties":null,"protected":false,"self":"/v2/images/b2173dd3-7ad6-4362-baa6-a68bce3565cb","file":"/v2/images/b2173dd3-7ad6-4362-baa6-a68bce3565cb/file","schema":"/v2/schemas/image"}],"schema":"/v2/schemas/images","first":"/v2/images"}`,
},
{
"GET",
"/v2/images/1bea47ed-f6a9-463b-b423-14b9cca9ad27",
getImage,
"",
http.StatusOK,
`{"status":"active","container_format":"bare","min_ram":0,"updated_at":"2014-05-05T17:15:11Z","owner":"5ef70662f8b34079a6eddb8da9d75fe8","min_disk":0,"tags":[],"locations":[],"visibility":"public","id":"1bea47ed-f6a9-463b-b423-14b9cca9ad27","size":13167616,"virtual_size":null,"name":"cirros-0.3.2-x86_64-disk","checksum":"64d7c1cd2b6f60c92c14662941cb7913","created_at":"2014-05-05T17:15:10Z","disk_format":"qcow2","properties":null,"protected":false,"self":"/v2/images/1bea47ed-f6a9-463b-b423-14b9cca9ad27","file":"/v2/images/1bea47ed-f6a9-463b-b423-14b9cca9ad27/file","schema":"/v2/schemas/image"}`,
},
}

func myHostname() string {
Expand All @@ -68,7 +77,7 @@ func myHostname() string {

type testImageService struct{}

func (is testImageService) CreateImage(req CreateImageRequest) (CreateImageResponse, error) {
func (is testImageService) CreateImage(req CreateImageRequest) (DefaultResponse, error) {
format := Bare
name := "Ubuntu"
createdAt, _ := time.Parse(time.RFC3339, "2015-11-29T22:21:42Z")
Expand All @@ -77,7 +86,7 @@ func (is testImageService) CreateImage(req CreateImageRequest) (CreateImageRespo
minRAM := 0
owner := "bab7d5c60cd041a0a36f7c4b6e1dd978"

return CreateImageResponse{
return DefaultResponse{
Status: Queued,
ContainerFormat: &format,
CreatedAt: createdAt,
Expand All @@ -98,7 +107,7 @@ func (is testImageService) CreateImage(req CreateImageRequest) (CreateImageRespo
}, nil
}

func (is testImageService) ListImages() ([]CreateImageResponse, error) {
func (is testImageService) ListImages() ([]DefaultResponse, error) {
format := Bare
name := "Ubuntu"
createdAt, _ := time.Parse(time.RFC3339, "2015-11-29T22:21:42Z")
Expand All @@ -107,7 +116,7 @@ func (is testImageService) ListImages() ([]CreateImageResponse, error) {
minRAM := 0
owner := "bab7d5c60cd041a0a36f7c4b6e1dd978"

image := CreateImageResponse{
image := DefaultResponse{
Status: Queued,
ContainerFormat: &format,
CreatedAt: createdAt,
Expand All @@ -127,12 +136,51 @@ func (is testImageService) ListImages() ([]CreateImageResponse, error) {
Name: &name,
}

var images []CreateImageResponse
var images []DefaultResponse
images = append(images, image)

return images, nil
}

func (is testImageService) GetImage(ID string) (DefaultResponse, error) {
imageID := "1bea47ed-f6a9-463b-b423-14b9cca9ad27"
format := Bare
name := "cirros-0.3.2-x86_64-disk"
createdAt, _ := time.Parse(time.RFC3339, "2014-05-05T17:15:10Z")
updatedAt, _ := time.Parse(time.RFC3339, "2014-05-05T17:15:11Z")
minDisk := 0
minRAM := 0
owner := "5ef70662f8b34079a6eddb8da9d75fe8"
checksum := "64d7c1cd2b6f60c92c14662941cb7913"
size := 13167616

return DefaultResponse{
Status: Active,
ContainerFormat: &format,
CreatedAt: createdAt,
Tags: make([]string, 0),
DiskFormat: QCow,
Visibility: Public,
UpdatedAt: &updatedAt,
Locations: make([]string, 0),
Self: fmt.Sprintf("/v2/images/%s", imageID),
MinDisk: &minDisk,
Protected: false,
CheckSum: &checksum,
ID: imageID,
File: fmt.Sprintf("/v2/images/%s/file", imageID),
Owner: &owner,
MinRAM: &minRAM,
Schema: "/v2/schemas/image",
Name: &name,
Size: &size,
}, nil
}

func (is testImageService) UploadImage(string, io.Reader) (UploadImageResponse, error) {
return UploadImageResponse{}, nil
}

func TestRoutes(t *testing.T) {
var is testImageService
config := APIConfig{9292, is}
Expand Down

0 comments on commit 53c686c

Please sign in to comment.