mirror of
https://github.com/luxfi/lpm.git
synced 2026-10-30 16:20:57 +00:00
Modules declare go 1.27.1 and the build images follow. go fix applied the modernizers, and the repository lookup is now a generic method on DiskRepository; omitzero is not applied, since it changes what the JSON says. Co-authored-by: Hanzo Dev <[email protected]>
90 lines
1.8 KiB
Go
90 lines
1.8 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package workflow
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/lpm/state"
|
|
"github.com/luxfi/lpm/types"
|
|
)
|
|
|
|
func TestUninstallExecute(t *testing.T) {
|
|
name := "organization/repository:vm"
|
|
|
|
vm := types.VM{
|
|
ID: "id",
|
|
Alias: "vm",
|
|
Homepage: "homepage",
|
|
Description: "description",
|
|
Maintainers: []string{"joshua", "kim"},
|
|
InstallScript: "./installScript",
|
|
BinaryPath: "./build/binaryPath",
|
|
URL: "url",
|
|
SHA256: "sha256",
|
|
}
|
|
|
|
definition := state.Definition[types.VM]{
|
|
Definition: vm,
|
|
Commit: "commit",
|
|
}
|
|
|
|
type mocks struct {
|
|
stateFile state.File
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
setup func(mocks)
|
|
wantErr assert.ErrorAssertionFunc
|
|
}{
|
|
{
|
|
name: "vm already uninstalled",
|
|
setup: func(_ mocks) {
|
|
},
|
|
wantErr: func(t assert.TestingT, err error, _ ...any) bool {
|
|
return assert.Nil(t, err)
|
|
},
|
|
},
|
|
{
|
|
name: "success",
|
|
setup: func(mocks mocks) {
|
|
mocks.stateFile.InstallationRegistry[name] = &state.InstallInfo{
|
|
ID: vm.GetID(),
|
|
Commit: definition.Commit,
|
|
}
|
|
},
|
|
wantErr: func(t assert.TestingT, err error, _ ...any) bool {
|
|
return assert.Nil(t, err)
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
stateFile, err := state.New("stateFilePath")
|
|
require.NoError(t, err)
|
|
|
|
test.setup(mocks{
|
|
stateFile: stateFile,
|
|
})
|
|
|
|
wf := NewUninstall(
|
|
UninstallConfig{
|
|
Name: "organization/repository:vm",
|
|
Plugin: "vm",
|
|
RepoAlias: "organization/repository",
|
|
StateFile: stateFile,
|
|
Fs: afero.NewMemMapFs(),
|
|
},
|
|
)
|
|
|
|
test.wantErr(t, wf.Execute())
|
|
})
|
|
}
|
|
}
|