From 40556860d194e04d76ca275508a7e7e61ad07aa2 Mon Sep 17 00:00:00 2001 From: Stefan Sakalik Date: Thu, 25 Apr 2019 17:49:13 +0100 Subject: [PATCH] Add support for go modules. - create go.sum - do not use .. in filenames in this repo due to https://github.com/golang/go/issues/27299 Testing strategy: I almost successfully ran `test_all.sh` and found a data race, but I don't think it's related to this PR: ``` WARNING: DATA RACE Read at 0x00c00016cac0 by goroutine 29: github.com/spf13/pflag.(*FlagSet).VisitAll() /home/stefan/usr/go/main/pkg/mod/github.com/spf13/pflag@v1.0.3/flag.go:277 +0x14a github.com/mwitkow/go-flagz.ChecksumFlagSet() /home/stefan/Projects/go-flagz/checksum.go:15 +0xc8 github.com/mwitkow/go-flagz/monitoring.(*flagSetCollector).Collect() /home/stefan/Projects/go-flagz/monitoring/collector.go:57 +0x2a2 github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1() /home/stefan/usr/go/main/pkg/mod/github.com/prometheus/client_golang@v0.9.2/prometheus/registry.go:434 +0x1eb Previous write at 0x00c00016cac0 by goroutine 28: github.com/spf13/pflag.sortFlags() /home/stefan/usr/go/main/pkg/mod/github.com/spf13/pflag@v1.0.3/flag.go:204 +0x2f2 github.com/spf13/pflag.(*FlagSet).VisitAll() /home/stefan/usr/go/main/pkg/mod/github.com/spf13/pflag@v1.0.3/flag.go:270 +0x1b0 github.com/mwitkow/go-flagz.ChecksumFlagSet() /home/stefan/Projects/go-flagz/checksum.go:15 +0xc8 github.com/mwitkow/go-flagz/monitoring.(*flagSetCollector).Collect() /home/stefan/Projects/go-flagz/monitoring/collector.go:55 +0xe9 github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1() /home/stefan/usr/go/main/pkg/mod/github.com/prometheus/client_golang@v0.9.2/prometheus/registry.go:434 +0x1eb ``` --- configmap/testdata/..data | 1 - .../some_dynint | 0 .../some_int | 0 .../some_dynint | 0 .../some_int | 0 .../some_dynint | 0 .../some_int | 0 configmap/updater_test.go | 9 +++++++++ go.mod | 14 ++++++++++++++ 9 files changed, 23 insertions(+), 1 deletion(-) delete mode 120000 configmap/testdata/..data rename configmap/testdata/{..1289_09_10_03_32_32.039823124 => 1289_09_10_03_32_32.039823124}/some_dynint (100%) rename configmap/testdata/{..1289_09_10_03_32_32.039823124 => 1289_09_10_03_32_32.039823124}/some_int (100%) rename configmap/testdata/{..9289_09_10_03_32_32.039823124 => 9289_09_10_03_32_32.039823124}/some_dynint (100%) rename configmap/testdata/{..9289_09_10_03_32_32.039823124 => 9289_09_10_03_32_32.039823124}/some_int (100%) rename configmap/testdata/{..9989_09_09_07_32_32.099817316 => 9989_09_09_07_32_32.099817316}/some_dynint (100%) rename configmap/testdata/{..9989_09_09_07_32_32.099817316 => 9989_09_09_07_32_32.099817316}/some_int (100%) create mode 100644 go.mod diff --git a/configmap/testdata/..data b/configmap/testdata/..data deleted file mode 120000 index c6a3cbb..0000000 --- a/configmap/testdata/..data +++ /dev/null @@ -1 +0,0 @@ -..9989_09_09_07_32_32.099817316 \ No newline at end of file diff --git a/configmap/testdata/..1289_09_10_03_32_32.039823124/some_dynint b/configmap/testdata/1289_09_10_03_32_32.039823124/some_dynint similarity index 100% rename from configmap/testdata/..1289_09_10_03_32_32.039823124/some_dynint rename to configmap/testdata/1289_09_10_03_32_32.039823124/some_dynint diff --git a/configmap/testdata/..1289_09_10_03_32_32.039823124/some_int b/configmap/testdata/1289_09_10_03_32_32.039823124/some_int similarity index 100% rename from configmap/testdata/..1289_09_10_03_32_32.039823124/some_int rename to configmap/testdata/1289_09_10_03_32_32.039823124/some_int diff --git a/configmap/testdata/..9289_09_10_03_32_32.039823124/some_dynint b/configmap/testdata/9289_09_10_03_32_32.039823124/some_dynint similarity index 100% rename from configmap/testdata/..9289_09_10_03_32_32.039823124/some_dynint rename to configmap/testdata/9289_09_10_03_32_32.039823124/some_dynint diff --git a/configmap/testdata/..9289_09_10_03_32_32.039823124/some_int b/configmap/testdata/9289_09_10_03_32_32.039823124/some_int similarity index 100% rename from configmap/testdata/..9289_09_10_03_32_32.039823124/some_int rename to configmap/testdata/9289_09_10_03_32_32.039823124/some_int diff --git a/configmap/testdata/..9989_09_09_07_32_32.099817316/some_dynint b/configmap/testdata/9989_09_09_07_32_32.099817316/some_dynint similarity index 100% rename from configmap/testdata/..9989_09_09_07_32_32.099817316/some_dynint rename to configmap/testdata/9989_09_09_07_32_32.099817316/some_dynint diff --git a/configmap/testdata/..9989_09_09_07_32_32.099817316/some_int b/configmap/testdata/9989_09_09_07_32_32.099817316/some_int similarity index 100% rename from configmap/testdata/..9989_09_09_07_32_32.099817316/some_int rename to configmap/testdata/9989_09_09_07_32_32.099817316/some_int diff --git a/configmap/updater_test.go b/configmap/updater_test.go index f1c4d3b..528a8d0 100644 --- a/configmap/updater_test.go +++ b/configmap/updater_test.go @@ -4,6 +4,8 @@ package configmap_test import ( + "path/filepath" + "strings" "testing" "time" @@ -67,6 +69,13 @@ func (s *updaterTestSuite) TearDownTest() { func (s *updaterTestSuite) copyTestDataToDir() { copyCmd := exec.Command("cp", "--archive", "testdata", s.tempDir) require.NoError(s.T(), copyCmd.Run(), "copying testdata directory to tempdir must not fail") + // We are storing file testdata/9989_09_09_07_32_32.099817316 and renaming it to testdata/..9989_09_09_07_32_32.099817316, + // because go modules don't allow repos with files with .. in their filename. See https://github.com/golang/go/issues/27299. + for _, p := range []string{firstGoodDir, secondGoodDir, badStaticDir} { + pOld := filepath.Join(s.tempDir, "testdata", strings.TrimPrefix(p, "..")) + pNew := filepath.Join(s.tempDir, "testdata", p) + require.NoError(s.T(), os.Rename(pOld, pNew), "renaming %q to %q failed", pOld, pNew) + } } func (s *updaterTestSuite) linkDataDirTo(newDataDir string) { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2122a32 --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module github.com/mwitkow/go-flagz + +require ( + github.com/coreos/etcd v3.3.12+incompatible + github.com/coreos/go-semver v0.3.0 // indirect + github.com/fsnotify/fsnotify v1.4.7 + github.com/golang/protobuf v1.3.1 + github.com/prometheus/client_golang v0.9.2 + github.com/spf13/pflag v1.0.3 + github.com/stretchr/testify v1.3.0 + github.com/ugorji/go v1.1.4 // indirect + golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6 + golang.org/x/sys v0.0.0-20190425145619-16072639606e // indirect +)