-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_acc_test.go
96 lines (78 loc) · 2.57 KB
/
client_acc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package gowindows_test
import (
"context"
"os"
"strconv"
"testing"
"github.com/d-strobel/gowindows"
"github.com/d-strobel/gowindows/connection/ssh"
"github.com/d-strobel/gowindows/connection/winrm"
"github.com/stretchr/testify/suite"
)
type GowindowsAccTestSuite struct {
suite.Suite
// Fixtures
host string
username string
password string
sshPort int
httpPort int
}
// SetupSuite setups all neccessary fixtures for running the gowindows tests.
func (suite *GowindowsAccTestSuite) SetupSuite() {
var err error
// Load environment variables
suite.host = os.Getenv("GOWINDOWS_TEST_HOST")
suite.Require().NotEmpty(suite.host, "Environment variable not set: GOWINDOWS_TEST_HOST")
suite.username = os.Getenv("GOWINDOWS_TEST_USERNAME")
suite.Require().NotEmpty(suite.username, "Environment variable not set: GOWINDOWS_TEST_USERNAME")
suite.password = os.Getenv("GOWINDOWS_TEST_PASSWORD")
suite.Require().NotEmpty(suite.password, "Environment variable not set: GOWINDOWS_TEST_PASSWORD")
suite.sshPort, err = strconv.Atoi(os.Getenv("GOWINDOWS_TEST_SSH_PORT"))
suite.Require().NoError(err)
suite.httpPort, err = strconv.Atoi(os.Getenv("GOWINDOWS_TEST_WINRM_HTTP_PORT"))
suite.Require().NoError(err)
}
// TestGowindowsAccTestSuite runs the acceptance test suite for the gowindwos package.
// It will be skipped if the short flag is set.
func TestGowindowsAccTestSuite(t *testing.T) {
if testing.Short() {
t.Skip()
}
suite.Run(t, &GowindowsAccTestSuite{})
}
func (suite *GowindowsAccTestSuite) TestNewClient() {
// Test subpackages to ensure the gowindows client works as expected.
suite.Run("should return local users with an ssh connection", func() {
sshConfig := &ssh.Config{
Host: suite.host,
Port: suite.sshPort,
Username: suite.username,
Password: suite.password,
}
conn, err := ssh.NewConnection(sshConfig)
suite.Require().NoError(err)
defer conn.Close()
client := gowindows.NewClient(conn)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err = client.LocalAccounts.UserList(ctx)
suite.NoError(err)
})
suite.Run("should return local users with a winrm connection", func() {
winrmConfig := &winrm.Config{
Host: suite.host,
Port: suite.httpPort,
Username: suite.username,
Password: suite.password,
}
conn, err := winrm.NewConnection(winrmConfig)
suite.Require().NoError(err)
defer conn.Close()
client := gowindows.NewClient(conn)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err = client.LocalAccounts.UserList(ctx)
suite.NoError(err)
})
}