@@ -34,63 +34,6 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
3434 }
3535 }
3636
37- // --- CLI script generation for queue/topic config ---
38- // Reference: https://docs.solace.com/Admin-Ref/CLI-Reference/VMR_CLI_Commands.html
39- var cliScript string
40- if len (settings .queues ) > 0 {
41- cliScript += "enable\n configure\n "
42-
43- // Create VPN if not default
44- if settings .vpn != defaultVpn {
45- cliScript += fmt .Sprintf ("create message-vpn %s\n " , settings .vpn )
46- cliScript += "no shutdown\n "
47- cliScript += "exit\n "
48- cliScript += fmt .Sprintf ("client-profile default message-vpn %s\n " , settings .vpn )
49- cliScript += "message-spool\n "
50- cliScript += "allow-guaranteed-message-send\n "
51- cliScript += "allow-guaranteed-message-receive\n "
52- cliScript += "allow-guaranteed-endpoint-create\n "
53- cliScript += "allow-guaranteed-endpoint-create-durability all\n "
54- cliScript += "exit\n "
55- cliScript += "exit\n "
56- cliScript += fmt .Sprintf ("message-spool message-vpn %s\n " , settings .vpn )
57- cliScript += "max-spool-usage 60000\n "
58- cliScript += "exit\n "
59- }
60-
61- // Configure username and password
62- cliScript += fmt .Sprintf ("create client-username %s message-vpn %s\n " , settings .username , settings .vpn )
63- cliScript += fmt .Sprintf ("password %s\n " , settings .password )
64- cliScript += "no shutdown\n "
65- cliScript += "exit\n "
66-
67- // Configure VPN Basic authentication
68- cliScript += fmt .Sprintf ("message-vpn %s\n " , settings .vpn )
69- cliScript += "authentication basic auth-type internal\n "
70- cliScript += "no shutdown\n "
71- cliScript += "end\n "
72-
73- // Configure queues and topic subscriptions
74- cliScript += "configure\n "
75- cliScript += fmt .Sprintf ("message-spool message-vpn %s\n " , settings .vpn )
76- for queue , topics := range settings .queues {
77- // Create the queue first
78- cliScript += fmt .Sprintf ("create queue %s\n " , queue )
79- cliScript += "access-type exclusive\n "
80- cliScript += "permission all consume\n "
81- cliScript += "no shutdown\n "
82- cliScript += "exit\n "
83-
84- // Add topic subscriptions to the queue
85- for _ , topic := range topics {
86- cliScript += fmt .Sprintf ("queue %s\n " , queue )
87- cliScript += fmt .Sprintf ("subscription topic %s\n " , topic )
88- cliScript += "exit\n "
89- }
90- }
91- cliScript += "exit\n exit\n "
92- }
93-
9437 req := testcontainers.ContainerRequest {
9538 Image : img ,
9639 ExposedPorts : settings .exposedPorts ,
@@ -118,45 +61,47 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
11861 }
11962 }
12063
121- // Copy and execute CLI script inside the container if it was generated
122- if cliScript != "" {
123- // Write the CLI script to a temp file
124- tmpFile , err := os .CreateTemp ("" , "solace-queue-setup-*.cli" )
125- if err != nil {
126- return nil , fmt .Errorf ("failed to create temp CLI script: %w" , err )
127- }
128- defer os .Remove (tmpFile .Name ())
129- if _ , err := tmpFile .Write ([]byte (cliScript )); err != nil {
130- return nil , fmt .Errorf ("failed to write CLI script: %w" , err )
131- }
132- if err := tmpFile .Close (); err != nil {
133- return nil , fmt .Errorf ("failed to close CLI script: %w" , err )
134- }
64+ // Generate CLI script for queue/topic configuration
65+ cliScript := generateCLIScript (settings )
66+ if cliScript == "" {
67+ return c , nil
68+ }
69+ // Write the CLI script to a temp file
70+ tmpFile , err := os .CreateTemp ("" , "solace-queue-setup-*.cli" )
71+ if err != nil {
72+ return nil , fmt .Errorf ("failed to create temp CLI script: %w" , err )
73+ }
74+ defer os .Remove (tmpFile .Name ())
75+ if _ , err := tmpFile .Write ([]byte (cliScript )); err != nil {
76+ return nil , fmt .Errorf ("failed to write CLI script: %w" , err )
77+ }
78+ if err := tmpFile .Close (); err != nil {
79+ return nil , fmt .Errorf ("failed to close CLI script: %w" , err )
80+ }
13581
136- // Copy the script into the container at the correct location
137- err = c .CopyFileToContainer (ctx , tmpFile .Name (), "/usr/sw/jail/cliscripts/script.cli" , 0o644 )
138- if err != nil {
139- return nil , fmt .Errorf ("failed to copy CLI script to container: %w" , err )
140- }
82+ // Copy the script into the container at the correct location
83+ err = c .CopyFileToContainer (ctx , tmpFile .Name (), "/usr/sw/jail/cliscripts/script.cli" , 0o644 )
84+ if err != nil {
85+ return nil , fmt .Errorf ("failed to copy CLI script to container: %w" , err )
86+ }
14187
142- // Execute the script
143- code , out , err := c .Exec (ctx , []string {"/usr/sw/loads/currentload/bin/cli" , "-A" , "-es" , "script.cli" })
144- output := ""
145- if out != nil {
146- bytes , readErr := io .ReadAll (out )
147- if readErr == nil {
148- output = string (bytes )
149- } else {
150- output = fmt .Sprintf ("[ERROR reading CLI output: %v]" , readErr )
151- }
152- }
153- if err != nil {
154- return nil , fmt .Errorf ("failed to execute CLI script for queue/topic setup: %w" , err )
155- }
156- if code != 0 {
157- return nil , fmt .Errorf ("CLI script execution failed with exit code %d: %s" , code , output )
88+ // Execute the script
89+ code , out , err := c .Exec (ctx , []string {"/usr/sw/loads/currentload/bin/cli" , "-A" , "-es" , "script.cli" })
90+ output := ""
91+ if out != nil {
92+ bytes , readErr := io .ReadAll (out )
93+ if readErr == nil {
94+ output = string (bytes )
95+ } else {
96+ output = fmt .Sprintf ("[ERROR reading CLI output: %v]" , readErr )
15897 }
15998 }
99+ if err != nil {
100+ return nil , fmt .Errorf ("failed to execute CLI script for queue/topic setup: %w" , err )
101+ }
102+ if code != 0 {
103+ return nil , fmt .Errorf ("CLI script execution failed with exit code %d: %s" , code , output )
104+ }
160105
161106 return c , nil
162107}
0 commit comments