mirror of
https://github.com/kubereboot/kured.git
synced 2026-03-02 17:00:19 +00:00
Without this patch, we use WriterLevel, which spawns go routines. As we do it at every call of the util commands, we spawn goroutines at every check. This is a problem as it leads to memory management issues. This fixes it by using a buffer for stdout and stderr, then logging the results after the command was executed. To make sure the logging happened at the same place, I inlined the code from utils. This results in duplicated the code. However, this is not a big problem as: - It makes the code more readable - The implementation between checkers and rebooters _ARE_ different -- One definitely NEEDS privileges, while the other does not... Which could lead to later improvements. Removing a "utils" package is not really a big deal (it is kinda a win in itself, as it is an anti-pattern), as the test coverage was kept. Partial-Fix: #1004 Fixes: #1013 Signed-off-by: Jean-Philippe Evrard <open-source@a.spamming.party>
44 lines
953 B
Go
44 lines
953 B
Go
package reboot
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewCommandRebooter(t *testing.T) {
|
|
type args struct {
|
|
rebootCommand string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *CommandRebooter
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Ensure command is nsenter wrapped",
|
|
args: args{"ls -Fal"},
|
|
want: &CommandRebooter{RebootCommand: []string{"/usr/bin/nsenter", "-m/proc/1/ns/mnt", "--", "ls", "-Fal"}},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "Ensure empty command is erroring",
|
|
args: args{""},
|
|
want: nil,
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := NewCommandRebooter(tt.args.rebootCommand)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("NewCommandRebooter() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("NewCommandRebooter() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|