77 "slices"
88 "strings"
99 "testing"
10+ "time"
1011
1112 "gopkg.in/yaml.v3"
1213
@@ -106,13 +107,17 @@ password_storage: pgpass
106107func TestConfigShow_JSONOutput (t * testing.T ) {
107108 tmpDir , _ := setupConfigTest (t )
108109
110+ now := time .Now ()
111+
109112 // Create config file with JSON output format
110113 configContent := `api_url: https://json.api.com/v1
111114project_id: json-project
112115output: json
113116analytics: true
114117password_storage: none
115- `
118+ version_check_interval: 1h
119+ version_check_last_time: ` + now .Format (time .RFC3339 ) + "\n "
120+
116121 configFile := config .GetConfigFile (tmpDir )
117122 if err := os .WriteFile (configFile , []byte (configContent ), 0644 ); err != nil {
118123 t .Fatalf ("Failed to write config file: %v" , err )
@@ -131,18 +136,21 @@ password_storage: none
131136
132137 // Verify ALL JSON keys and their expected values
133138 expectedValues := map [string ]interface {}{
134- "api_url" : "https://json.api.com/v1" ,
135- "console_url" : "https://console.cloud.timescale.com" ,
136- "gateway_url" : "https://console.cloud.timescale.com/api" ,
137- "docs_mcp" : true ,
138- "docs_mcp_url" : "https://mcp.tigerdata.com/docs" ,
139- "project_id" : "json-project" ,
140- "service_id" : "" ,
141- "output" : "json" ,
142- "analytics" : true ,
143- "password_storage" : "none" ,
144- "debug" : false ,
145- "config_dir" : tmpDir ,
139+ "api_url" : "https://json.api.com/v1" ,
140+ "console_url" : "https://console.cloud.timescale.com" ,
141+ "gateway_url" : "https://console.cloud.timescale.com/api" ,
142+ "docs_mcp" : true ,
143+ "docs_mcp_url" : "https://mcp.tigerdata.com/docs" ,
144+ "project_id" : "json-project" ,
145+ "service_id" : "" ,
146+ "output" : "json" ,
147+ "analytics" : true ,
148+ "password_storage" : "none" ,
149+ "debug" : false ,
150+ "config_dir" : tmpDir ,
151+ "releases_url" : "https://cli.tigerdata.com" ,
152+ "version_check_interval" : float64 (3600000000000 ), // JSON unmarshals time.Duration as nanoseconds (1 hour = 3600000000000ns)
153+ "version_check_last_time" : now .Format (time .RFC3339 ),
146154 }
147155
148156 for key , expectedValue := range expectedValues {
@@ -160,13 +168,16 @@ password_storage: none
160168func TestConfigShow_YAMLOutput (t * testing.T ) {
161169 tmpDir , _ := setupConfigTest (t )
162170
171+ now := time .Now ()
172+
163173 // Create config file with YAML output format
164174 configContent := `api_url: https://yaml.api.com/v1
165175project_id: yaml-project
166176output: yaml
167177analytics: false
168178password_storage: keyring
169- `
179+ version_check_last_time: ` + now .Format (time .RFC3339 ) + "\n "
180+
170181 configFile := config .GetConfigFile (tmpDir )
171182 if err := os .WriteFile (configFile , []byte (configContent ), 0644 ); err != nil {
172183 t .Fatalf ("Failed to write config file: %v" , err )
@@ -178,30 +189,42 @@ password_storage: keyring
178189 }
179190
180191 // Parse YAML output
181- var result map [string ]interface {}
192+ var result map [string ]any
182193 if err := yaml .Unmarshal ([]byte (output ), & result ); err != nil {
183194 t .Fatalf ("Failed to parse YAML output: %v" , err )
184195 }
185196
186197 // Verify ALL YAML keys and their expected values
187- expectedValues := map [string ]interface {}{
188- "api_url" : "https://yaml.api.com/v1" ,
189- "console_url" : "https://console.cloud.timescale.com" ,
190- "gateway_url" : "https://console.cloud.timescale.com/api" ,
191- "docs_mcp" : true ,
192- "docs_mcp_url" : "https://mcp.tigerdata.com/docs" ,
193- "project_id" : "yaml-project" ,
194- "service_id" : "" ,
195- "output" : "yaml" ,
196- "analytics" : false ,
197- "password_storage" : "keyring" ,
198- "debug" : false ,
199- "config_dir" : tmpDir ,
198+ expectedValues := map [string ]any {
199+ "api_url" : "https://yaml.api.com/v1" ,
200+ "console_url" : "https://console.cloud.timescale.com" ,
201+ "gateway_url" : "https://console.cloud.timescale.com/api" ,
202+ "docs_mcp" : true ,
203+ "docs_mcp_url" : "https://mcp.tigerdata.com/docs" ,
204+ "project_id" : "yaml-project" ,
205+ "service_id" : "" ,
206+ "output" : "yaml" ,
207+ "analytics" : false ,
208+ "password_storage" : "keyring" ,
209+ "debug" : false ,
210+ "config_dir" : tmpDir ,
211+ "releases_url" : "https://cli.tigerdata.com" ,
212+ "version_check_interval" : "24h0m0s" , // YAML serializes time.Duration as string
213+ "version_check_last_time" : now ,
200214 }
201215
202216 for key , expectedValue := range expectedValues {
203- if result [key ] != expectedValue {
204- t .Errorf ("Expected %s '%v', got %v" , key , expectedValue , result [key ])
217+ switch expectedValue .(type ) {
218+ case time.Time :
219+ // YAML unmarshals time.Time as time.Time type, so we need to compare differently
220+ if expectedValue .(time.Time ).Format (time .RFC3339 ) != result [key ].(time.Time ).Format (time .RFC3339 ) {
221+ t .Errorf ("foo Expected %s '%v', got %v" , key , expectedValue , result [key ])
222+ }
223+ default :
224+ // Other types can be compared directly
225+ if result [key ] != expectedValue {
226+ t .Errorf ("Expected %s '%v', got %v" , key , expectedValue , result [key ])
227+ }
205228 }
206229 }
207230
0 commit comments