github.com/confluentinc/cli@v1.100.0/test/price_test.go (about)

     1  package test
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"net/http"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/require"
    11  
    12  	orgv1 "github.com/confluentinc/cc-structs/kafka/org/v1"
    13  )
    14  
    15  const (
    16  	exampleAvailability = "low"
    17  	exampleCloud        = "aws"
    18  	exampleClusterType  = "basic"
    19  	exampleMetric       = "ConnectNumRecords"
    20  	exampleNetworkType  = "internet"
    21  	examplePrice        = 1
    22  	exampleRegion       = "us-east-1"
    23  	exampleUnit         = "GB"
    24  )
    25  
    26  func (s *CLITestSuite) TestPriceList() {
    27  	tests := []CLITest{
    28  		{
    29  			args:    fmt.Sprintf("price list --cloud %s --region %s", exampleCloud, exampleRegion),
    30  			fixture: "price/list.golden",
    31  		},
    32  	}
    33  
    34  	for _, test := range tests {
    35  		test.login = "default"
    36  		loginURL := serve(s.T(), "").URL
    37  		s.runCcloudTest(test, loginURL)
    38  	}
    39  }
    40  
    41  func handlePriceTable(t *testing.T) func(w http.ResponseWriter, r *http.Request) {
    42  	return func(w http.ResponseWriter, r *http.Request) {
    43  		prices := map[string]float64{
    44  			strings.Join([]string{exampleCloud, exampleRegion, exampleAvailability, exampleClusterType, exampleNetworkType}, ":"): examplePrice,
    45  		}
    46  
    47  		res := &orgv1.GetPriceTableReply{
    48  			PriceTable: &orgv1.PriceTable{
    49  				PriceTable: map[string]*orgv1.UnitPrices{
    50  					exampleMetric: {Unit: exampleUnit, Prices: prices},
    51  				},
    52  			},
    53  		}
    54  
    55  		data, err := json.Marshal(res)
    56  		require.NoError(t, err)
    57  		_, err = w.Write(data)
    58  		require.NoError(t, err)
    59  	}
    60  }