8000 tracee-ebpf: add output validate test by josedonizetti · Pull Request #881 · aquasecurity/tracee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tracee-ebpf: add output validate test #881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up f 8000 or GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tracee-ebpf/tracee/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ type netProbe struct {

// Validate does static validation of the configuration
func (cfg OutputConfig) Validate() error {
if cfg.Format != "table" && cfg.Format != "table-verbose" && cfg.Format != "json" && cfg.Format != "gob" && !strings.HasPrefix(cfg.Format, "gotemplate=") {
if cfg.Format != "table" &&
cfg.Format != "table-verbose" &&
cfg.Format != "json" &&
cfg.Format != "gob" &&
!strings.HasPrefix(cfg.Format, "gotemplate=") {
return fmt.Errorf("unrecognized output format: %s. Valid format values: 'table', 'table-verbose', 'json', 'gob' or 'gotemplate='. Use '--output help' for more info.", cfg.Format)
}

return nil
}

Expand Down
24 changes: 24 additions & 0 deletions tracee-ebpf/tracee/tracee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,27 @@ func Test_updateFileSHA(t *testing.T) {
},
}, trc.profiledFiles)
}

func TestOutputConfigValidate(t *testing.T) {

testCases := []struct {
name string
format string
expectedError error
}{
{"format:table", "table", nil},
{"format:table-verbose", "table-verbose", nil},
{"format:json", "json", nil},
{"format:gob", "gob", nil},
{"format:gotemplate=tmpl", "gotemplate=tmpl", nil},
{"invalid format", "invalid", errors.New("unrecognized output format: invalid. Valid format values: 'table', 'table-verbose', 'json', 'gob' or 'gotemplate='. Use '--output help' for more info.")},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cfg := OutputConfig{Format: tc.format}
err := cfg.Validate()
assert.Equal(t, tc.expectedError, err)
})
}
}
0