github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/integration/nwo/components.go (about)

     1  /*
     2  Copyright hechain All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package nwo
     8  
     9  import (
    10  	"fmt"
    11  	"io/ioutil"
    12  	"net/http"
    13  
    14  	"github.com/hechain20/hechain/integration/nwo/runner"
    15  	. "github.com/onsi/gomega"
    16  	"github.com/onsi/gomega/gexec"
    17  )
    18  
    19  type Components struct {
    20  	ServerAddress string `json:"server_address"`
    21  }
    22  
    23  func (c *Components) ConfigTxGen() string {
    24  	return c.Build("github.com/hechain20/hechain/cmd/configtxgen")
    25  }
    26  
    27  func (c *Components) Cryptogen() string {
    28  	return c.Build("github.com/hechain20/hechain/cmd/cryptogen")
    29  }
    30  
    31  func (c *Components) Discover() string {
    32  	return c.Build("github.com/hechain20/hechain/cmd/discover")
    33  }
    34  
    35  func (c *Components) Idemixgen() string {
    36  	idemixgen, err := gexec.Build("github.com/IBM/idemix/tools/idemixgen", "-mod=mod")
    37  	Expect(err).NotTo(HaveOccurred())
    38  	return idemixgen
    39  }
    40  
    41  func (c *Components) Orderer() string {
    42  	return c.Build("github.com/hechain20/hechain/cmd/orderer")
    43  }
    44  
    45  func (c *Components) Osnadmin() string {
    46  	return c.Build("github.com/hechain20/hechain/cmd/osnadmin")
    47  }
    48  
    49  func (c *Components) Peer() string {
    50  	return c.Build("github.com/hechain20/hechain/cmd/peer")
    51  }
    52  
    53  func (c *Components) Cleanup() {}
    54  
    55  func (c *Components) Build(path string) string {
    56  	Expect(c.ServerAddress).NotTo(BeEmpty(), "build server address is empty")
    57  
    58  	resp, err := http.Get(fmt.Sprintf("http://%s/%s", c.ServerAddress, path))
    59  	Expect(err).NotTo(HaveOccurred())
    60  
    61  	body, err := ioutil.ReadAll(resp.Body)
    62  	Expect(err).NotTo(HaveOccurred())
    63  
    64  	if resp.StatusCode != http.StatusOK {
    65  		Expect(resp.StatusCode).To(Equal(http.StatusOK), fmt.Sprintf("%s", body))
    66  	}
    67  
    68  	return string(body)
    69  }
    70  
    71  const CCEnvDefaultImage = "hyperledger/fabric-ccenv:latest"
    72  
    73  var RequiredImages = []string{
    74  	CCEnvDefaultImage,
    75  	runner.CouchDBDefaultImage,
    76  }