pikman/command/command_test.go

80 lines
1.7 KiB
Go
Raw Permalink Normal View History

package command
import (
"testing"
"pikman/types"
)
func Test_getCommand(t *testing.T) {
type args struct {
2023-01-19 17:19:14 +01:00
command string
osType types.OSType
packageName []string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "Ubuntu single package",
args: args{
2023-01-19 17:19:14 +01:00
command: "install",
osType: types.Ubuntu,
packageName: []string{"testPackage"},
},
want: "sudo -S apt install testPackage",
wantErr: false,
},
{
name: "Arch single package",
args: args{
2023-01-19 17:19:14 +01:00
command: "install",
osType: types.Arch,
packageName: []string{"testPackage"},
},
2023-01-19 17:19:14 +01:00
want: "apx --aur install testPackage",
wantErr: false,
},
{
name: "Arch single package with container name",
args: args{
2023-01-19 17:19:14 +01:00
command: "install",
osType: types.Arch,
packageName: []string{"--name testName", "testPackage"},
},
want: "apx --aur install --name testName testPackage",
wantErr: false,
},
{
name: "Ubuntu invalid command should return nothing and error",
args: args{
2023-01-19 17:19:14 +01:00
command: "init",
osType: types.Ubuntu,
packageName: []string{"testPackage"},
},
want: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
command := &Command{
Command: tt.args.command,
OsType: tt.args.osType,
PackageName: tt.args.packageName,
}
got, err := command.getCommand()
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)
}
})
}
}