Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Add support for building and bundling windows binaries. #117

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ build-cross: cmd/gaurun/gaurun.go cmd/gaurun_recover/gaurun_recover.go gaurun/*.
GO111MODULE=on GOOS=linux GOARCH=amd64 go build -o bin/linux/amd64/gaurun-${VERSION}/gaurun_recover cmd/gaurun_recover/gaurun_recover.go
GO111MODULE=on GOOS=darwin GOARCH=amd64 go build -o bin/darwin/amd64/gaurun-${VERSION}/gaurun cmd/gaurun/gaurun.go
GO111MODULE=on GOOS=darwin GOARCH=amd64 go build -o bin/darwin/amd64/gaurun-${VERSION}/gaurun_recover cmd/gaurun_recover/gaurun_recover.go
GO111MODULE=on GOOS=windows GOARCH=amd64 go build -o bin/windows/amd64/gaurun-${VERSION}/gaurun.exe cmd/gaurun/gaurun.go
GO111MODULE=on GOOS=windows GOARCH=amd64 go build -o bin/windows/amd64/gaurun-${VERSION}/gaurun_recover.exe cmd/gaurun_recover/gaurun_recover.go

dist: build-cross
cd bin/linux/amd64 && tar zcvf gaurun-linux-amd64-${VERSION}.tar.gz gaurun-${VERSION}
cd bin/darwin/amd64 && tar zcvf gaurun-darwin-amd64-${VERSION}.tar.gz gaurun-${VERSION}
cd bin/windows/amd64 && tar zcvf gaurun-windows-amd64-${VERSION}.tar.gz gaurun-${VERSION}

bin/gaurun: cmd/gaurun/gaurun.go gaurun/*.go buford/**/*.go gcm/*.go
GO111MODULE=on go build -o bin/gaurun cmd/gaurun/gaurun.go
Expand Down
2 changes: 2 additions & 0 deletions buford/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Token struct {
}

// AuthKeyFromFile loads a .p8 certificate from a local file and returns a
// private key.
func AuthKeyFromFile(filename string) (*ecdsa.PrivateKey, error) {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
Expand All @@ -50,6 +51,7 @@ func AuthKeyFromFile(filename string) (*ecdsa.PrivateKey, error) {
}

// AuthKeyFromBytes loads a .p8 certificate from an in memory byte array and
// returns a private key.
func AuthKeyFromBytes(bytes []byte) (*ecdsa.PrivateKey, error) {
block, _ := pem.Decode(bytes)
if block == nil {
Expand Down
14 changes: 10 additions & 4 deletions buford/token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"errors"
"io/ioutil"
"runtime"
"testing"
"time"

Expand All @@ -27,9 +27,15 @@ func TestValidTokenFromP8Bytes(t *testing.T) {
}

func TestNoSuchFileP8File(t *testing.T) {
token, err := token.AuthKeyFromFile("")
assert.Equal(t, errors.New("open : no such file or directory").Error(), err.Error())
assert.Nil(t, token)
// assume *nix 'system file not found' error is returned by default.
expected := "open : no such file or directory"
if runtime.GOOS == "windows" {
expected = "open : The system cannot find the file specified."
}

privateKey, err := token.AuthKeyFromFile("")
assert.Equal(t, expected, err.Error())
assert.Nil(t, privateKey)
}

func TestInvalidP8File(t *testing.T) {
Expand Down
11 changes: 10 additions & 1 deletion gaurun/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gaurun
import (
"net/http"
"net/url"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -31,8 +32,16 @@ func TestRegisterHandlers(t *testing.T) {
func TestGetListener(t *testing.T) {
validConfigs := []ConfToml{
{Core: SectionCore{Port: "8080"}},
{Core: SectionCore{Port: "unix:/tmp/gaurun.sock"}},
}

if runtime.GOOS != "windows" {
// Only provide a config with a unix socket if *nix based.
validConfigs = append(
validConfigs,
ConfToml{Core: SectionCore{Port: "unix:/tmp/gaurun.sock"}},
)
}

invalidConfigs := []ConfToml{
// port is empty
{},
Expand Down