fix: proper default 2.x config filename

pull/19784/head
Ales Pour 2020-10-20 12:06:25 +02:00 committed by Stuart Carnie
parent b63bcb43c4
commit 6a43939546
2 changed files with 9 additions and 26 deletions

View File

@ -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

View File

@ -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",
@ -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)
}