Files
sofmani/installer/installer_test.go

43 lines
1.2 KiB
Go
Executable File

package installer
import (
"testing"
"github.com/chenasraf/sofmani/appconfig"
"github.com/chenasraf/sofmani/logger"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
)
func TestGetInstaller(t *testing.T) {
config := &appconfig.AppConfig{}
logger.InitLogger(false)
installer := &appconfig.InstallerData{Type: appconfig.InstallerTypeBrew}
inst, err := GetInstaller(config, installer)
assert.NoError(t, err)
assert.NotNil(t, inst)
}
func TestInstallerWithDefaults(t *testing.T) {
opts := map[string]any{"key": "value"}
defaults := &appconfig.AppConfigDefaults{
Type: &map[appconfig.InstallerType]appconfig.InstallerData{
appconfig.InstallerTypeBrew: {Opts: &opts},
},
}
installer := &appconfig.InstallerData{Type: appconfig.InstallerTypeBrew, Opts: &map[string]any{}}
result := InstallerWithDefaults(installer, appconfig.InstallerTypeBrew, defaults)
assert.Equal(t, "value", (*result.Opts)["key"])
}
func TestRunInstaller(t *testing.T) {
config := &appconfig.AppConfig{}
mockInstaller := &MockInstaller{
data: &appconfig.InstallerData{Name: lo.ToPtr("test"), Type: appconfig.InstallerTypeBrew},
isInstalled: false,
}
result, err := RunInstaller(config, mockInstaller)
assert.NoError(t, err)
assert.NotNil(t, result)
}