Skip to content

Commit

Permalink
Default to package.name, but allow overrides, add example docs for sp…
Browse files Browse the repository at this point in the history
…ecifying which package, and version to test.

Signed-off-by: Ville Aikas <[email protected]>
  • Loading branch information
vaikas committed Dec 1, 2023
1 parent ad516f1 commit dab89e8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
30 changes: 30 additions & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,36 @@ step by using `uses:` instead of `runs:`. You can specify the location of the
predefined pipelines using the `--pipeline-dir` to point to the directory where
the custom pipelines are located.

## Specifying package to test / reusing tests

You can leave out the package name from the command line if you want, in which
case the PUT is pulled from the package.Name. However, for versioned packages,
say for example, php-8.1, php-8.2, php-8.3, it is beneficial to reuse some of
the tests. In those cases, you can specify the testfile and also which package
to use for testing by providing a second argument to the `test` command that is
the name of the package used for the tests.

Lastly, if you want to test a specific version of the package, you can specify
the constraint in the argument. For example:

* Use package.Name

```shell
melange test ./testfile.yaml
```

* Use above testfile, but a different package to run tests against

```shell
melange test ./testfile.yaml mypackage
```

* Use above testfile, but specify a particular version of the package

```shell
melange test ./testfile.yaml mypackage=2.2.0-r2
```

## Full example

Here's a full example invocation, where I'm testing with my local mac, so just
Expand Down
2 changes: 1 addition & 1 deletion docs/md/melange_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ melange test [flags]
### Examples

```
melange test <test.yaml> <package-name>
melange test <test.yaml> [package-name]
```

### Options
Expand Down
9 changes: 7 additions & 2 deletions pkg/build/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,13 @@ func (t *Test) TestPackage(ctx context.Context) error {
}

t.Logger.Printf("evaluating main pipeline for package requirements")
// Append the main test package to be installed.
t.Configuration.Test.Environment.Contents.Packages = append(t.Configuration.Test.Environment.Contents.Packages, pkg.Name)
// Append the main test package to be installed unless explicitly specified
// by the command line.
if t.Package != "" {
t.Configuration.Test.Environment.Contents.Packages = append(t.Configuration.Test.Environment.Contents.Packages, t.Package)
} else {
t.Configuration.Test.Environment.Contents.Packages = append(t.Configuration.Test.Environment.Contents.Packages, pkg.Name)
}
for i := range t.Configuration.Test.Pipeline {
p := &t.Configuration.Test.Pipeline[i]
// fine to pass nil for config, since not running in container.
Expand Down
6 changes: 4 additions & 2 deletions pkg/cli/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func Test() *cobra.Command {
Use: "test",
Short: "Test a package with a YAML configuration file",
Long: `Test a package from a YAML configuration file containing a test pipeline.`,
Example: ` melange test <test.yaml> <package-name>`,
Args: cobra.MinimumNArgs(2),
Example: ` melange test <test.yaml> [package-name]`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
archs := apko_types.ParseArchitectures(archstrs)
options := []build.TestOption{
Expand All @@ -69,6 +69,8 @@ func Test() *cobra.Command {

if len(args) > 0 {
options = append(options, build.WithTestConfig(args[0]))
}
if len(args) > 1 {
options = append(options, build.WithTestPackage(args[1]))
}

Expand Down

0 comments on commit dab89e8

Please sign in to comment.