github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/common/enroller/enroller_suite_test.go (about)

     1  /*
     2   * Copyright contributors to the Hyperledger Fabric Operator project
     3   *
     4   * SPDX-License-Identifier: Apache-2.0
     5   *
     6   * Licensed under the Apache License, Version 2.0 (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at:
     9   *
    10   * 	  http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  package enroller_test
    20  
    21  import (
    22  	"net/http"
    23  	"net/http/httptest"
    24  	"testing"
    25  
    26  	"github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/enroller"
    27  	"github.com/hyperledger/fabric-ca/lib"
    28  	. "github.com/onsi/ginkgo/v2"
    29  	. "github.com/onsi/gomega"
    30  )
    31  
    32  func TestEnroller(t *testing.T) {
    33  	RegisterFailHandler(Fail)
    34  	RunSpecs(t, "Enroller Suite")
    35  }
    36  
    37  var (
    38  	server      *httptest.Server
    39  	fabCaClient *enroller.FabCAClient
    40  )
    41  
    42  var _ = BeforeSuite(func() {
    43  	server = httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
    44  		// Test request parameters
    45  		Expect(req.URL.String()).To(Equal("/cainfo"))
    46  		// Send response to be tested
    47  		rw.Write([]byte(`OK`))
    48  	}))
    49  
    50  	fabCaClient = &enroller.FabCAClient{
    51  		Client: &lib.Client{
    52  			Config: &lib.ClientConfig{
    53  				URL: server.URL,
    54  			},
    55  		},
    56  	}
    57  })
    58  
    59  var _ = AfterSuite(func() {
    60  	server.Close()
    61  })
    62  
    63  //go:generate counterfeiter -o mocks/client.go -fake-name Client ../../../k8s/controllerclient Client