package sborepo

import (
	"errors"
	"regexp"
	"syscall"
	"testing"
)

func TestKernelVersion(t *testing.T) {
	VersionPattern := regexp.MustCompile(`\d+\.\d+\.\d+`)
	// Test the KernelVersion function
	if KernelVersion() == "" {
		t.Error("KernelVersion() returned an empty string")
	}
	if !VersionPattern.MatchString(KernelVersion()) {
		t.Error("KernelVersion() returned an invalid version")
	}
	t.Log("KernelVersion() test passed with version:", KernelVersion())
}

func TestKernelVersionPanic(t *testing.T) {
	origUnameFunc := unameFunc
	defer func() {
		unameFunc = origUnameFunc
		if r := recover(); r == nil {
			t.Error("expected KernelVersion() to panic")
		}
	}()

	unameFunc = func(*syscall.Utsname) error { return errors.New("uname failed") }
	KernelVersion()
}
