Skip to content

Commit

Permalink
Merge pull request #437 from thockin/master
Browse files Browse the repository at this point in the history
Do not require listType on []byte fields
  • Loading branch information
k8s-ci-robot authored Nov 13, 2023
2 parents 2dd684a + 34ea5aa commit 778a556
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/generators/rules/idl_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func (l *ListTypeMissing) Validate(t *types.Type) ([]string, error) {
continue
}

if m.Type.Kind == types.Slice && !hasListType {
// All slice fields must have a list-type tag except []byte
if m.Type.Kind == types.Slice && m.Type.Elem != types.Byte && !hasListType {
fields = append(fields, m.Name)
continue
}
Expand Down
19 changes: 18 additions & 1 deletion pkg/generators/rules/idl_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,29 @@ func TestListTypeMissing(t *testing.T) {
},
expected: []string{"Items"},
},

{
name: "a byte-slice field without annotation should pass validation",
t: &types.Type{
Kind: types.Struct,
Members: []types.Member{
{
Name: "ByteSliceField",
Type: &types.Type{
Kind: types.Slice,
Elem: types.Byte,
},
},
},
},
expected: []string{},
},
}

rule := &ListTypeMissing{}
for _, tc := range tcs {
if violations, _ := rule.Validate(tc.t); !reflect.DeepEqual(violations, tc.expected) {
t.Errorf("unexpected validation result: test name %v, want: %v, got: %v",
t.Errorf("unexpected validation result: test name %q, want: %v, got: %v",
tc.name, tc.expected, violations)
}
}
Expand Down

0 comments on commit 778a556

Please sign in to comment.