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.
Fixed CDI dep and updated rest endpoint test
See emicklei/go-restful#396 for the changes test Signed-off-by: Marc Sluiter <[email protected]>
- Loading branch information
Showing
314 changed files
with
33,622 additions
and
13,274 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 |
---|---|---|
|
@@ -38,7 +38,9 @@ import ( | |
|
||
func newValidJSONPostRequest() *http.Request { | ||
request, _ := http.NewRequest("POST", "/apis/kubevirt.io/v1alpha3/namespaces/default/virtualmachineinstances", nil) | ||
request.Body = marshalToJSON(payload{Name: "test", Email: "[email protected]"}) | ||
length := 0 | ||
request.Body, length = marshalToJSON(payload{Name: "test", Email: "[email protected]"}) | ||
request.ContentLength = int64(length) | ||
request.Header.Set("Content-Type", rest.MIME_JSON) | ||
return request | ||
} | ||
|
@@ -90,14 +92,14 @@ var _ = Describe("Post", func() { | |
}) | ||
Context("with missing name field", func() { | ||
It("should return 400", func() { | ||
request.Body = marshalToJSON(payload{Email: "[email protected]"}) | ||
request.Body, _ = marshalToJSON(payload{Email: "[email protected]"}) | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(http.StatusBadRequest)) | ||
}) | ||
}) | ||
Context("with invalid email", func() { | ||
It("should return 400", func() { | ||
request.Body = marshalToJSON(payload{Name: "test", Email: "wrong"}) | ||
request.Body, _ = marshalToJSON(payload{Name: "test", Email: "wrong"}) | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(http.StatusBadRequest)) | ||
}) | ||
|
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 |
---|---|---|
|
@@ -38,18 +38,18 @@ import ( | |
"kubevirt.io/kubevirt/pkg/rest" | ||
) | ||
|
||
func marshalToJSON(payload interface{}) io.ReadCloser { | ||
func marshalToJSON(payload interface{}) (io.ReadCloser, int) { | ||
var b []byte | ||
buffer := bytes.NewBuffer(b) | ||
Expect(json.NewEncoder(buffer).Encode(payload)).To(Succeed()) | ||
return ioutil.NopCloser(buffer) | ||
return ioutil.NopCloser(buffer), buffer.Len() | ||
} | ||
|
||
func toReader(json string) io.ReadCloser { | ||
func toReader(json string) (io.ReadCloser, int) { | ||
var b []byte | ||
buffer := bytes.NewBuffer(b) | ||
buffer.WriteString(json) | ||
return ioutil.NopCloser(buffer) | ||
return ioutil.NopCloser(buffer), buffer.Len() | ||
} | ||
|
||
func marshalToYAML(payload interface{}) io.ReadCloser { | ||
|
@@ -69,7 +69,9 @@ type payload struct { | |
|
||
func newValidPutRequest() *http.Request { | ||
request, _ := http.NewRequest("PUT", "/apis/kubevirt.io/v1alpha3/namespaces/default/virtualmachineinstances/test", nil) | ||
request.Body = marshalToJSON(payload{Name: "test", Email: "[email protected]"}) | ||
length := 0 | ||
request.Body, length = marshalToJSON(payload{Name: "test", Email: "[email protected]"}) | ||
request.ContentLength = int64(length) | ||
request.Header.Set("Content-Type", rest.MIME_JSON) | ||
return request | ||
} | ||
|
@@ -122,14 +124,14 @@ var _ = Describe("Put", func() { | |
}) | ||
Context("with missing name field", func() { | ||
It("should return 400", func() { | ||
request.Body = marshalToJSON(payload{Email: "[email protected]"}) | ||
request.Body, _ = marshalToJSON(payload{Email: "[email protected]"}) | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(http.StatusBadRequest)) | ||
}) | ||
}) | ||
Context("with invalid email", func() { | ||
It("should return 400", func() { | ||
request.Body = marshalToJSON(payload{Name: "test", Email: "wrong"}) | ||
request.Body, _ = marshalToJSON(payload{Name: "test", Email: "wrong"}) | ||
handler.ServeHTTP(recorder, request) | ||
Expect(recorder.Code).To(Equal(http.StatusBadRequest)) | ||
}) | ||
|
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
Oops, something went wrong.