Skip to content

Commit

Permalink
Merge pull request #43 from maxmind/greg/test-on-windows
Browse files Browse the repository at this point in the history
Test on Windows
  • Loading branch information
horgh authored Sep 12, 2019
2 parents ad21829 + 1ca0009 commit 66a0490
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 39 deletions.
32 changes: 21 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
language: go

matrix:
include:
- go: "1.10.x"
- go: "1.11.x"
- go: "1.12.x"
- go: "1.13.x"
os:
- linux
- osx
- windows

go:
- "1.10.x"
- "1.11.x"
- "1.12.x"
- "1.13.x"

install:
- go get -t ./...
- "curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin"

script:
- go test -race
- golangci-lint run
before_script:
- |
if [[ $TRAVIS_GO_VERSION == '1.13.x' && $TRAVIS_OS_NAME == 'linux' ]]; then
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin
fi
script: go test -v ./...
script:
- go test -v -race ./...
- |
if [[ $TRAVIS_GO_VERSION == '1.13.x' && $TRAVIS_OS_NAME == 'linux' ]]; then
golangci-lint run
fi
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## 4.0.5

* Ignore errors when syncing file system. These errors were primarily due
to the file system not supporting the sync call. Reported by devkappa.
GitHub #37.
* Use CRLF line endings on Windows for text files.
* Fix tests on Windows.

## 4.0.4 (2019-08-30)

* Do not try to sync the database directory when running on Windows.
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ DATADIR=/usr/local/share/GeoIP
endif
endif

ifeq ($(OS),Windows_NT)
MAYBE_CR=\r
endif

ifndef VERSION
VERSION=unknown
endif
Expand All @@ -41,13 +45,13 @@ $(BUILDDIR)/geoipupdate: $(BUILDDIR)
cp cmd/geoipupdate/geoipupdate $(BUILDDIR)

$(BUILDDIR)/GeoIP.conf: $(BUILDDIR) conf/GeoIP.conf.default
sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' conf/GeoIP.conf.default > $(BUILDDIR)/GeoIP.conf
sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' -e 's|$$|$(MAYBE_CR)|g' conf/GeoIP.conf.default > $(BUILDDIR)/GeoIP.conf

$(BUILDDIR)/GeoIP.conf.md: $(BUILDDIR) doc/GeoIP.conf.md
sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' doc/GeoIP.conf.md > $(BUILDDIR)/GeoIP.conf.md
sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' -e 's|$$|$(MAYBE_CR)|g' doc/GeoIP.conf.md > $(BUILDDIR)/GeoIP.conf.md

$(BUILDDIR)/geoipupdate.md: $(BUILDDIR) doc/geoipupdate.md
sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' doc/geoipupdate.md > $(BUILDDIR)/geoipupdate.md
sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' -e 's|$$|$(MAYBE_CR)|g' doc/geoipupdate.md > $(BUILDDIR)/geoipupdate.md

$(BUILDDIR)/GeoIP.conf.5: $(BUILDDIR)/GeoIP.conf.md $(BUILDDIR)/geoipupdate.md
dev-bin/make-man-pages.pl "$(BUILDDIR)"
Expand Down
8 changes: 4 additions & 4 deletions cmd/geoipupdate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewConfig( // nolint: gocyclo
keysSeen["AccountID"] = struct{}{}
keysSeen["UserId"] = struct{}{}
case "DatabaseDirectory":
config.DatabaseDirectory = value
config.DatabaseDirectory = filepath.Clean(value)
case "EditionIDs", "ProductIds":
config.EditionIDs = strings.Fields(value)
keysSeen["EditionIDs"] = struct{}{}
Expand All @@ -84,7 +84,7 @@ func NewConfig( // nolint: gocyclo
case "LicenseKey":
config.LicenseKey = value
case "LockFile":
config.LockFile = value
config.LockFile = filepath.Clean(value)
case "PreserveFileTimes":
if value != "0" && value != "1" {
return nil, errors.New("`PreserveFileTimes' must be 0 or 1")
Expand Down Expand Up @@ -132,11 +132,11 @@ func NewConfig( // nolint: gocyclo

// Argument takes precedence.
if databaseDirectory != "" {
config.DatabaseDirectory = databaseDirectory
config.DatabaseDirectory = filepath.Clean(databaseDirectory)
}

if config.DatabaseDirectory == "" {
config.DatabaseDirectory = defaultDatabaseDirectory
config.DatabaseDirectory = filepath.Clean(defaultDatabaseDirectory)
}

if host == "" {
Expand Down
41 changes: 21 additions & 20 deletions cmd/geoipupdate/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"net/url"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -60,9 +61,9 @@ EditionIDs GeoLite2-Country GeoLite2-City
# LockFile DATADIR/.geoipupdate.lock
`,
Output: &Config{
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoLite2-Country", "GeoLite2-City"},
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand Down Expand Up @@ -109,9 +110,9 @@ ProductIds GeoLite2-Country GeoLite2-City
# LockFile DATADIR/.geoipupdate.lock
`,
Output: &Config{
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoLite2-Country", "GeoLite2-City"},
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand Down Expand Up @@ -159,10 +160,10 @@ LockFile /usr/lock
`,
Output: &Config{
AccountID: 1234,
DatabaseDirectory: "/tmp", // Argument takes precedence
DatabaseDirectory: filepath.Clean("/tmp"), // Argument takes precedence
EditionIDs: []string{"GeoLite2-Country", "GeoLite2-City", "GeoIP2-City"},
LicenseKey: "abcdefghi",
LockFile: "/usr/lock",
LockFile: filepath.Clean("/usr/lock"),
Proxy: &url.URL{
Scheme: "http",
User: url.UserPassword("username", "password"),
Expand Down Expand Up @@ -237,9 +238,9 @@ EditionIDs GeoIP2-City`,
LicenseKey 000000000000
EditionIDs GeoIP2-City`,
Output: &Config{
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoIP2-City"},
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand All @@ -249,9 +250,9 @@ EditionIDs GeoIP2-City`,
LicenseKey 000000000000
EditionIDs GeoIP2-City`,
Output: &Config{
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoIP2-City"},
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand All @@ -262,10 +263,10 @@ LicenseKey abcd
EditionIDs GeoIP2-City`,
Output: &Config{
AccountID: 999999,
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoIP2-City"},
LicenseKey: "abcd",
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand All @@ -280,10 +281,10 @@ SkipPeerVerification 1
`,
Output: &Config{
AccountID: 123,
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoIP2-City"},
LicenseKey: "abcd",
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand All @@ -292,10 +293,10 @@ SkipPeerVerification 1
Input: "AccountID 123\r\nLicenseKey 123\r\nEditionIDs GeoIP2-City\r\n",
Output: &Config{
AccountID: 123,
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoIP2-City"},
LicenseKey: "123",
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand All @@ -312,10 +313,10 @@ EditionIDs GeoLite2-City GeoLite2-Country
`,
Output: &Config{
AccountID: 123,
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoLite2-City", "GeoLite2-Country"},
LicenseKey: "456",
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand All @@ -324,10 +325,10 @@ EditionIDs GeoLite2-City GeoLite2-Country
Input: "AccountID\t123\nLicenseKey\t\t456\nEditionIDs\t\t\tGeoLite2-City\t\t\t\tGeoLite2-Country\t\t\t\t\n",
Output: &Config{
AccountID: 123,
DatabaseDirectory: "/tmp",
DatabaseDirectory: filepath.Clean("/tmp"),
EditionIDs: []string{"GeoLite2-City", "GeoLite2-Country"},
LicenseKey: "456",
LockFile: "/tmp/.geoipupdate.lock",
LockFile: filepath.Clean("/tmp/.geoipupdate.lock"),
URL: "https://updates.maxmind.com",
},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/geoipupdate/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestUpdateEdition(t *testing.T) {
FilenameBody: "GeoIP2-City.mmdb",
DownloadStatus: http.StatusOK,
DownloadBody: "new database goes here",
Err: `error updating: error creating file: open \S+GeoIP2-City\.mmdb\.test: no such file or directory`,
Err: `error updating: error creating file: open \S+GeoIP2-City\.mmdb\.test: (?:no such file or directory|The system cannot find the path specified)`,
},
{
Description: "Download fails because provided checksum does not match",
Expand Down

0 comments on commit 66a0490

Please sign in to comment.