Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 1664219

Browse files
authored
[minor QOL] Unify testname throughout unit tests (#1379)
I think e.g. `test_name(32)` is a nice format. Also we start having a standard, so we can change it everywhere if we agree on something else. With this one I can quickly ctrl-f for `[32]` in most of tests in `testdata`, and I find it pretty convenient for debugging.
1 parent 8c8db15 commit 1664219

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+205
-168
lines changed

platform/clickhouse/clickhouse_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ func TestLogManager_GetTable(t *testing.T) {
692692
found: false,
693693
},
694694
}
695-
for _, tt := range tests {
696-
t.Run(tt.name, func(t *testing.T) {
695+
for i, tt := range tests {
696+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
697697
var tableDefinitions = atomic.Pointer[TableMap]{}
698698
tableDefinitions.Store(&tt.predefinedTables)
699699
lm := NewLogManager(&tt.predefinedTables, &config.QuesmaConfiguration{})
@@ -770,8 +770,8 @@ func TestLogManager_ResolveIndexes(t *testing.T) {
770770
resolved: []string{"table2"},
771771
},
772772
}
773-
for _, tt := range tests {
774-
t.Run(tt.name, func(t *testing.T) {
773+
for i, tt := range tests {
774+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
775775
var tableDefinitions = atomic.Pointer[TableMap]{}
776776
schemaTables := make(map[schema2.IndexName]schema2.Schema)
777777

platform/clickhouse/table_discovery_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package clickhouse
44

55
import (
6+
"github.com/QuesmaOrg/quesma/platform/util"
67
"github.com/stretchr/testify/assert"
78
"reflect"
89
"testing"
@@ -143,8 +144,8 @@ func Test_resolveColumn(t *testing.T) {
143144
},
144145
}
145146

146-
for _, tt := range tests {
147-
t.Run(tt.name, func(t *testing.T) {
147+
for i, tt := range tests {
148+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
148149
assert.Equalf(t, tt.want, resolveColumn(tt.args.colName, tt.args.colType), "resolveColumn(%v, %v)", tt.args.colName, tt.args.colType)
149150
})
150151
}
@@ -297,8 +298,8 @@ func Test_resolveColumn_Nullable(t *testing.T) {
297298
},
298299
}
299300

300-
for _, tt := range tests {
301-
t.Run(tt.name, func(t *testing.T) {
301+
for i, tt := range tests {
302+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
302303
assert.Equalf(t, tt.want, resolveColumn(tt.args.colName, tt.args.colType), "resolveColumn(%v, %v)", tt.args.colName, tt.args.colType)
303304
})
304305
}
@@ -323,8 +324,8 @@ func TestExtractMapValueType(t *testing.T) {
323324
{"Map(String, Map(String, Int32))", "Map(String, Int32)", false}, // Nested map
324325
}
325326

326-
for _, test := range tests {
327-
t.Run(test.input, func(t *testing.T) {
327+
for i, test := range tests {
328+
t.Run(util.PrettyTestName(test.input, i), func(t *testing.T) {
328329
result, err := extractMapValueType(test.input)
329330
if (err != nil) != test.hasError {
330331
t.Errorf("unexpected error state for input %q: got error %v", test.input, err)

platform/comment_metadata/comment_metadata_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package comment_metadata
44

55
import (
6+
"github.com/QuesmaOrg/quesma/platform/util"
67
"github.com/stretchr/testify/assert"
78
"testing"
89
)
@@ -30,8 +31,8 @@ func TestCommentMetadata_Marshall(t *testing.T) {
3031
},
3132
}
3233

33-
for _, tt := range tests {
34-
t.Run(tt.name, func(t *testing.T) {
34+
for i, tt := range tests {
35+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
3536
cm := NewCommentMetadata()
3637
cm.Values = tt.input
3738

@@ -90,8 +91,8 @@ func TestUnmarshallCommentMetadata(t *testing.T) {
9091
},
9192
}
9293

93-
for _, tt := range tests {
94-
t.Run(tt.name, func(t *testing.T) {
94+
for i, tt := range tests {
95+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
9596
cm, err := UnmarshallCommentMetadata(tt.input)
9697

9798
if tt.fail {

platform/config/config_v2_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package config
44

55
import (
66
"fmt"
7+
"github.com/QuesmaOrg/quesma/platform/util"
78
"github.com/stretchr/testify/assert"
89
"os"
910
"strings"
@@ -61,8 +62,8 @@ func TestQuesmaConfigurationLoading(t *testing.T) {
6162
{"example-elastic-index", []string{ElasticsearchTarget}, []string{ElasticsearchTarget}},
6263
}
6364

64-
for _, tt := range tests {
65-
t.Run(tt.name, func(t *testing.T) {
65+
for i, tt := range tests {
66+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
6667
ic := findIndexConfig(tt.name)
6768
assert.NotNil(t, ic)
6869
assert.Equal(t, tt.queryTarget, ic.QueryTarget)
@@ -223,8 +224,8 @@ func TestMatchName(t *testing.T) {
223224
{args: args{"logs-custom-specific-123", "logs-custom-*"}, want: true},
224225
{args: args{"logs-custom-abc", "logs-custom-*"}, want: true},
225226
}
226-
for _, tt := range tests {
227-
t.Run(fmt.Sprintf("%s->%s[%v]", tt.args.indexName, tt.args.indexNamePattern, tt.want), func(t *testing.T) {
227+
for i, tt := range tests {
228+
t.Run(fmt.Sprintf("%s->%s[%v](%d)", tt.args.indexName, tt.args.indexNamePattern, tt.want, i), func(t *testing.T) {
228229
assert.Equalf(t, tt.want, MatchName(tt.args.indexNamePattern, tt.args.indexName), "matches(%v, %v)", tt.args.indexName, tt.args.indexNamePattern)
229230
})
230231
}

platform/elasticsearch/feature/not_supported_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package feature
55
import (
66
"context"
77
"github.com/QuesmaOrg/quesma/platform/config"
8+
"github.com/QuesmaOrg/quesma/platform/util"
89
"github.com/stretchr/testify/assert"
910
"testing"
1011
)
@@ -41,9 +42,9 @@ func TestNewUnsupportedFeature_index(t *testing.T) {
4142
return []string{}, nil
4243
}
4344

44-
for _, tt := range tests {
45+
for i, tt := range tests {
4546

46-
t.Run(tt.path, func(t *testing.T) {
47+
t.Run(util.PrettyTestName(tt.path, i), func(t *testing.T) {
4748
given := AnalyzeUnsupportedCalls(ctx, "GET", tt.path, tt.opaqueId, indexNameResolver)
4849
assert.Equal(t, tt.isLogged, given)
4950
})
@@ -64,8 +65,8 @@ func TestIndexRegexp(t *testing.T) {
6465
{"/traces-xx*,xx-*,traces-xx*,x-*,logs-xx*,xx-*/_search", "traces-xx*,xx-*,traces-xx*,x-*,logs-xx*,xx-*"},
6566
}
6667

67-
for _, tt := range tests {
68-
t.Run(tt.path, func(t *testing.T) {
68+
for i, tt := range tests {
69+
t.Run(util.PrettyTestName(tt.path, i), func(t *testing.T) {
6970
given := indexPathRegexp.FindStringSubmatch(tt.path)
7071
if len(given) > 1 {
7172
index := given[1]

platform/elasticsearch/index_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// SPDX-License-Identifier: Elastic-2.0
33
package elasticsearch
44

5-
import "testing"
5+
import (
6+
"github.com/QuesmaOrg/quesma/platform/util"
7+
"testing"
8+
)
69

710
func TestIsValidIndexName(t *testing.T) {
811

@@ -24,8 +27,8 @@ func TestIsValidIndexName(t *testing.T) {
2427
},
2528
}
2629

27-
for _, tt := range tests {
28-
t.Run(tt.name, func(t *testing.T) {
30+
for i, tt := range tests {
31+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
2932
if err := IsValidIndexName(tt.name); (err != nil) != tt.wantErr {
3033
t.Errorf("IsValidIndexName() error = %v, wantErr %v", err, tt.wantErr)
3134
}

platform/elasticsearch/requests_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
package elasticsearch
44

55
import (
6+
"fmt"
7+
"github.com/QuesmaOrg/quesma/platform/util"
68
"net/http"
79
"net/url"
810
"testing"
@@ -20,8 +22,8 @@ func TestIsWriteRequest(t *testing.T) {
2022
{method: http.MethodPut, url: "/_create", want: true},
2123
{method: http.MethodPost, url: "/_search", want: false},
2224
}
23-
for _, tt := range tests {
24-
t.Run(tt.method+" "+tt.url, func(t *testing.T) {
25+
for i, tt := range tests {
26+
t.Run(util.PrettyTestName(fmt.Sprintf("%s %s", tt.method, tt.url), i), func(t *testing.T) {
2527
if got := IsWriteRequest(&http.Request{
2628
Method: tt.method,
2729
URL: &url.URL{Path: tt.url},

platform/frontend_connectors/matchers_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package frontend_connectors
44

55
import (
66
"github.com/QuesmaOrg/quesma/platform/types"
7+
"github.com/QuesmaOrg/quesma/platform/util"
78
mux "github.com/QuesmaOrg/quesma/platform/v2/core"
89
"github.com/stretchr/testify/assert"
910
"testing"
@@ -386,8 +387,8 @@ func TestMatchAgainstKibanaAlerts(t *testing.T) {
386387
{"migration", migrationQuery, false},
387388
}
388389

389-
for _, test := range tests {
390-
t.Run(test.name, func(tt *testing.T) {
390+
for i, test := range tests {
391+
t.Run(util.PrettyTestName(test.name, i), func(tt *testing.T) {
391392

392393
req := &mux.Request{Body: test.body}
393394

platform/frontend_connectors/router_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/QuesmaOrg/quesma/platform/telemetry"
2626
"github.com/QuesmaOrg/quesma/platform/types"
2727
"github.com/QuesmaOrg/quesma/platform/ui"
28+
"github.com/QuesmaOrg/quesma/platform/util"
2829
quesma_api "github.com/QuesmaOrg/quesma/platform/v2/core"
2930
"github.com/QuesmaOrg/quesma/platform/v2/core/routes"
3031
"github.com/QuesmaOrg/quesma/platform/v2/core/tracing"
@@ -518,8 +519,8 @@ func Test_matchedAgainstConfig(t *testing.T) {
518519

519520
resolver := table_resolver.NewEmptyTableResolver()
520521

521-
for _, tt := range tests {
522-
t.Run(tt.name, func(t *testing.T) {
522+
for i, tt := range tests {
523+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
523524

524525
req := &quesma_api.Request{Params: map[string]string{"index": tt.index}, Body: tt.body}
525526
res := matchedExactQueryPath(resolver).Matches(req)
@@ -658,8 +659,8 @@ func Test_matchedAgainstPattern(t *testing.T) {
658659

659660
resolver := table_resolver.NewEmptyTableResolver()
660661

661-
for _, tt := range tests {
662-
t.Run(tt.name, func(t *testing.T) {
662+
for i, tt := range tests {
663+
t.Run(util.PrettyTestName(tt.name, i), func(t *testing.T) {
663664

664665
req := &quesma_api.Request{Params: map[string]string{"index": tt.pattern}, Body: tt.body}
665666
assert.Equalf(t, tt.want, matchedAgainstPattern(resolver).Matches(req).Matched, "matchedAgainstPattern(%v)", tt.configuration)
@@ -753,10 +754,10 @@ func TestConfigureRouter(t *testing.T) {
753754
{routes.QuesmaTableResolverPath, "DELETE", false},
754755
}
755756

756-
for _, tt := range tests {
757+
for i, tt := range tests {
757758
tt.path = strings.Replace(tt.path, ":id", "quesma_async_absurd_test_id", -1)
758759
tt.path = strings.Replace(tt.path, ":index", testIndexName, -1)
759-
t.Run(tt.method+"-at-"+tt.path, func(t *testing.T) {
760+
t.Run(util.PrettyTestName(fmt.Sprintf("%s-at-%s", tt.method, tt.path), i), func(t *testing.T) {
760761
req := &quesma_api.Request{Path: tt.path, Method: tt.method}
761762
reqHandler, _ := testRouter.Matches(req)
762763
assert.Equal(t, tt.shouldReturnHandler, reqHandler != nil, "Expected route match result for path: %s and method: %s", tt.path, tt.method)

platform/frontend_connectors/schema_search_after_transformer_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/QuesmaOrg/quesma/platform/config"
99
"github.com/QuesmaOrg/quesma/platform/model"
1010
"github.com/QuesmaOrg/quesma/platform/schema"
11+
"github.com/QuesmaOrg/quesma/platform/util"
1112
"github.com/stretchr/testify/assert"
1213
"strconv"
1314
"testing"
@@ -38,7 +39,7 @@ func Test_validateAndParse(t *testing.T) {
3839
strategies := []searchAfterStrategy{searchAfterStrategyFactory(basicAndFast)}
3940
for _, strategy := range strategies {
4041
for i, tc := range testcases {
41-
t.Run(fmt.Sprintf("%v (testNr:%d)", tc.searchAfter, i), func(t *testing.T) {
42+
t.Run(util.PrettyTestName(fmt.Sprintf("%v", tc.searchAfter), i), func(t *testing.T) {
4243
query := &model.Query{}
4344
query.SelectCommand.OrderBy = []model.OrderByExpr{model.NewOrderByExprWithoutOrder(model.NewColumnRef("@timestamp"))}
4445
if arr, ok := tc.searchAfter.([]any); ok && len(arr) == 2 {
@@ -150,7 +151,7 @@ func Test_applySearchAfterParameter(t *testing.T) {
150151
strategies := []searchAfterStrategyType{basicAndFast}
151152
for _, strategy := range strategies {
152153
for i, tc := range testcases {
153-
t.Run(fmt.Sprintf("%v (testNr:%d)", tc.searchAfter, i), func(t *testing.T) {
154+
t.Run(util.PrettyTestName(fmt.Sprintf("%v", tc.searchAfter), i), func(t *testing.T) {
154155
// apply search_after parameter, easier to do here than in all the testcases
155156
tc.query.SearchAfter = tc.searchAfter
156157
tc.transformedQueryExpected.SearchAfter = tc.searchAfter

0 commit comments

Comments
 (0)