Skip to content

Commit

Permalink
Run unit tests on Windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
csstaub committed Jan 10, 2018
1 parent fc40a1f commit 679b25b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ before_build:

build_script:
- go build -o ghostunnel.exe -i .
- go test -v .
3 changes: 2 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestIntegrationMain(t *testing.T) {

func TestInitLoggerSyslog(t *testing.T) {
*useSyslog = true
defer func() { *useSyslog = false }()
originalLogger := logger
err := initLogger()
updatedLogger := logger
Expand All @@ -91,10 +92,10 @@ func TestInitLoggerSyslog(t *testing.T) {
// get an error from the syslog setup we just warn and skip test.
t.Logf("Error setting up syslog for test, skipping: %s", err)
t.SkipNow()
return
}
assert.NotEqual(t, originalLogger, updatedLogger, "should have updated logger object")
assert.NotNil(t, logger, "logger should never be nil after init")
*useSyslog = false
}

func TestPanicOnError(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c fakeConn) SetWriteDeadline(t time.Time) error {
}

func dummyDial() (net.Conn, error) {
f, err := os.Open("/dev/null")
f, err := os.Open(os.DevNull)
panicOnError(err)
return fakeConn{f}, nil
}
Expand Down
23 changes: 19 additions & 4 deletions tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/base64"
"io/ioutil"
"os"
"runtime"
"testing"

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

func TestCipherSuitePreference(t *testing.T) {
tmpCaBundle, err := ioutil.TempFile("", "ghostunnel-test")
panicOnError(err)

tmpCaBundle.WriteString(testCertificate)
tmpCaBundle.WriteString("\n")

tmpCaBundle.Sync()
defer os.Remove(tmpCaBundle.Name())

*enabledCipherSuites = "XYZ"
conf, err := buildConfig("")
conf, err := buildConfig(tmpCaBundle.Name())
assert.NotNil(t, err, "should not be able to build TLS config with invalid cipher suite option")

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

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

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

func TestBuildConfigSystemRoots(t *testing.T) {
if runtime.GOOS == "windows" {
// System roots are not supported on Windows
t.SkipNow()
return
}
conf, err := buildConfig("")
assert.Nil(t, err, "should be able to build TLS config")
assert.NotNil(t, conf.RootCAs, "config must have CA certs")
Expand Down

0 comments on commit 679b25b

Please sign in to comment.