@@ -6609,3 +6609,72 @@ software:
66096609 assert .Contains (t , err .Error (), "macos_manual_agent_install" )
66106610 })
66116611}
6612+
6613+ func TestGitOpsScriptsLogging (t * testing.T ) {
6614+ // Cannot run t.Parallel() because SetupFullGitOpsPremiumServer sets env vars.
6615+ ds , _ , _ := testing_utils .SetupFullGitOpsPremiumServer (t )
6616+
6617+ // Echo back a ScriptResponse for each input script so the real-run no-team
6618+ // log line reflects the count of scripts sent to the server. (In dry-run,
6619+ // the service short-circuits before reaching this mock.)
6620+ ds .BatchSetScriptsFunc = func (ctx context.Context , tmID * uint , scripts []* fleet.Script ) ([]fleet.ScriptResponse , error ) {
6621+ responses := make ([]fleet.ScriptResponse , len (scripts ))
6622+ for i , s := range scripts {
6623+ responses [i ] = fleet.ScriptResponse {ID : uint (i + 1 ), Name : s .Name , TeamID : s .TeamID } //nolint:gosec // dismiss G115
6624+ }
6625+ return responses , nil
6626+ }
6627+
6628+ // No labels — keep the test focused on scripts.
6629+ ds .GetLabelSpecsFunc = func (ctx context.Context , filter fleet.TeamFilter ) ([]* fleet.LabelSpec , error ) {
6630+ return nil , nil
6631+ }
6632+
6633+ tmpDir := t .TempDir ()
6634+ scriptPath := filepath .Join (tmpDir , "script.sh" )
6635+ require .NoError (t , os .WriteFile (scriptPath , []byte (`echo "hello"` ), 0o644 ))
6636+
6637+ globalPath := filepath .Join (tmpDir , "global.yml" )
6638+ require .NoError (t , os .WriteFile (globalPath , []byte (`
6639+ controls:
6640+ scripts:
6641+ - path: ./script.sh
6642+ queries:
6643+ policies:
6644+ agent_options:
6645+ org_settings:
6646+ server_settings:
6647+ server_url: $FLEET_SERVER_URL
6648+ org_info:
6649+ contact_url: https://example.com/contact
6650+ org_name: $ORG_NAME
6651+ secrets:
6652+ - secret: globalSecret
6653+ software:
6654+ ` ), 0o644 ))
6655+
6656+ teamPath := filepath .Join (tmpDir , "team.yml" )
6657+ require .NoError (t , os .WriteFile (teamPath , []byte (`
6658+ name: $TEST_TEAM_NAME
6659+ team_settings:
6660+ secrets:
6661+ - secret: team-secret
6662+ agent_options:
6663+ controls:
6664+ scripts:
6665+ - path: ./script.sh
6666+ policies:
6667+ queries:
6668+ software:
6669+ ` ), 0o644 ))
6670+
6671+ // Dry run.
6672+ logs := RunAppForTest (t , []string {"gitops" , "-f" , globalPath , "-f" , teamPath , "--dry-run" })
6673+ assert .Contains (t , logs , "[+] would've applied 1 script\n " )
6674+ assert .Contains (t , logs , fmt .Sprintf ("[+] would've applied 1 script for fleet %s\n " , teamName ))
6675+
6676+ // Real run.
6677+ logs = RunAppForTest (t , []string {"gitops" , "-f" , globalPath , "-f" , teamPath })
6678+ assert .Contains (t , logs , "[+] applied 1 script\n " )
6679+ assert .Contains (t , logs , fmt .Sprintf ("[+] applying 1 script for fleet %s\n " , teamName ))
6680+ }
0 commit comments