Skip to content

Commit 679b25b

Browse files
committed
Run unit tests on Windows builds
1 parent fc40a1f commit 679b25b

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

.appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ before_build:
3636

3737
build_script:
3838
- go build -o ghostunnel.exe -i .
39+
- go test -v .

main_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func TestIntegrationMain(t *testing.T) {
8282

8383
func TestInitLoggerSyslog(t *testing.T) {
8484
*useSyslog = true
85+
defer func() { *useSyslog = false }()
8586
originalLogger := logger
8687
err := initLogger()
8788
updatedLogger := logger
@@ -91,10 +92,10 @@ func TestInitLoggerSyslog(t *testing.T) {
9192
// get an error from the syslog setup we just warn and skip test.
9293
t.Logf("Error setting up syslog for test, skipping: %s", err)
9394
t.SkipNow()
95+
return
9496
}
9597
assert.NotEqual(t, originalLogger, updatedLogger, "should have updated logger object")
9698
assert.NotNil(t, logger, "logger should never be nil after init")
97-
*useSyslog = false
9899
}
99100

100101
func TestPanicOnError(t *testing.T) {

status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (c fakeConn) SetWriteDeadline(t time.Time) error {
5252
}
5353

5454
func dummyDial() (net.Conn, error) {
55-
f, err := os.Open("/dev/null")
55+
f, err := os.Open(os.DevNull)
5656
panicOnError(err)
5757
return fakeConn{f}, nil
5858
}

tls_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/base64"
2222
"io/ioutil"
2323
"os"
24+
"runtime"
2425
"testing"
2526

2627
"github.com/stretchr/testify/assert"
@@ -212,21 +213,30 @@ func TestBuildConfig(t *testing.T) {
212213
}
213214

214215
func TestCipherSuitePreference(t *testing.T) {
216+
tmpCaBundle, err := ioutil.TempFile("", "ghostunnel-test")
217+
panicOnError(err)
218+
219+
tmpCaBundle.WriteString(testCertificate)
220+
tmpCaBundle.WriteString("\n")
221+
222+
tmpCaBundle.Sync()
223+
defer os.Remove(tmpCaBundle.Name())
224+
215225
*enabledCipherSuites = "XYZ"
216-
conf, err := buildConfig("")
226+
conf, err := buildConfig(tmpCaBundle.Name())
217227
assert.NotNil(t, err, "should not be able to build TLS config with invalid cipher suite option")
218228

219229
*enabledCipherSuites = ""
220-
conf, err = buildConfig("")
230+
conf, err = buildConfig(tmpCaBundle.Name())
221231
assert.NotNil(t, err, "should not be able to build TLS config wihout cipher suite selection")
222232

223233
*enabledCipherSuites = "CHACHA,AES"
224-
conf, err = buildConfig("")
234+
conf, err = buildConfig(tmpCaBundle.Name())
225235
assert.Nil(t, err, "should be able to build TLS config")
226236
assert.True(t, conf.CipherSuites[0] == tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, "expecting ChaCha20")
227237

228238
*enabledCipherSuites = "AES,CHACHA"
229-
conf, err = buildConfig("")
239+
conf, err = buildConfig(tmpCaBundle.Name())
230240
assert.Nil(t, err, "should be able to build TLS config")
231241
assert.True(t, conf.CipherSuites[0] == tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, "expecting AES")
232242
}
@@ -247,6 +257,11 @@ func TestReload(t *testing.T) {
247257
}
248258

249259
func TestBuildConfigSystemRoots(t *testing.T) {
260+
if runtime.GOOS == "windows" {
261+
// System roots are not supported on Windows
262+
t.SkipNow()
263+
return
264+
}
250265
conf, err := buildConfig("")
251266
assert.Nil(t, err, "should be able to build TLS config")
252267
assert.NotNil(t, conf.RootCAs, "config must have CA certs")

0 commit comments

Comments
 (0)