forked from aquasecurity/tracee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tracee-ebpf: separate printer and debug package (aquasecurity#1775)
- Loading branch information
1 parent
5626d26
commit 557e225
Showing
8 changed files
with
154 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package debug_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/tracee/cmd/tracee-ebpf/internal/debug" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDebug_Initial(t *testing.T) { | ||
assert.Equal(t, false, debug.Enabled()) | ||
} | ||
|
||
func TestDebug_EnableDebug(t *testing.T) { | ||
err := debug.Enable() | ||
require.NoError(t, err) | ||
assert.Equal(t, true, debug.Enabled()) | ||
} | ||
|
||
func TestDebug_DisableDebug(t *testing.T) { | ||
err := debug.Disable() | ||
require.NoError(t, err) | ||
assert.Equal(t, false, debug.Enabled()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package printer_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/aquasecurity/tracee/cmd/tracee-ebpf/internal/flags" | ||
"github.com/aquasecurity/tracee/cmd/tracee-ebpf/internal/printer" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPrepareOutputPrinterConfig(t *testing.T) { | ||
|
||
testCases := []struct { | ||
testName string | ||
outputSlice []string | ||
expectedPrinter printer.Config | ||
expectedError error | ||
}{ | ||
{ | ||
testName: "invalid format", | ||
outputSlice: []string{"notaformat"}, | ||
expectedPrinter: printer.Config{}, | ||
expectedError: fmt.Errorf("unrecognized output format: %s. Valid format values: 'table', 'table-verbose', 'json', 'gob' or 'gotemplate='. Use '--output help' for more info", "notaformat"), | ||
}, | ||
{ | ||
testName: "invalid format with format prefix", | ||
outputSlice: []string{"format:notaformat2"}, | ||
expectedPrinter: printer.Config{}, | ||
expectedError: fmt.Errorf("unrecognized output format: %s. Valid format values: 'table', 'table-verbose', 'json', 'gob' or 'gotemplate='. Use '--output help' for more info", "notaformat2"), | ||
}, | ||
{ | ||
testName: "default", | ||
outputSlice: []string{}, | ||
expectedPrinter: printer.Config{ | ||
Kind: "table", | ||
OutFile: os.Stdout, | ||
ErrFile: os.Stderr, | ||
}, | ||
expectedError: nil, | ||
}, | ||
{ | ||
testName: "format: json", | ||
outputSlice: []string{"format:json"}, | ||
expectedPrinter: printer.Config{ | ||
Kind: "json", | ||
OutFile: os.Stdout, | ||
ErrFile: os.Stderr, | ||
}, | ||
expectedError: nil, | ||
}, | ||
{ | ||
testName: "option relative timestamp", | ||
outputSlice: []string{"option:relative-time"}, | ||
expectedPrinter: printer.Config{ | ||
Kind: "table", | ||
OutFile: os.Stdout, | ||
ErrFile: os.Stderr, | ||
RelativeTS: true, | ||
}, | ||
expectedError: nil, | ||
}, | ||
} | ||
for _, testcase := range testCases { | ||
t.Run(testcase.testName, func(t *testing.T) { | ||
_, printerCfg, err := flags.PrepareOutput(testcase.outputSlice) | ||
if err != nil { | ||
assert.Equal(t, testcase.expectedError, err) | ||
} else { | ||
assert.Equal(t, testcase.expectedPrinter, printerCfg) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters