Skip to content

Commit

Permalink
fix indentation
Browse files Browse the repository at this point in the history
Signed-off-by: Przemyslaw Lal <przemyslawx.lal@intel.com>
  • Loading branch information
przemeklal authored and rkamudhan committed Nov 12, 2018
1 parent 0903a11 commit bf89318
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 68 deletions.
8 changes: 4 additions & 4 deletions webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func prepareAdmissionReviewResponse(allowed bool, message string, ar *v1beta1.Ad
Message: message,
}
}
return nil
return nil
} else {
return fmt.Errorf("AdmissionReview request empty")
}
return fmt.Errorf("AdmissionReview request empty")
}
}

func deserializeAdmissionReview(body []byte) (v1beta1.AdmissionReview, error) {
Expand Down Expand Up @@ -175,7 +175,7 @@ func validateHandler(w http.ResponseWriter, req *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

writeResponse(w, ar)
}

Expand Down
128 changes: 64 additions & 64 deletions webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,82 +19,82 @@ import (
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

"bytes"
"net/http"
"net/http/httptest"
"bytes"
"net/http"
"net/http/httptest"

"k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/api/admission/v1beta1"

"github.com/intel/multus-cni/types"
)

var _ = Describe("Webhook", func() {

Describe("Preparing Admission Review Response", func() {
Context("Admission Review Request is nil", func() {
It("should return error", func() {
ar := &v1beta1.AdmissionReview{}
ar.Request = nil
Expect(prepareAdmissionReviewResponse(false, "", ar)).To(HaveOccurred())
})
})
Context("Message is not empty", func() {
It("should set message in the response", func() {
ar := &v1beta1.AdmissionReview{}
ar.Request = &v1beta1.AdmissionRequest{
UID: "fake-uid",
}
err := prepareAdmissionReviewResponse(false, "some message", ar)
Expect(err).NotTo(HaveOccurred())
Expect(ar.Response.Result.Message).To(Equal("some message"))
})
})
})
Describe("Preparing Admission Review Response", func() {
Context("Admission Review Request is nil", func() {
It("should return error", func() {
ar := &v1beta1.AdmissionReview{}
ar.Request = nil
Expect(prepareAdmissionReviewResponse(false, "", ar)).To(HaveOccurred())
})
})
Context("Message is not empty", func() {
It("should set message in the response", func() {
ar := &v1beta1.AdmissionReview{}
ar.Request = &v1beta1.AdmissionRequest{
UID: "fake-uid",
}
err := prepareAdmissionReviewResponse(false, "some message", ar)
Expect(err).NotTo(HaveOccurred())
Expect(ar.Response.Result.Message).To(Equal("some message"))
})
})
})

Describe("Deserializing Admission Review", func() {
Context("It's not an Admission Review", func() {
It("should return an error", func() {
body := []byte("some-invalid-body")
_, err := deserializeAdmissionReview(body)
Expect(err).To(HaveOccurred())
})
})
})
Describe("Deserializing Admission Review", func() {
Context("It's not an Admission Review", func() {
It("should return an error", func() {
body := []byte("some-invalid-body")
_, err := deserializeAdmissionReview(body)
Expect(err).To(HaveOccurred())
})
})
})

Describe("Deserializing Network Attachment Definition", func() {
Context("It's not an Network Attachment Definition", func() {
It("should return an error", func() {
ar := &v1beta1.AdmissionReview{}
ar.Request = &v1beta1.AdmissionRequest{}
_, err := deserializeNetworkAttachmentDefinition(*ar)
Expect(err).To(HaveOccurred())
})
})
})
Describe("Deserializing Network Attachment Definition", func() {
Context("It's not an Network Attachment Definition", func() {
It("should return an error", func() {
ar := &v1beta1.AdmissionReview{}
ar.Request = &v1beta1.AdmissionRequest{}
_, err := deserializeNetworkAttachmentDefinition(*ar)
Expect(err).To(HaveOccurred())
})
})
})

Describe("Handling validation request", func() {
Context("Request body is empty", func() {
It("should return an error", func() {
req := httptest.NewRequest("POST", "https://fakewebhook/validate", nil)
w := httptest.NewRecorder()
validateHandler(w, req)
resp := w.Result()
Expect(resp.StatusCode).To(Equal(http.StatusBadRequest))
})
})
Describe("Handling validation request", func() {
Context("Request body is empty", func() {
It("should return an error", func() {
req := httptest.NewRequest("POST", "https://fakewebhook/validate", nil)
w := httptest.NewRecorder()
validateHandler(w, req)
resp := w.Result()
Expect(resp.StatusCode).To(Equal(http.StatusBadRequest))
})
})

Context("Content type is not application/json", func() {
It("should return an error", func() {
req := httptest.NewRequest("POST", "https://fakewebhook/validate", bytes.NewBufferString("fake-body"))
req.Header.Set("Content-Type", "invalid-type")
w := httptest.NewRecorder()
validateHandler(w, req)
resp := w.Result()
Expect(resp.StatusCode).To(Equal(http.StatusUnsupportedMediaType))
})
})
})
Context("Content type is not application/json", func() {
It("should return an error", func() {
req := httptest.NewRequest("POST", "https://fakewebhook/validate", bytes.NewBufferString("fake-body"))
req.Header.Set("Content-Type", "invalid-type")
w := httptest.NewRecorder()
validateHandler(w, req)
resp := w.Result()
Expect(resp.StatusCode).To(Equal(http.StatusUnsupportedMediaType))
})
})
})

DescribeTable("Network Attachment Definition validation",
func(in types.NetworkAttachmentDefinition, out bool, shouldFail bool) {
Expand Down

0 comments on commit bf89318

Please sign in to comment.