2024-09-29 14:59:39 +09:00
|
|
|
package helper_test
|
|
|
|
|
|
|
|
import (
|
2024-10-06 16:00:59 +09:00
|
|
|
"errors"
|
|
|
|
"os"
|
2024-09-29 14:59:39 +09:00
|
|
|
"testing"
|
|
|
|
|
2024-12-20 00:20:02 +09:00
|
|
|
"git.gensokyo.uk/security/fortify/helper"
|
2024-09-29 14:59:39 +09:00
|
|
|
)
|
|
|
|
|
2024-10-08 14:02:54 +09:00
|
|
|
func TestDirect(t *testing.T) {
|
2024-10-06 16:00:59 +09:00
|
|
|
t.Run("start non-existent helper path", func(t *testing.T) {
|
2024-10-07 12:48:20 +09:00
|
|
|
h := helper.New(argsWt, "/nonexistent", argF)
|
2024-10-06 16:00:59 +09:00
|
|
|
|
|
|
|
if err := h.Start(); !errors.Is(err, os.ErrNotExist) {
|
|
|
|
t.Errorf("Start() error = %v, wantErr %v",
|
|
|
|
err, os.ErrNotExist)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-09-29 14:59:39 +09:00
|
|
|
t.Run("valid new helper nil check", func(t *testing.T) {
|
2024-10-08 14:02:54 +09:00
|
|
|
if got := helper.New(argsWt, "fortify", argF); got == nil {
|
2024-09-29 14:59:39 +09:00
|
|
|
t.Errorf("New(%q, %q) got nil",
|
2024-10-08 14:02:54 +09:00
|
|
|
argsWt, "fortify")
|
2024-09-29 14:59:39 +09:00
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid new helper panic", func(t *testing.T) {
|
|
|
|
defer func() {
|
2024-10-08 14:02:54 +09:00
|
|
|
wantPanic := "attempted to create helper with invalid argument writer"
|
|
|
|
if r := recover(); r != wantPanic {
|
2024-09-29 14:59:39 +09:00
|
|
|
t.Errorf("New: panic = %q, want %q",
|
2024-10-08 14:02:54 +09:00
|
|
|
r, wantPanic)
|
2024-09-29 14:59:39 +09:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2024-10-07 12:48:20 +09:00
|
|
|
helper.New(nil, "fortify", argF)
|
2024-09-29 14:59:39 +09:00
|
|
|
})
|
2024-10-08 14:02:54 +09:00
|
|
|
|
|
|
|
t.Run("implementation compliance", func(t *testing.T) {
|
|
|
|
testHelper(t, func() helper.Helper { return helper.New(argsWt, "crash-test-dummy", argF) })
|
|
|
|
})
|
2024-09-29 14:59:39 +09:00
|
|
|
}
|