Skip to content

Commit

Permalink
fix: proper default 2.x config filename
Browse files Browse the repository at this point in the history
  • Loading branch information
alespour authored and stuartcarnie committed Oct 20, 2020
1 parent b63bcb4 commit 6a43939
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cmd/influxd/upgrade/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func upgradeConfig(configFile string, targetOptions optionsV2, log *zap.Logger)
cu.updateV2Config(cTransformed, targetOptions)

// save new config
configFileV2 := strings.TrimSuffix(configFile, filepath.Ext(configFile)) + ".toml"
configFileV2 := filepath.Join(filepath.Dir(configFile), "config.toml")
configFileV2, err = cu.save(cTransformed, configFileV2)
if err != nil {
return nil, err
Expand Down
33 changes: 8 additions & 25 deletions cmd/influxd/upgrade/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,16 @@ package upgrade

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/BurntSushi/toml"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)

func testCreateTempFile(t *testing.T, pattern, content string) string {
f, err := ioutil.TempFile("", pattern)
if err != nil {
t.Fatal(err)
}
_, err = f.WriteString(content)
if err != nil {
t.Fatal(err)
}
if err = f.Close(); err != nil {
t.Fatal(err)
}

return f.Name()
}

func TestConfigUpgrade(t *testing.T) {
targetOtions := optionsV2{
boltPath: "/db/.influxdbv2/influxd.bolt",
Expand Down Expand Up @@ -79,13 +63,12 @@ func TestConfigUpgrade(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
configFile := testCreateTempFile(t, "influxdb-*.conf", tc.config1x)
configFileV2 := strings.TrimSuffix(configFile, filepath.Ext(configFile)) + ".toml"
defer func() {
os.Remove(configFile)
os.Remove(configFileV2)
}()
retval, err := upgradeConfig(configFile, targetOtions, zap.NewNop())
tmpdir := t.TempDir()
configFile := filepath.Join(tmpdir, "influxdb.conf")
configFileV2 := filepath.Join(filepath.Dir(configFile), "config.toml")
err := ioutil.WriteFile(configFile, []byte(tc.config1x), 0444)
require.NoError(t, err)
retval, err := upgradeConfig(configFile, targetOtions, zaptest.NewLogger(t))
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 6a43939

Please sign in to comment.