github.com/true-sqn/fabric@v2.1.1+incompatible/core/operations/version_test.go (about)

     1  /*
     2  Copyright IBM Corp All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package operations
     8  
     9  import (
    10  	"net/http"
    11  	"net/http/httptest"
    12  
    13  	. "github.com/onsi/ginkgo"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  var _ = Describe("Version", func() {
    18  	It("returns 200 if the method is GET", func() {
    19  		resp := httptest.NewRecorder()
    20  
    21  		versionInfoHandler := &VersionInfoHandler{Version: "latest"}
    22  		versionInfoHandler.ServeHTTP(resp, &http.Request{Method: http.MethodGet})
    23  		Expect(resp.Result().StatusCode).To(Equal(http.StatusOK))
    24  		Expect(resp.Body).To(MatchJSON(`{"Version": "latest"}`))
    25  	})
    26  
    27  	It("returns 400 when an unsupported method is used", func() {
    28  		resp := httptest.NewRecorder()
    29  
    30  		versionInfoHandler := &VersionInfoHandler{}
    31  		versionInfoHandler.ServeHTTP(resp, &http.Request{Method: http.MethodPut})
    32  		Expect(resp.Result().StatusCode).To(Equal(http.StatusBadRequest))
    33  		Expect(resp.Body).To(MatchJSON(`{"Error": "invalid request method: PUT"}`))
    34  	})
    35  
    36  	It("returns 500 when the payload is invalid JSON", func() {
    37  		resp := httptest.NewRecorder()
    38  
    39  		versionInfoHandler := &VersionInfoHandler{}
    40  		versionInfoHandler.sendResponse(resp, 200, make(chan int))
    41  		Expect(resp.Result().StatusCode).To(Equal(http.StatusInternalServerError))
    42  	})
    43  })