Skip to content

Commit

Permalink
fix: allow empty selector in specs v1 (#2880)
Browse files Browse the repository at this point in the history
* fix: allow empty selector in specs v1

* update variable and format JSON
  • Loading branch information
mathnogueira committed Jul 6, 2023
1 parent bcf11e7 commit 963d827
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
9 changes: 8 additions & 1 deletion server/test/test_json.go
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions server/test/test_json_test.go
Expand Up @@ -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 := `
[
Expand Down
4 changes: 0 additions & 4 deletions server/test/test_repository.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 963d827

Please sign in to comment.