github.com/0chain/gosdk@v1.17.11/core/conf/reader_test.go (about)

     1  package conf
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestJSONReader(t *testing.T) {
    10  
    11  	reader, _ := NewReaderFromJSON(`{
    12  		"chain_id":"chain_id",
    13  		"signature_scheme" : "bls0chain",
    14  		"block_worker" : "http://localhost/dns",
    15  		"min_submit" : -20,
    16  		"min_confirmation" : 10,
    17  		"confirmation_chain_length" : 0,
    18  		"preferred_blobbers":["http://localhost:31051",
    19  		"http://localhost:31052",
    20  		"http://localhost:31053"
    21  		]
    22  }`)
    23  
    24  	tests := []struct {
    25  		name string
    26  		run  func(*require.Assertions)
    27  	}{
    28  		{
    29  			name: "Test_JSONReader_GetString",
    30  			run: func(r *require.Assertions) {
    31  				r.Equal("chain_id", reader.GetString("chain_id"))
    32  				r.Equal("bls0chain", reader.GetString("signature_scheme"))
    33  				r.Equal("http://localhost/dns", reader.GetString("block_worker"))
    34  			},
    35  		},
    36  		{
    37  			name: "Test_JSONReader_GetInt",
    38  
    39  			run: func(r *require.Assertions) {
    40  				r.Equal(-20, reader.GetInt("min_submit"))
    41  				r.Equal(10, reader.GetInt("min_confirmation"))
    42  				r.Equal(0, reader.GetInt("confirmation_chain_length"))
    43  			},
    44  		},
    45  		{
    46  			name: "Test_JSONReader_GetStringSlice",
    47  			run: func(r *require.Assertions) {
    48  
    49  				preferredBlobbers := reader.GetStringSlice("preferred_blobbers")
    50  
    51  				r.Equal(3, len(preferredBlobbers))
    52  				r.Equal(preferredBlobbers[0], "http://localhost:31051")
    53  				r.Equal(preferredBlobbers[1], "http://localhost:31052")
    54  				r.Equal(preferredBlobbers[2], "http://localhost:31053")
    55  			},
    56  		},
    57  	}
    58  	for _, tt := range tests {
    59  		t.Run(tt.name, func(t *testing.T) {
    60  
    61  			require := require.New(t)
    62  
    63  			tt.run(require)
    64  
    65  		})
    66  	}
    67  }