Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
wbrowne committed Aug 16, 2024
1 parent 11ae6e4 commit a87a823
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/log/context_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ContextualAttributesFromIncomingContext(ctx context.Context) []any {
var attrs []any
for _, param := range logParams {
kv := strings.Split(param, logParamSeparator)
if len(kv) != 2 {
if len(kv) != 2 || kv[0] == "" || kv[1] == "" {
continue
}
attrs = append(attrs, kv[0], kv[1])
Expand Down
14 changes: 12 additions & 2 deletions backend/log/context_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,18 @@ func TestContextualAttributesFromIncomingContext(t *testing.T) {
expected: []any{"key1", "value1", "key2", "value2"},
},
{
name: "metadata with invalid log params",
md: metadata.MD{logParamsCtxMetadataKey: []string{"key1", "key2:value2"}},
name: "metadata with missing key",
md: metadata.MD{logParamsCtxMetadataKey: []string{":value1", "key2:value2"}},
expected: []any{"key2", "value2"},
},
{
name: "metadata with missing value",
md: metadata.MD{logParamsCtxMetadataKey: []string{"key1:", "key2:value2"}},
expected: []any{"key2", "value2"},
},
{
name: "metadata with invalid key + value",
md: metadata.MD{logParamsCtxMetadataKey: []string{":", "key2:value2"}},
expected: []any{"key2", "value2"},
},
}
Expand Down

0 comments on commit a87a823

Please sign in to comment.