@@ -31,12 +31,13 @@ type PhpPackagesCollection struct {
31
31
// PHP packages config describes how to collect the JSON for the packages installed
32
32
// for the current test case
33
33
type PhpPackagesConfiguration struct {
34
- path string
35
- command string
36
- supportedListFile string
37
- overrideVersionsFile string
38
- expectedPackages []string
39
- packageNameOnly []string
34
+ path string //
35
+ command string // command to run to detect packages
36
+ supportedListFile string // JSON file containing list of packages we expect agent to detect
37
+ overrideVersionsFile string // JSON file containing overrides for expected package versions
38
+ expectedPackages []string // manual override of packages we expect to detect
39
+ packageNameOnly []string // list of packages which only have a name because agent cannot determine the version
40
+ expectAllDetected bool // flag to indicate we expect all packages detected by the command "command"
40
41
}
41
42
42
43
// composer package JSON
@@ -159,16 +160,22 @@ func NewPhpPackagesCollection(path string, config []byte) (*PhpPackagesCollectio
159
160
}
160
161
}
161
162
162
- if supportedOK && expectedOK {
163
- return nil , fmt .Errorf ("Improper EXPECT_PHP_PACKAGES config - cannot specify 'supported_packages' and 'expected packages' - got %+v" , params )
163
+ // or "expect_all" which means we expect the agent to detect all the packages that the "command" option would detect
164
+ _ , expectAllOK := params ["expect_all" ]
165
+
166
+ if (supportedOK && expectedOK ) || (supportedOK && expectAllOK ) || (expectedOK && expectAllOK ) {
167
+ return nil , fmt .Errorf ("Improper EXPECT_PHP_PACKAGES config - must specify one of 'supported_packages', " +
168
+ "'expected packages' or 'expect_all' - got %+v" , params )
164
169
}
165
170
166
- if ! supportedOK && ! expectedOK {
167
- return nil , fmt .Errorf ("Improper EXPECT_PHP_PACKAGES config - must specify 'supported_packages' or 'expected packages' - got %+v" , params )
171
+ if ! supportedOK && ! expectedOK && ! expectAllOK {
172
+ return nil , fmt .Errorf ("Improper EXPECT_PHP_PACKAGES config - must specify 'supported_packages' or 'expected packages' " +
173
+ "or 'expect_all' - got %+v" , params )
168
174
}
169
175
170
- if supportedOK && ! commandOK {
171
- return nil , fmt .Errorf ("Improper EXPECT_PHP_PACKAGES config - must specify 'command' option with `supported_packages` - got %+v" , params )
176
+ if (supportedOK || expectAllOK ) && ! commandOK {
177
+ return nil , fmt .Errorf ("Improper EXPECT_PHP_PACKAGES config - must specify 'command' option with `supported_packages` / " +
178
+ "'expect_all' - got %+v" , params )
172
179
}
173
180
174
181
// optional option to specify which packages will only have a name because agent cannot determine the version
@@ -209,7 +216,8 @@ func NewPhpPackagesCollection(path string, config []byte) (*PhpPackagesCollectio
209
216
supportedListFile : supportedListFile ,
210
217
overrideVersionsFile : overrideVersionsFile ,
211
218
expectedPackages : expectedPackagesArr ,
212
- packageNameOnly : packageNameOnlyArr },
219
+ packageNameOnly : packageNameOnlyArr ,
220
+ expectAllDetected : expectAllOK },
213
221
}
214
222
215
223
return p , nil
@@ -296,18 +304,27 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
296
304
var supported []string
297
305
298
306
// get list of packages we expected the agent to detect
299
- // this can be one of 2 scenarios:
307
+ // this can be one of 3 scenarios:
300
308
// 1) test case used the "supported_packages" option which gives a JSON file which
301
309
// lists all the packages the agent can detect
302
310
// 2) test case used the "expected_packages" options which provides a comma separated
303
311
// list of packages we expect the agent to detect
312
+ // 3) test case used the "expect_all" option which means we expect the agent to
313
+ // detect all the packages that the "command" option would detect
314
+ //
315
+ // Options #1 and #2 are mutually exclusive, and are intended for testing the legacy VM detection
316
+ // mechanism where the agent looks for "magic" files of a package and examinew internals of the
317
+ // package to determine its version.
304
318
//
305
- // Option #1 is preferable as it provides the most comprehensive view of what the agent can do.
319
+ // Option #1 is preferable when it available as it provides the most comprehensive view of what the agent can do.
306
320
//
307
321
// Option #2 is needed because some test cases do not exercise all the packages which are
308
322
// installed and so the agent will not detect everything for that test case run which it could
309
323
// theorectically detect if the test case used all the available packages installed.
310
324
//
325
+ // Option #3 is used when testing the agent's ability to detect packages using the Composer API. In
326
+ // this case we expect the agent to detect the exact same packages as composer would detect.
327
+ //
311
328
// Once the list of packages the agent is expected to detect is created it is used to filter
312
329
// down the package list returned by running the "command" (usually composer) option for the
313
330
// test case provided.
@@ -318,8 +335,9 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
318
335
}
319
336
} else if 0 < len (pkgs .config .expectedPackages ) {
320
337
supported = pkgs .config .expectedPackages
321
- } else {
322
- return nil , fmt .Errorf ("Error determining expected packages - supported_packages and expected_packages are both empty" )
338
+ } else if ! pkgs .config .expectAllDetected {
339
+ return nil , fmt .Errorf ("Error determining expected packages - supported_packages and expected_packages are both empty " +
340
+ "and expect_all is false" )
323
341
}
324
342
325
343
splitCmd := strings .Split (pkgs .config .command , " " )
@@ -338,8 +356,8 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
338
356
detected := ComposerJSON {}
339
357
json .Unmarshal ([]byte (out ), & detected )
340
358
for _ , v := range detected .Installed {
341
- // fmt.Printf("composer detected %s %s\n", v.Name, v.Version)
342
- if StringSliceContains (supported , v .Name ) {
359
+ fmt .Printf ("composer detected %s %s\n " , v .Name , v .Version )
360
+ if pkgs . config . expectAllDetected || StringSliceContains (supported , v .Name ) {
343
361
var version string
344
362
345
363
// remove any 'v' from front of version string
@@ -349,9 +367,9 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
349
367
version = v .Version
350
368
}
351
369
pkgs .packages = append (pkgs .packages , PhpPackage {v .Name , version })
352
- // fmt.Printf(" -> %s in supported!\n", v.Name)
370
+ fmt .Printf (" -> %s in supported!\n " , v .Name )
353
371
} else {
354
- // fmt.Printf(" -> %s NOT in supported!\n", v.Name)
372
+ fmt .Printf (" -> %s NOT in supported!\n " , v .Name )
355
373
}
356
374
}
357
375
} else if 1 < len (splitCmd ) && "wp-cli.phar" == splitCmd [1 ] {
0 commit comments