2023-01-19 14:34:17 +01:00
|
|
|
package loader
|
|
|
|
|
2023-01-19 14:45:24 +01:00
|
|
|
import (
|
|
|
|
"pikman/types"
|
|
|
|
"testing"
|
|
|
|
)
|
2023-01-19 14:34:17 +01:00
|
|
|
|
|
|
|
func Test_getCommand(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
command string
|
2023-01-19 14:45:24 +01:00
|
|
|
osType types.OSType
|
2023-01-19 14:34:17 +01:00
|
|
|
containerName string
|
|
|
|
packageName []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Ubuntu single package",
|
|
|
|
args: args{
|
|
|
|
command: "install",
|
2023-01-19 14:45:24 +01:00
|
|
|
osType: types.Ubuntu,
|
2023-01-19 14:34:17 +01:00
|
|
|
containerName: "",
|
|
|
|
packageName: []string{"testPackage"},
|
|
|
|
},
|
|
|
|
want: "sudo -S nala install testPackage",
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Arch single package",
|
|
|
|
args: args{
|
|
|
|
command: "install",
|
2023-01-19 14:45:24 +01:00
|
|
|
osType: types.Arch,
|
2023-01-19 14:34:17 +01:00
|
|
|
containerName: "",
|
|
|
|
packageName: []string{"testPackage"},
|
|
|
|
},
|
|
|
|
want: "apx --aur install testPackage",
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Arch single package with container name",
|
|
|
|
args: args{
|
|
|
|
command: "install",
|
2023-01-19 14:45:24 +01:00
|
|
|
osType: types.Arch,
|
2023-01-19 14:34:17 +01:00
|
|
|
containerName: "--name testName",
|
|
|
|
packageName: []string{"testPackage"},
|
|
|
|
},
|
|
|
|
want: "apx --aur install --name testName testPackage",
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Ubuntu single package, container name not used",
|
|
|
|
args: args{
|
|
|
|
command: "install",
|
2023-01-19 14:45:24 +01:00
|
|
|
osType: types.Ubuntu,
|
2023-01-19 14:34:17 +01:00
|
|
|
containerName: "--name testName",
|
|
|
|
packageName: []string{"testPackage"},
|
|
|
|
},
|
|
|
|
want: "sudo -S nala install testPackage",
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Ubuntu invalid command should return nothing and error",
|
|
|
|
args: args{
|
|
|
|
command: "init",
|
2023-01-19 14:45:24 +01:00
|
|
|
osType: types.Ubuntu,
|
2023-01-19 14:34:17 +01:00
|
|
|
containerName: "",
|
|
|
|
packageName: []string{"testPackage"},
|
|
|
|
},
|
|
|
|
want: "",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := getCommand(tt.args.command, tt.args.osType, tt.args.containerName, tt.args.packageName)
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("getCommand() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if got != tt.want {
|
|
|
|
t.Errorf("getCommand() got = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|