Skip to content

Commit 3940529

Browse files
authored
conformance: support OCI_REPORT_DIR (#473)
This makes it possible to run the conformance tests in a read-only directory without failing by specifying an output directory for the report files instead of hard-coding it to the current directory (which may not be writable, and _won't_ be writable if the tests are being run with `go test github.com/opencontainers/distribution-spec/conformance` rather than in a git checkout of the conformance module. We recognize the value `none` for disabling report generation entirely. Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
1 parent 3f68583 commit 3940529

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

conformance/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ Lastly, run the tests:
3939
./conformance.test
4040
```
4141

42-
This will produce `junit.xml` and `report.html` with the results.
43-
4442
Note: for some registries, you may need to create `OCI_NAMESPACE` ahead of time.
4543

44+
This will produce `junit.xml` and `report.html` in the current directory with the results. To choose an alternative directory:
45+
46+
```
47+
export OCI_REPORT_DIR=/alternative/directory
48+
```
49+
50+
To disable writing of the result files:
51+
52+
```
53+
export OCI_REPORT_DIR=none
54+
```
55+
4656
#### Testing registry workflows
4757

4858
The tests are broken down into 4 major categories:
@@ -230,7 +240,7 @@ jobs:
230240
- name: Run OCI Distribution Spec conformance tests
231241
uses: opencontainers/distribution-spec@main
232242
# you can also run against a specific tag or commit instead
233-
# uses: opencontainers/distribution-spec@v1.1.0
243+
# uses: opencontainers/distribution-spec@v1.1.0
234244
env:
235245
OCI_ROOT_URL: https://myreg.io
236246
OCI_NAMESPACE: mytestorg/mytestrepo

conformance/reporter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,10 @@ func (reporter *HTMLReporter) afterReport(r types.SpecReport) {
568568
}
569569

570570
func (reporter *HTMLReporter) endSuite(report types.Report) error {
571+
if reporter.htmlReportFilename == "" {
572+
// Reporting is disabled.
573+
return nil
574+
}
571575
reporter.Report = report
572576
reporter.endTime = time.Now()
573577
reporter.EndTimeString = reporter.endTime.Format("Jan 2 15:04:05.000 -0700 MST")

conformance/setup.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"math/big"
1111
mathrand "math/rand"
1212
"os"
13+
"path/filepath"
1314
"runtime"
1415
"strconv"
1516

@@ -75,6 +76,7 @@ const (
7576
envVarDeleteManifestBeforeBlobs = "OCI_DELETE_MANIFEST_BEFORE_BLOBS"
7677
envVarCrossmountNamespace = "OCI_CROSSMOUNT_NAMESPACE"
7778
envVarAutomaticCrossmount = "OCI_AUTOMATIC_CROSSMOUNT"
79+
envVarReportDir = "OCI_REPORT_DIR"
7880

7981
emptyLayerTestTag = "emptylayer"
8082
testTagName = "tagtest0"
@@ -510,8 +512,10 @@ func init() {
510512
automaticCrossmountVal, runAutomaticCrossmountTest = os.LookupEnv(envVarAutomaticCrossmount)
511513
automaticCrossmountEnabled, _ = strconv.ParseBool(automaticCrossmountVal)
512514

513-
reportJUnitFilename = "junit.xml"
514-
reportHTMLFilename = "report.html"
515+
if dir := os.Getenv(envVarReportDir); dir != "none" {
516+
reportJUnitFilename = filepath.Join(dir, "junit.xml")
517+
reportHTMLFilename = filepath.Join(dir, "report.html")
518+
}
515519
suiteDescription = "OCI Distribution Conformance Tests"
516520
}
517521

0 commit comments

Comments
 (0)