mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-03 20:44:14 -04:00
feat: added journald collection package to bootstrapper internal packages
This commit is contained in:
parent
2a8169dd3b
commit
c1dbf0561a
3 changed files with 127 additions and 0 deletions
64
bootstrapper/internal/journald/journald_test.go
Normal file
64
bootstrapper/internal/journald/journald_test.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package journald
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type stubJournaldCommand struct {
|
||||
outputReturn []byte
|
||||
outputError error
|
||||
}
|
||||
|
||||
func (j *stubJournaldCommand) Output() ([]byte, error) {
|
||||
return j.outputReturn, j.outputError
|
||||
}
|
||||
|
||||
func TestCollect(t *testing.T) {
|
||||
someError := errors.New("failed")
|
||||
|
||||
testCases := map[string]struct {
|
||||
command *stubJournaldCommand
|
||||
wantedOutput []byte
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
command: &stubJournaldCommand{},
|
||||
},
|
||||
"execution failed": {
|
||||
command: &stubJournaldCommand{outputError: someError},
|
||||
wantErr: true,
|
||||
},
|
||||
"exit error": {
|
||||
command: &stubJournaldCommand{outputError: &exec.ExitError{}},
|
||||
wantErr: true,
|
||||
},
|
||||
"output check": {
|
||||
command: &stubJournaldCommand{outputReturn: []byte("asdf")},
|
||||
wantedOutput: []byte("asdf"),
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
collector := Collector{cmd: tc.command}
|
||||
|
||||
out, err := collector.Collect()
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
}
|
||||
assert.Equal(out, tc.wantedOutput)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue