Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .claude/skills/reportportal/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ counted once (a test with subtests is not counted itself). `t.Skip` tests are `S
"To Investigate" unless `--skipped-issue=false`. The launch gets the system attributes `agent`, `os`, `go`
and `skippedIssue`. With `--print-launch-uuid` the launch link is printed as well (`ReportPortal Launch: <url>`).

### Parameters

A subtest named `key=value` gets the pair as a test item parameter (`size=64`; several pairs separated by `/` or
`,`), plus the parameters of the subtests it is nested in. Keys are letters, digits, `.` and `-` (no `_`: Go
turns spaces into underscores, so `fails_when_n=1` is a sentence); a value must be non-empty and without `=`.
`testCaseId`, `uniqueId` and `codeRef` stay the full test name.

### Repeated runs (retries)

With `go test -count=N` or `gotestsum --rerun-fails --jsonfile` a test runs several times in one stream. Each
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ A Go CLI tool (`gorp`) and library (`pkg/gorp`) for [ReportPortal](https://repor
| `report.go` | `report test2json` command: flags, input scanning, feeding events to the reporter |
| `reporter.go` | `reporter`/`testEvent` types: test2json events → launch, `SUITE` per package, `STEP` per test, subtests nested under their parent |
| `report_steps.go` | Atomic report commands: `start-launch`, `start-test`, `log`, `finish-test`, `finish-launch` |
| `report_parameters.go` | `subtestParameters`: `key=value` subtest names → test item parameters for `report test2json` |
| `quality_gate.go` | `quality-gate check` (polls launch metadata until QG resolves) |
| `util.go` | Shared CLI helpers (config file path, validation, stdin checks) |

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ The launch finishes as `FAILED` if any test or package failed, otherwise `PASSED
(Ctrl-C, `SIGTERM`) or the input stream breaks midway, items that are still running are finished as `INTERRUPTED`,
followed by the launch, so nothing is left `IN_PROGRESS`. A second Ctrl-C terminates immediately.

**Parameters.** A subtest whose name is `key=value` (the naming convention of Go's table tests and benchmarks)
gets that pair as a ReportPortal parameter: `t.Run("size=64", …)` → `size=64`. Several pairs in one name can be
separated by `/` or `,` (`size=64/align=8`, `tls=true,http2=false`), and a subtest also gets the parameters of the
subtests it is nested in. Only names that consist of such pairs count: `fails_when_n=1` (a sentence; Go turns
spaces into underscores, so keys with `_` are not accepted), `expr=a=b` or `k=` give no parameter. The test case
ID is not affected: it stays the full test name.

**Build failures.** A package that does not compile (or fails `go vet`) runs no test. With Go 1.24 or later,
`go test -json` puts the compiler output into the stream; the package is then reported as a `FAILED` suite with
that output as one `ERROR` log, and the launch is `FAILED`. A broken dependency fails every package that imports
Expand Down
17 changes: 11 additions & 6 deletions e2e/e2e_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ import (
// its response is not decodable.
type (
testItem struct {
ID int64 `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Status string `json:"status"`
CodeRef string `json:"codeRef"`
Parent int64 `json:"parent"`
ID int64 `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Status string `json:"status"`
CodeRef string `json:"codeRef"`
Parent int64 `json:"parent"`
TestCaseID string `json:"testCaseId"`
Parameters []struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"parameters"`
// Retries are the earlier runs of the item; they are not listed as items themselves
Retries []struct {
ID int64 `json:"id"`
Expand Down
62 changes: 62 additions & 0 deletions e2e/parameters_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//go:build e2e

package e2e

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// Subtests named "key=value" get parameters; the test case ID stays the full test name. The stream is
// real `go test -json` output, see internal/commands/report_parameters_test.go.
func TestReportTest2JSON_SubtestParameters(t *testing.T) {
e := newEnv(t)
name := uniqueName(t)
input := filepath.Join("..", "internal", "commands", "testdata", "params", "params.jsonl")

runGorp(t, "report", "test2json", "--file", input, "--launchName", name).requireOK(t)

launch := e.findLaunch(t, name, finished)
items := e.items(t, launch.Id, 17) // the suite, TestParams and its 15 subtests
params := func(item string) []string {
require.NotNil(t, items[item], item)
got := []string{}
for _, p := range items[item].Parameters {
got = append(got, p.Key+"="+p.Value)
}

return got
}

assert.Equal(t, []string{"n=2"}, params("n=2"))
assert.Equal(
t,
[]string{"n=1"},
params("n=1#01"),
"the suffix of a repeated name is not a value",
)
// the server does not keep the order of the parameters
assert.ElementsMatch(t, []string{"tableSize=8", "elems=4"}, params("tableSize=8/elems=4"))
assert.ElementsMatch(
t,
[]string{"cache=ram", "pages=16"},
params("pages=16"),
"with the parent's parameter",
)
assert.ElementsMatch(t, []string{"cache=ram", "pages=16"}, params("plain"))
assert.ElementsMatch(
t,
[]string{"sameSubject=true", "sameKey=false"},
params("sameSubject=true,sameKey=false"),
)
assert.Empty(t, params("expr=a=b"))
assert.Empty(t, params("not_a_parameter"))
assert.Empty(t, params("TestParams"))

const test = "example.com/params/p/TestParams"
assert.Equal(t, test+"/n=2", items["n=2"].TestCaseID)
assert.Equal(t, test+"/cache=ram/pages=16", items["pages=16"].TestCaseID)
}
67 changes: 67 additions & 0 deletions internal/commands/report_parameters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package commands

import (
"regexp"
"strings"

"github.com/reportportal/goRP/v5/pkg/openapi"
)

// testParameter is the generated model of a test item parameter.
type testParameter = openapi.ComEpamReportportalBaseReportingParameterResource

var (
// parameterKey is the key of a "key=value" subtest name: letters and digits, with "." and "-"
// allowed inside ("keySize=128", "work-dur=1s", "http.version=2"). There is no "_" on purpose: the
// testing package turns the spaces of a subtest name into underscores, so "fails when n=1" arrives
// as "fails_when_n=1", which is a sentence and not a pair.
parameterKey = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9.-]*$`)
// duplicateSuffix is what the testing package appends to a subtest name that is used twice ("n=1#01").
duplicateSuffix = regexp.MustCompile(`#\d{2,}$`)
)

// subtestParameters derives test item parameters from the name of a subtest, relative to its parent.
//
// Go has no parameterized tests, but a convention for naming the cases of a table: "key=value", as in
// the standard library's own tests and in the benchmark format ("BenchmarkX/size=64/align=8"). Several
// pairs in one name are separated by "/" or ",". Only names that are nothing but such pairs give
// parameters:
//
// "n=1" n=1
// "n=1#01" n=1 (the suffix that makes a repeated name unique is dropped)
// "size=64/align=8" size=64, align=8
// "tls=true,http2=false" tls=true, http2=false
// "list=a,b,c" list="a,b,c" (the rest is not a pair, so it belongs to the value)
// "path=a/b" path="a/b"
// "expr=a=b", "k=", "=v" none: ambiguous or incomplete
// "fails_when_n=1" none: a sentence, see parameterKey
func subtestParameters(name string) []testParameter {
name = duplicateSuffix.ReplaceAllString(name, "")

pieces := strings.FieldsFunc(name, func(r rune) bool { return r == '/' || r == ',' })
params := make([]testParameter, 0, len(pieces))
for _, piece := range pieces {
param, ok := parseParameter(piece)
if !ok {
params = nil
break
}
params = append(params, param)
}
if len(params) > 0 {
return params
}
if param, ok := parseParameter(name); ok {
return []testParameter{param}
}
return nil
}

// parseParameter parses "key=value" with a key as in parameterKey and a non-empty value without "=".
func parseParameter(s string) (testParameter, bool) {
key, value, found := strings.Cut(s, "=")
if !found || value == "" || strings.Contains(value, "=") || !parameterKey.MatchString(key) {
return testParameter{}, false
}
return testParameter{Key: key, Value: openapi.PtrString(value)}, true
}
101 changes: 101 additions & 0 deletions internal/commands/report_parameters_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package commands

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSubtestParameters(t *testing.T) {
t.Parallel()

tests := map[string][]string{ // subtest name -> "key=value" of the expected parameters
"n=1": {"n=1"},
"n=1#01": {"n=1"},
"work-dur=1.5s": {"work-dur=1.5s"},
"Elem=*int32": {"Elem=*int32"},
"size=64/align=8": {"size=64", "align=8"},
"tls=true,http2=false": {"tls=true", "http2=false"},
"a=1/b=2,c=3": {"a=1", "b=2", "c=3"},
"name=two_words": {"name=two_words"},
"list=a,b,c": {"list=a,b,c"},
"path=a/b": {"path=a/b"},
"expr=a=b": nil,
"url=http://x/y?q=1": nil,
"empty=": nil,
"=novalue": nil,
"plain": nil,
"with_n=1_inside/plain": nil,
"case_1:_n=1": nil,
"fails_when_n=1": nil, // "fails when n=1": spaces arrive as underscores
"max_size=10": nil, // not told apart from a sentence
"x=5_works": {"x=5_works"},
"1st=x": nil,
"": nil,
"n=1/": {"n=1"},
"SetZero/string/size=16": nil,
}
for name, want := range tests {
var got []string
for _, p := range subtestParameters(name) {
got = append(got, p.Key+"="+p.GetValue())
}
assert.Equal(t, want, got, "subtest %q", name)
}
}

// testdata/params/params.jsonl is unedited `go test -json` output (go1.27.4) of a test whose subtests
// are named after the conventions above; it shows what the testing package does to such names.
func TestReportLaunch_SubtestParameters(t *testing.T) {
t.Parallel()

rec, srv := newHierarchyServer(t, "proj")
cfg := &clientConfig{URL: srv.URL, Project: "proj", ApiKey: "tok"}
file := filepath.Join("testdata", "params", "params.jsonl")
_, _, err := reportLaunch(t.Context(), cfg, reportCmd(file, "launch", false))
require.NoError(t, err)

const test = "example.com/params/p/TestParams"
want := map[string][]string{ // code reference -> parameters
test: nil,
test + "/n=1": {"n=1"},
test + "/n=1#01": {"n=1"},
test + "/n=2": {"n=2"},
test + "/tableSize=8/elems=4": {"tableSize=8", "elems=4"},
test + "/cache=ram": {"cache=ram"},
// subtests run with the parameters of their parents
test + "/cache=ram/pages=16": {"cache=ram", "pages=16"},
test + "/cache=ram/pages=16/plain": {"cache=ram", "pages=16"},
test + "/sameSubject=true,sameKey=false": {"sameSubject=true", "sameKey=false"},
test + "/name=two_words": {"name=two_words"},
test + "/list=a,b,c": {"list=a,b,c"},
test + "/expr=a=b": nil,
test + "/empty=": nil,
test + "/=novalue": nil,
test + "/not_a_parameter": nil,
test + "/url=http://x/y?q=1": nil,
}
for codeRef, wantParams := range want {
runs := rec.runs(codeRef)
require.Len(t, runs, 1, codeRef)
body := runs[0].Body
assert.Equal(
t,
codeRef,
body["testCaseId"],
"the test case ID is the full name, with or without parameters",
)

var got []string
params, _ := body["parameters"].([]any)
for _, p := range params {
param, ok := p.(map[string]any)
require.True(t, ok)
got = append(got, param["key"].(string)+"="+param["value"].(string))
}
assert.Equal(t, wantParams, got, codeRef)
}
assert.Len(t, rec.items, len(want)+1, "the tests and the suite")
}
12 changes: 12 additions & 0 deletions internal/commands/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ type reporter struct {
joined *gorppkg.LaunchInfo
// started is set once the first event has been seen
started bool
// parameters are the parameters of the started tests: those of their own name ("size=64") and
// those of the tests they are subtests of
parameters map[string][]testParameter
// retries reports a test that runs again as a retry of its previous run, see startTest
retries bool
// containers are the tests that had subtests in one of their runs
Expand Down Expand Up @@ -181,6 +184,7 @@ func newReporter(
buildOutput: map[string][]string{},
retries: opts.retries,
containers: map[string]bool{},
parameters: map[string][]testParameter{},
failedTests: map[testKey]bool{},
failedPackages: map[string]bool{},
logs: []*openapi.SaveLogRQ{},
Expand Down Expand Up @@ -456,6 +460,13 @@ func (r *reporter) startTest(ev *testEvent) error {
} else {
r.containers[parentTest] = true
}
// A subtest named "key=value" is a case of a table test: the pair is reported as a parameter. A
// subtest runs with the parameters of its parents too. The test case ID stays the full name.
parameters := slices.Concat(r.parameters[parentTest], subtestParameters(name))
if parentTest == "" {
parameters = nil // the name of a top-level test is a function name
}
r.parameters[testID] = parameters
rq := &openapi.StartTestItemRQ{
Name: name,
StartTime: ev.Time,
Expand All @@ -466,6 +477,7 @@ func (r *reporter) startTest(ev *testEvent) error {
TestCaseId: openapi.PtrString(testID),
Type: string(gorppkg.TestItemTypes.Step),
Retry: openapi.PtrBool(false),
Parameters: parameters,
}
// a previous run that is still open is not a previous run: the name is not unique in the stream
if previous, seen := r.tests[testID]; seen && r.retries &&
Expand Down
Loading