mirror of
https://github.com/chenasraf/sofmani.git
synced 2026-05-17 17:28:04 +00:00
60 lines
1.5 KiB
Go
Executable File
60 lines
1.5 KiB
Go
Executable File
package installer
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/chenasraf/sofmani/appconfig"
|
|
"github.com/chenasraf/sofmani/logger"
|
|
)
|
|
|
|
func newTestShellInstaller(data *appconfig.InstallerData) *ShellInstaller {
|
|
return &ShellInstaller{
|
|
InstallerBase: InstallerBase{Data: data},
|
|
Config: nil,
|
|
Info: data,
|
|
}
|
|
}
|
|
|
|
func TestShellValidation(t *testing.T) {
|
|
logger.InitLogger(false)
|
|
|
|
// 🟢 Valid shell config
|
|
validData := &appconfig.InstallerData{
|
|
Name: strPtr("shell-valid"),
|
|
Type: appconfig.InstallerTypeShell,
|
|
Opts: &map[string]any{
|
|
"command": "echo install",
|
|
"update_command": "echo update",
|
|
},
|
|
}
|
|
assertNoValidationErrors(t, newTestShellInstaller(validData).Validate())
|
|
|
|
// 🔴 Missing command
|
|
missingCommand := &appconfig.InstallerData{
|
|
Name: strPtr("shell-missing-command"),
|
|
Type: appconfig.InstallerTypeShell,
|
|
Opts: &map[string]any{
|
|
"update_command": "echo update",
|
|
},
|
|
}
|
|
assertValidationError(t, newTestShellInstaller(missingCommand).Validate(), "command")
|
|
|
|
// 🟢 Valid - missing update_command
|
|
missingUpdate := &appconfig.InstallerData{
|
|
Name: strPtr("shell-missing-update"),
|
|
Type: appconfig.InstallerTypeShell,
|
|
Opts: &map[string]any{
|
|
"command": "echo install",
|
|
},
|
|
}
|
|
assertNoValidationErrors(t, newTestShellInstaller(missingUpdate).Validate())
|
|
|
|
// 🔴 Missing both
|
|
missingBoth := &appconfig.InstallerData{
|
|
Name: strPtr("shell-missing-both"),
|
|
Type: appconfig.InstallerTypeShell,
|
|
Opts: &map[string]any{},
|
|
}
|
|
assertValidationError(t, newTestShellInstaller(missingBoth).Validate(), "command")
|
|
}
|