Skip to content

Commit

Permalink
add pkg test and move bin/main.go to root
Browse files Browse the repository at this point in the history
also reports correct version symbol to goreleaser
  • Loading branch information
displague committed Aug 12, 2020
1 parent c53d799 commit 7ee5b7f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ jobs:
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.30
test:
name: test
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.14' ]
steps:
- uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
- run: go test -v ./...
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ builds:
- CGO_ENABLED=0
- GO111MODULE=on
binary: docker-machine-driver-packet
ldflags:
- -X github.com/packethost/docker-machine-driver-packet/pkg/drivers/packet/packet.version={{.Version}}
goos:
- windows
- darwin
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ containerbuild:
make build

clean:
rm -r bin/docker-machine*
rm -r docker-machine-driver-packet bin/docker-machine-driver-packet

compile:
GO111MODULE=on GOGC=off CGOENABLED=0 go build -ldflags "-s" -o bin/$(current_dir)$(BIN_SUFFIX)/$(current_dir) ./bin/...
GO111MODULE=on GOGC=off CGOENABLED=0 go build -ldflags "-s"

# deprecated in favor of goreleaser
pack: cross
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/packethost/packngo v0.2.0
github.com/pkg/errors v0.8.1 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect
gotest.tools v2.2.0+incompatible // indirect
Expand Down
2 changes: 1 addition & 1 deletion bin/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package main

import (
"github.com/docker/machine/libmachine/drivers/plugin"
packet "github.com/packethost/docker-machine-driver-packet"
packet "github.com/packethost/docker-machine-driver-packet/pkg/drivers/packet"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion driver.go → pkg/drivers/packet/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
mcnflag.StringFlag{
EnvVar: "PACKET_UA_PREFIX",
Name: "packet-ua-prefix",
Usage: fmt.Sprintf("Prefix the User-Agent in Packet API calls with some 'product/version'"),
Usage: "Prefix the User-Agent in Packet API calls with some 'product/version'",
},
}
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/drivers/packet/packet_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package packet

import (
"testing"

"github.com/docker/machine/libmachine/drivers"
"github.com/stretchr/testify/assert"
)

func TestSetConfigFromFlags(t *testing.T) {
driver := NewDriver("", "")

checkFlags := &drivers.CheckDriverOptions{
FlagsValues: map[string]interface{}{
"packet-api-key": "APIKEY",
"packet-project-id": "PROJECT",
},
CreateFlags: driver.GetCreateFlags(),
}

err := driver.SetConfigFromFlags(checkFlags)

assert.NoError(t, err)
assert.Empty(t, checkFlags.InvalidFlags)
}

0 comments on commit 7ee5b7f

Please sign in to comment.