mirror of
https://gitlab.durp.info/durfy/modules/gopwsh.git
synced 2026-05-07 16:10:29 -05:00
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
|
|
package gopwsh
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestRunPowershellCommand(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
cmd string
|
||
|
|
expectedErr error
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "test error",
|
||
|
|
cmd: "irm tgssdcfas.asdfasdf",
|
||
|
|
expectedErr: errors.New("The remote name could not be resolved: 'tgssdcfas.asdfasdf'"),
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "Test working command",
|
||
|
|
cmd: `get-host`,
|
||
|
|
expectedErr: nil,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
_, err := RunPowershellCommand(tt.cmd)
|
||
|
|
if err != nil {
|
||
|
|
if err.Error() != tt.expectedErr.Error() {
|
||
|
|
t.Errorf("RunPowershellCommand() error = %v, want error %v", err, tt.expectedErr)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestRunPwshCommand(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
cmd string
|
||
|
|
expectedErr error
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "test error",
|
||
|
|
cmd: "irm tgssdcfas.asdfasdf",
|
||
|
|
expectedErr: errors.New("No such host is known. (tgssdcfas.asdfasdf:80)"),
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "Test working command",
|
||
|
|
cmd: `get-host`,
|
||
|
|
expectedErr: nil,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
_, err := RunPwshCommand(tt.cmd)
|
||
|
|
if err != nil {
|
||
|
|
if err.Error() != tt.expectedErr.Error() {
|
||
|
|
t.Errorf("RunPwshCommand() error = %v, want error %v", err, tt.expectedErr)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|