@@ -281,6 +281,117 @@ func (suite *InstallScriptsIntegrationTestSuite) assertCorrectVersion(ts *e2e.Se
281281 }
282282}
283283
284+ func (suite * InstallScriptsIntegrationTestSuite ) TestInstall_ConfigSet () {
285+ suite .OnlyRunForTags (tagsuite .InstallScripts )
286+ ts := e2e .New (suite .T (), false )
287+ defer ts .Close ()
288+
289+ baseUrl := "https://state-tool.s3.amazonaws.com/update/state/"
290+ scriptBaseName := "install."
291+ if runtime .GOOS != "windows" {
292+ scriptBaseName += "sh"
293+ } else {
294+ scriptBaseName += "ps1"
295+ }
296+ scriptUrl := baseUrl + constants .ChannelName + "/" + scriptBaseName
297+
298+ b , err := httputil .GetDirect (scriptUrl )
299+ suite .Require ().NoError (err )
300+ script := filepath .Join (ts .Dirs .Work , scriptBaseName )
301+ suite .Require ().NoError (fileutils .WriteFile (script , b ))
302+
303+ installDir := filepath .Join (ts .Dirs .Work , "install" )
304+ args := []string {script }
305+ args = append (args , "-t" , installDir )
306+ args = append (args , "-n" ) // non-interactive
307+ args = append (args , "-f" ) // force (like other working tests)
308+ args = append (args , "-b" , constants .ChannelName )
309+
310+ args = append (args , "--config-set" , "analytics.enabled=false" )
311+ args = append (args , "--config-set" , "output.format=json" )
312+ args = append (args , "--config-set" , "test.key1=value1" )
313+ args = append (args , "--config-set" , "test.key2=value2" )
314+
315+ appInstallDir := filepath .Join (ts .Dirs .Work , "app" )
316+ suite .NoError (fileutils .Mkdir (appInstallDir ))
317+
318+ cmd := "bash"
319+ opts := []e2e.SpawnOptSetter {
320+ e2e .OptArgs (args ... ),
321+ e2e .OptAppendEnv (constants .DisableRuntime + "=false" ),
322+ e2e .OptAppendEnv (fmt .Sprintf ("%s=%s" , constants .AppInstallDirOverrideEnvVarName , appInstallDir )),
323+ e2e .OptAppendEnv (fmt .Sprintf ("%s=FOO" , constants .OverrideSessionTokenEnvVarName )),
324+ e2e .OptAppendEnv (fmt .Sprintf ("%s=false" , constants .DisableActivateEventsEnvVarName )),
325+ }
326+ if runtime .GOOS == "windows" {
327+ cmd = "powershell.exe"
328+ opts = append (opts ,
329+ e2e .OptAppendEnv ("SHELL=" ),
330+ e2e .OptAppendEnv (constants .OverrideShellEnvVarName + "=" ),
331+ )
332+ }
333+ cp := ts .SpawnCmdWithOpts (cmd , opts ... )
334+ cp .Expect ("Preparing Installer for State Tool Package Manager" )
335+ if runtime .GOOS == "windows" {
336+ cp .Expect ("Continuing because the '--force' flag is set" ) // admin prompt
337+ }
338+ cp .Expect ("Installation Complete" , e2e .RuntimeSourcingTimeoutOpt )
339+
340+ cp .SendLine ("exit" )
341+ cp .ExpectExitCode (0 )
342+
343+ stateExec , err := installation .StateExecFromDir (installDir )
344+ suite .NoError (err )
345+ suite .FileExists (stateExec )
346+
347+ suite .verifyConfigValue (ts , stateExec , "analytics.enabled" , "false" )
348+ suite .verifyConfigValue (ts , stateExec , "output.format" , "json" )
349+ suite .verifyConfigValue (ts , stateExec , "test.key1" , "value1" )
350+ suite .verifyConfigValue (ts , stateExec , "test.key2" , "value2" )
351+
352+ suite .verifyConfigValueDirect (ts , "analytics.enabled" , "false" )
353+ suite .verifyConfigValueDirect (ts , "output.format" , "json" )
354+ suite .verifyConfigValueDirect (ts , "test.key1" , "value1" )
355+ suite .verifyConfigValueDirect (ts , "test.key2" , "value2" )
356+ }
357+
358+ func (suite * InstallScriptsIntegrationTestSuite ) verifyConfigValue (ts * e2e.Session , stateExec , key , expectedValue string ) {
359+ cp := ts .SpawnCmd (stateExec , "config" , "get" , key , "--output=json" )
360+ cp .ExpectExitCode (0 )
361+ output := strings .TrimSpace (cp .StrippedSnapshot ())
362+
363+ var result map [string ]interface {}
364+ err := json .Unmarshal ([]byte (output ), & result )
365+ suite .Require ().NoError (err , "Failed to parse JSON output: %s" , output )
366+
367+ // Extract the value field from the JSON object
368+ value , exists := result ["value" ]
369+ suite .Require ().True (exists , "JSON output missing 'value' field: %s" , output )
370+
371+ var actualValue string
372+ switch v := value .(type ) {
373+ case string :
374+ actualValue = v
375+ case bool :
376+ actualValue = fmt .Sprintf ("%t" , v )
377+ case float64 :
378+ actualValue = fmt .Sprintf ("%.0f" , v )
379+ default :
380+ actualValue = fmt .Sprintf ("%v" , v )
381+ }
382+
383+ suite .Equal (expectedValue , actualValue , "Config value for key %s should be %s, got %s" , key , expectedValue , actualValue )
384+ }
385+
386+ func (suite * InstallScriptsIntegrationTestSuite ) verifyConfigValueDirect (ts * e2e.Session , key , expectedValue string ) {
387+ cfg , err := config .NewCustom (ts .Dirs .Config , singlethread .New (), true )
388+ suite .Require ().NoError (err )
389+ defer cfg .Close ()
390+
391+ actualValue := cfg .GetString (key )
392+ suite .Equal (expectedValue , actualValue , "Config value for key %s should be %s, got %s (via config library)" , key , expectedValue , actualValue )
393+ }
394+
284395func (suite * InstallScriptsIntegrationTestSuite ) assertAnalytics (ts * e2e.Session ) {
285396 // Verify analytics reported a non-empty sessionToken.
286397 sessionTokenFound := false
0 commit comments