forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the BDD testing frameworkg Ginko and its macher library Gomega. Further add first REST tests for the RawDomainEndpoint. Change-Id: I48b6b968f568c9bcf952fe3346bbd7ac2df98c86 Signed-off-by: Roman Mohr <[email protected]>
- Loading branch information
Showing
8 changed files
with
220 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestVirtController(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "VirtController Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"golang.org/x/net/context" | ||
"net/http" | ||
|
||
"io/ioutil" | ||
"net/http/httptest" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
func newValidRequest() *http.Request { | ||
request, _ := http.NewRequest("POST", "/api/v1/domain/raw", nil) | ||
request.Body = ioutil.NopCloser(strings.NewReader("<domain><name>testvm</name></domain>")) | ||
request.Header.Set("Content-Type", "application/xml") | ||
return request | ||
|
||
} | ||
|
||
type mockVmService struct{} | ||
|
||
func (mockVmService) StartVmRaw(name string) error { | ||
return nil | ||
} | ||
|
||
var _ = Describe("VirtController", func() { | ||
var recorder *httptest.ResponseRecorder | ||
ctx := context.Background() | ||
svc := mockVmService{} | ||
endpoints := Handlers{ | ||
RawDomainHandler: makeRawDomainHandler(ctx, makeRawDomainEndpoint(svc)), | ||
} | ||
handler := http.Handler(defineRoutes(&endpoints)) | ||
|
||
BeforeEach(func() { | ||
recorder = httptest.NewRecorder() | ||
}) | ||
|
||
Describe("REST call", func() { | ||
Context("with invalid URL", func() { | ||
It("should return 404", func() { | ||
request := newValidRequest() | ||
request.URL, _ = url.Parse("/api/v1/wrong/url") | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(404)) | ||
}) | ||
}) | ||
Context("with missing Content-Type header", func() { | ||
It("should return 404", func() { | ||
request := newValidRequest() | ||
request.Header.Del("Content-Type") | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(404)) | ||
}) | ||
}) | ||
Context("with invalid XML", func() { | ||
It("should return 400", func() { | ||
request := newValidRequest() | ||
request.Body = ioutil.NopCloser(strings.NewReader("test")) | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(400)) | ||
}) | ||
}) | ||
Context("with unexpected root XML element", func() { | ||
It("should return 400", func() { | ||
request := newValidRequest() | ||
request.Body = ioutil.NopCloser(strings.NewReader("<test><name>myvm</name></test>")) | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(400)) | ||
}) | ||
}) | ||
Context("with missing VM name", func() { | ||
It("should return 400", func() { | ||
request := newValidRequest() | ||
request.Body = ioutil.NopCloser(strings.NewReader("<domain><name></name></domain>")) | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(400)) | ||
}) | ||
}) | ||
Context("with valid XMl", func() { | ||
It("should return 200", func() { | ||
request := newValidRequest() | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(200)) | ||
}) | ||
}) | ||
}) | ||
|
||
}) |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestVirtLauncher(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "VirtLauncher Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters