github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/test/e2e/stack.go (about)

     1  // Copyright © 2021 Kaleido, Inc.
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package e2e
    18  
    19  import (
    20  	"encoding/json"
    21  	"io/ioutil"
    22  )
    23  
    24  type Stack struct {
    25  	Members []*Member `json:"members,omitempty"`
    26  }
    27  
    28  type Member struct {
    29  	ExposedFireflyPort int `json:"exposedFireflyPort,omitempty"`
    30  }
    31  
    32  func GetMemberPort(filename string, n int) (int, error) {
    33  	jsonBytes, err := ioutil.ReadFile(filename)
    34  	if err != nil {
    35  		return 0, err
    36  	}
    37  
    38  	var stack Stack
    39  	err = json.Unmarshal(jsonBytes, &stack)
    40  	if err != nil {
    41  		return 0, err
    42  	}
    43  
    44  	return stack.Members[n].ExposedFireflyPort, nil
    45  }