@@ -20,7 +20,6 @@ import (
2020
2121 "github.com/juju/cmd/v4"
2222 "github.com/juju/cmd/v4/cmdtesting"
23- "github.com/juju/names/v5"
2423 jc "github.com/juju/testing/checkers"
2524 gc "gopkg.in/check.v1"
2625
@@ -53,11 +52,7 @@ func (*IntrospectCommandSuite) assertInitError(c *gc.C, expect string, args ...s
5352}
5453
5554func (* IntrospectCommandSuite ) run (c * gc.C , args ... string ) (* cmd.Context , error ) {
56- return cmdtesting .RunCommand (c , & introspect.IntrospectCommand {
57- IntrospectionSocketName : func (tag names.Tag ) string {
58- return filepath .Join (config .DataDir , "jujud-" + tag .String ())
59- },
60- }, args ... )
55+ return cmdtesting .RunCommand (c , & introspect.IntrospectCommand {}, args ... )
6156}
6257
6358func (s * IntrospectCommandSuite ) TestAutoDetectMachineAgent (c * gc.C ) {
@@ -66,7 +61,7 @@ func (s *IntrospectCommandSuite) TestAutoDetectMachineAgent(c *gc.C) {
6661 c .Assert (err , jc .ErrorIsNil )
6762
6863 _ , err = s .run (c , "query" )
69- c .Assert (err , gc .ErrorMatches , ".*jujud- machine-1024.*" )
64+ c .Assert (err , gc .ErrorMatches , ".*machine-1024.*" )
7065}
7166
7267func (s * IntrospectCommandSuite ) TestAutoDetectMachineAgentFails (c * gc.C ) {
@@ -80,11 +75,14 @@ func (s *IntrospectCommandSuite) TestAutoDetectMachineAgentFails(c *gc.C) {
8075
8176func (s * IntrospectCommandSuite ) TestAgentSpecified (c * gc.C ) {
8277 _ , err := s .run (c , "query" , "--agent=unit-foo-0" )
83- c .Assert (err , gc .ErrorMatches , ".*jujud- unit-foo-0.*" )
78+ c .Assert (err , gc .ErrorMatches , ".*unit-foo-0.*" )
8479}
8580
8681func (s * IntrospectCommandSuite ) TestQuery (c * gc.C ) {
87- listener , err := net .Listen ("unix" , "@" + filepath .Join (config .DataDir , "jujud-machine-0" ))
82+ agentDir := filepath .Join (config .DataDir , "agents" , "machine-0" )
83+ err := os .MkdirAll (agentDir , 0755 )
84+ c .Assert (err , jc .ErrorIsNil )
85+ listener , err := net .Listen ("unix" , filepath .Join (agentDir , "introspection.socket" ))
8886 c .Assert (err , jc .ErrorIsNil )
8987 defer listener .Close ()
9088
@@ -98,7 +96,10 @@ func (s *IntrospectCommandSuite) TestQuery(c *gc.C) {
9896}
9997
10098func (s * IntrospectCommandSuite ) TestQueryFails (c * gc.C ) {
101- listener , err := net .Listen ("unix" , "@" + filepath .Join (config .DataDir , "jujud-machine-0" ))
99+ agentDir := filepath .Join (config .DataDir , "agents" , "machine-0" )
100+ err := os .MkdirAll (agentDir , 0755 )
101+ c .Assert (err , jc .ErrorIsNil )
102+ listener , err := net .Listen ("unix" , filepath .Join (agentDir , "introspection.socket" ))
102103 c .Assert (err , jc .ErrorIsNil )
103104 defer listener .Close ()
104105
@@ -118,7 +119,10 @@ func (s *IntrospectCommandSuite) TestQueryFails(c *gc.C) {
118119}
119120
120121func (s * IntrospectCommandSuite ) TestGetToPostEndpoint (c * gc.C ) {
121- listener , err := net .Listen ("unix" , "@" + filepath .Join (config .DataDir , "jujud-machine-0" ))
122+ agentDir := filepath .Join (config .DataDir , "agents" , "machine-0" )
123+ err := os .MkdirAll (agentDir , 0755 )
124+ c .Assert (err , jc .ErrorIsNil )
125+ listener , err := net .Listen ("unix" , filepath .Join (agentDir , "introspection.socket" ))
122126 c .Assert (err , jc .ErrorIsNil )
123127 defer listener .Close ()
124128
@@ -133,7 +137,10 @@ func (s *IntrospectCommandSuite) TestGetToPostEndpoint(c *gc.C) {
133137}
134138
135139func (s * IntrospectCommandSuite ) TestPost (c * gc.C ) {
136- listener , err := net .Listen ("unix" , "@" + filepath .Join (config .DataDir , "jujud-machine-0" ))
140+ agentDir := filepath .Join (config .DataDir , "agents" , "machine-0" )
141+ err := os .MkdirAll (agentDir , 0755 )
142+ c .Assert (err , jc .ErrorIsNil )
143+ listener , err := net .Listen ("unix" , filepath .Join (agentDir , "introspection.socket" ))
137144 c .Assert (err , jc .ErrorIsNil )
138145 defer listener .Close ()
139146
@@ -151,8 +158,11 @@ single="value"
151158}
152159
153160func (s * IntrospectCommandSuite ) TestListen (c * gc.C ) {
154- socketName := filepath .Join (config .DataDir , "jujud-machine-0" )
155- listener , err := net .Listen ("unix" , "@" + socketName )
161+ agentDir := filepath .Join (config .DataDir , "agents" , "machine-0" )
162+ err := os .MkdirAll (agentDir , 0755 )
163+ c .Assert (err , jc .ErrorIsNil )
164+ socketName := filepath .Join (agentDir , "introspection.socket" )
165+ listener , err := net .Listen ("unix" , socketName )
156166 c .Assert (err , jc .ErrorIsNil )
157167 defer listener .Close ()
158168
@@ -162,7 +172,7 @@ func (s *IntrospectCommandSuite) TestListen(c *gc.C) {
162172
163173 ctx , cancel := context .WithCancel (context .Background ())
164174 defer cancel ()
165- cmd := exec .CommandContext (ctx , os .Args [0 ], "-run-listen=" + socketName )
175+ cmd := exec .CommandContext (ctx , os .Args [0 ], "-run-listen=" + config . DataDir )
166176 stderr , err := cmd .StderrPipe ()
167177 c .Assert (err , jc .ErrorIsNil )
168178 defer stderr .Close ()
@@ -172,7 +182,7 @@ func (s *IntrospectCommandSuite) TestListen(c *gc.C) {
172182 scanner := bufio .NewScanner (stderr )
173183 c .Assert (scanner .Scan (), jc .IsTrue )
174184 line := scanner .Text ()
175- c .Assert (line , gc .Matches , "Exposing @ .* introspection socket on 127.0.0.1:.*" )
185+ c .Assert (line , gc .Matches , "Exposing .* introspection socket on 127.0.0.1:.*" )
176186
177187 fields := strings .Fields (line )
178188 addr := fields [len (fields )- 1 ]
@@ -217,16 +227,12 @@ func newServer(l net.Listener) *http.Server {
217227 return srv
218228}
219229
220- var flagListen = flag .String ("run-listen" , "" , "Name of the Unix socket to connect the introspect command to using --listen=:0" )
230+ var flagListen = flag .String ("run-listen" , "" , "DataDir of the Unix socket to connect the introspect command to using --listen=:0" )
221231
222232func TestRunListen (t * stdtesting.T ) {
223233 if * flagListen != "" {
224- introspectCommand := & introspect.IntrospectCommand {
225- IntrospectionSocketName : func (names.Tag ) string {
226- return * flagListen
227- },
228- }
229- args := append (flag .Args (), "--listen=127.0.0.1:0" , "--agent=machine-0" )
234+ introspectCommand := & introspect.IntrospectCommand {}
235+ args := append (flag .Args (), "--data-dir=" + * flagListen , "--listen=127.0.0.1:0" , "--agent=machine-0" )
230236 if err := cmdtesting .InitCommand (introspectCommand , args ); err != nil {
231237 t .Fatal (err )
232238 }
0 commit comments