diff --git a/server/test/test_json.go b/server/test/test_json.go index a33ef2dd1b..e328a9a305 100644 --- a/server/test/test_json.go +++ b/server/test/test_json.go @@ -17,7 +17,14 @@ func (v1 testSpecV1) valid() bool { valid := true specs := maps.Ordered[SpanQuery, namedAssertions](v1) specs.ForEach(func(key SpanQuery, val namedAssertions) error { - if key == "" { + anyEmptyAssertion := false + for _, assertion := range val.Assertions { + if assertion == "" { + anyEmptyAssertion = true + } + } + + if key == "" && anyEmptyAssertion { valid = false } return nil diff --git a/server/test/test_json_test.go b/server/test/test_json_test.go index 4dab191de2..23a5059da4 100644 --- a/server/test/test_json_test.go +++ b/server/test/test_json_test.go @@ -51,6 +51,38 @@ func TestSpecV1(t *testing.T) { assert.Equal(t, test.Assertion("attr:http.status = 200"), testObject.Specs[1].Assertions[0]) } +func TestV1WithEmptySelector(t *testing.T) { + specsJSONWithEmptySelector := `[ + { + "Key": "", + "Value": { + "Name": "DURATION_CHECK", + "Assertions": ["attr:tracetest.span.duration < 2s"] + } + }, + { + "Key": "span[tracetest.span.type=\"database\"]", + "Value": { + "Name": "All Database Spans: Processing time is less than 100ms", + "Assertions": ["attr:tracetest.span.duration < 100ms"] + } + } + ]` + testObject := test.Test{} + err := json.Unmarshal([]byte(specsJSONWithEmptySelector), &testObject.Specs) + + require.NoError(t, err) + assert.Equal(t, test.SpanQuery(""), testObject.Specs[0].Selector) + assert.Equal(t, "DURATION_CHECK", testObject.Specs[0].Name) + assert.Len(t, testObject.Specs[0].Assertions, 1) + assert.Equal(t, test.Assertion("attr:tracetest.span.duration < 2s"), testObject.Specs[0].Assertions[0]) + + assert.Equal(t, test.SpanQuery("span[tracetest.span.type=\"database\"]"), testObject.Specs[1].Selector) + assert.Equal(t, "All Database Spans: Processing time is less than 100ms", testObject.Specs[1].Name) + assert.Len(t, testObject.Specs[1].Assertions, 1) + assert.Equal(t, test.Assertion("attr:tracetest.span.duration < 100ms"), testObject.Specs[1].Assertions[0]) +} + func TestSpecV2(t *testing.T) { specFormat := ` [ diff --git a/server/test/test_repository.go b/server/test/test_repository.go index 01f23eef31..f1d1270a6c 100644 --- a/server/test/test_repository.go +++ b/server/test/test_repository.go @@ -476,10 +476,6 @@ func testFieldHasChanged(oldField interface{}, newField interface{}) (bool, erro return string(oldFieldJSON) != string(newFieldJSON), nil } -func intPtr(in int) *int { - return &in -} - func (r *repository) Delete(ctx context.Context, id id.ID) error { exists, err := r.Exists(ctx, id) if err != nil {