@@ -9,6 +9,7 @@ package v1
99import (
1010 "bytes"
1111 "testing"
12+ "time"
1213
1314 "github.com/stretchr/testify/require"
1415
@@ -56,3 +57,131 @@ func TestInfoCommand_NilConfigPrintsNull(t *testing.T) {
5657 require .NoError (t , err )
5758 require .Contains (t , outBuf .String (), "null" )
5859}
60+
61+ func TestInfoCommand_PrintsEnvConfig (t * testing.T ) {
62+ t .Parallel ()
63+
64+ boolPtr := func (b bool ) * bool { return & b }
65+
66+ var outBuf bytes.Buffer
67+ ctx := & CLIContext {
68+ Config : & config.Config {
69+ Logging : config.LoggingConfig {
70+ Level : "ERROR" ,
71+ Format : "%{color}%{level}%{color:reset} %{message}" ,
72+ },
73+ MSP : config.MSPConfig {
74+ LocalMspID : "Org1MSP" ,
75+ ConfigPath : "/path/to/msp" ,
76+ },
77+ TLS : config.TLSConfig {
78+ Enabled : boolPtr (true ),
79+ ClientKeyPath : "/path/to/client.key" ,
80+ ClientCertPath : "/path/to/client.crt" ,
81+ RootCertPaths : []string {"/path/to/ca.crt" },
82+ },
83+ Orderer : config.OrdererConfig {
84+ EndpointServiceConfig : config.EndpointServiceConfig {
85+ Address : "localhost:7050" ,
86+ ConnectionTimeout : 30 * time .Second ,
87+ TLS : & config.TLSConfig {
88+ Enabled : boolPtr (true ),
89+ RootCertPaths : []string {"/path/to/orderer-ca.crt" },
90+ ClientCertPath : "/path/to/orderer-client.crt" ,
91+ ClientKeyPath : "/path/to/orderer-client.key" ,
92+ },
93+ },
94+ Channel : "mychannel" ,
95+ },
96+ Queries : config.QueriesConfig {
97+ EndpointServiceConfig : config.EndpointServiceConfig {
98+ Address : "localhost:7001" ,
99+ ConnectionTimeout : 30 * time .Second ,
100+ TLS : & config.TLSConfig {
101+ Enabled : boolPtr (true ),
102+ RootCertPaths : []string {"/path/to/peer-ca.crt" },
103+ },
104+ },
105+ },
106+ Notifications : config.NotificationsConfig {
107+ EndpointServiceConfig : config.EndpointServiceConfig {
108+ Address : "localhost:7001" ,
109+ ConnectionTimeout : 30 * time .Second ,
110+ TLS : & config.TLSConfig {
111+ Enabled : boolPtr (false ),
112+ },
113+ },
114+ WaitingTimeout : 30 * time .Second ,
115+ },
116+ },
117+ Printer : cliio .NewCLIPrinter (& outBuf , & outBuf , cliio .FormatTable ),
118+ }
119+
120+ cmd := NewInfoCommand (ctx )
121+ err := cmd .Flags ().Set ("format" , "env" )
122+ require .NoError (t , err )
123+
124+ err = cmd .RunE (cmd , nil )
125+ require .NoError (t , err )
126+
127+ output := outBuf .String ()
128+ require .Contains (t , output , "FXCONFIG_LOGGING_LEVEL=ERROR" )
129+ require .Contains (t , output , "FXCONFIG_MSP_LOCALMSPID=Org1MSP" )
130+ require .Contains (t , output , "FXCONFIG_MSP_CONFIGPATH=/path/to/msp" )
131+ require .Contains (t , output , "FXCONFIG_TLS_ENABLED=true" )
132+ require .Contains (t , output , "FXCONFIG_TLS_CLIENTKEY=/path/to/client.key" )
133+ require .Contains (t , output , "FXCONFIG_TLS_CLIENTCERT=/path/to/client.crt" )
134+ require .Contains (t , output , "FXCONFIG_TLS_ROOTCERTS=/path/to/ca.crt" )
135+ require .Contains (t , output , "FXCONFIG_ORDERER_ADDRESS=localhost:7050" )
136+ require .Contains (t , output , "FXCONFIG_ORDERER_CHANNEL=mychannel" )
137+ require .Contains (t , output , "FXCONFIG_ORDERER_CONNECTIONTIMEOUT=30s" )
138+ require .Contains (t , output , "FXCONFIG_QUERIES_ADDRESS=localhost:7001" )
139+ require .Contains (t , output , "FXCONFIG_NOTIFICATIONS_ADDRESS=localhost:7001" )
140+ }
141+
142+ func TestInfoCommand_PrintsEnvConfig_MultipleCerts (t * testing.T ) {
143+ t .Parallel ()
144+
145+ boolPtr := func (b bool ) * bool { return & b }
146+
147+ var outBuf bytes.Buffer
148+ ctx := & CLIContext {
149+ Config : & config.Config {
150+ TLS : config.TLSConfig {
151+ Enabled : boolPtr (true ),
152+ ClientKeyPath : "/path/to/client.key" ,
153+ ClientCertPath : "/path/to/client.crt" ,
154+ RootCertPaths : []string {"/path/to/ca1.crt" , "/path/to/ca2.crt" },
155+ },
156+ },
157+ Printer : cliio .NewCLIPrinter (& outBuf , & outBuf , cliio .FormatTable ),
158+ }
159+
160+ cmd := NewInfoCommand (ctx )
161+ err := cmd .Flags ().Set ("format" , "env" )
162+ require .NoError (t , err )
163+
164+ err = cmd .RunE (cmd , nil )
165+ require .NoError (t , err )
166+
167+ output := outBuf .String ()
168+ require .Contains (t , output , "FXCONFIG_TLS_ROOTCERTS=/path/to/ca1.crt,/path/to/ca2.crt" )
169+ }
170+
171+ func TestInfoCommand_InvalidFormat (t * testing.T ) {
172+ t .Parallel ()
173+
174+ var outBuf bytes.Buffer
175+ ctx := & CLIContext {
176+ Config : & config.Config {},
177+ Printer : cliio .NewCLIPrinter (& outBuf , & outBuf , cliio .FormatTable ),
178+ }
179+
180+ cmd := NewInfoCommand (ctx )
181+ err := cmd .Flags ().Set ("format" , "json" )
182+ require .NoError (t , err )
183+
184+ err = cmd .RunE (cmd , nil )
185+ require .Error (t , err )
186+ require .Contains (t , err .Error (), "invalid --format: json (want yaml|env)" )
187+ }
0 commit comments