github.com/aeternity/aepp-sdk-go/v6@v6.0.0/cmd/terminal_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"math/big"
     7  	"os"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/aeternity/aepp-sdk-go/v6/utils"
    12  )
    13  
    14  func Test_printIf_BigIntBalancePrinted(t *testing.T) {
    15  	type args struct {
    16  		title string
    17  		v     *big.Int
    18  	}
    19  	tests := []struct {
    20  		name string
    21  		args args
    22  	}{
    23  		{
    24  			name: "Test that printIf() recognizes the big.Int special case",
    25  			args: args{
    26  				title: "Title",
    27  				v:     utils.NewIntFromUint64(1377),
    28  			},
    29  		},
    30  	}
    31  	for _, tt := range tests {
    32  		t.Run(tt.name, func(t *testing.T) {
    33  			rescueStdout := os.Stdout
    34  			r, w, _ := os.Pipe()
    35  			os.Stdout = w
    36  
    37  			printIf(tt.args.title, tt.args.v)
    38  
    39  			w.Close()
    40  			out, _ := ioutil.ReadAll(r)
    41  			outs := string(out)
    42  			os.Stdout = rescueStdout
    43  			fmt.Println("DEBUG", outs)
    44  
    45  			expected := tt.args.v.Text(10)
    46  			if !strings.Contains(outs, expected) {
    47  				t.Fatalf("The terminal pretty printer printIf did not print out the value of the BigInt, which was %s", expected)
    48  			}
    49  		})
    50  	}
    51  }