fix: proper default 2.x config filename
parent
b63bcb43c4
commit
6a43939546
|
@ -83,7 +83,7 @@ func upgradeConfig(configFile string, targetOptions optionsV2, log *zap.Logger)
|
||||||
cu.updateV2Config(cTransformed, targetOptions)
|
cu.updateV2Config(cTransformed, targetOptions)
|
||||||
|
|
||||||
// save new config
|
// 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)
|
configFileV2, err = cu.save(cTransformed, configFileV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -2,32 +2,16 @@ package upgrade
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/zap"
|
"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) {
|
func TestConfigUpgrade(t *testing.T) {
|
||||||
targetOtions := optionsV2{
|
targetOtions := optionsV2{
|
||||||
boltPath: "/db/.influxdbv2/influxd.bolt",
|
boltPath: "/db/.influxdbv2/influxd.bolt",
|
||||||
|
@ -79,13 +63,12 @@ func TestConfigUpgrade(t *testing.T) {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
configFile := testCreateTempFile(t, "influxdb-*.conf", tc.config1x)
|
tmpdir := t.TempDir()
|
||||||
configFileV2 := strings.TrimSuffix(configFile, filepath.Ext(configFile)) + ".toml"
|
configFile := filepath.Join(tmpdir, "influxdb.conf")
|
||||||
defer func() {
|
configFileV2 := filepath.Join(filepath.Dir(configFile), "config.toml")
|
||||||
os.Remove(configFile)
|
err := ioutil.WriteFile(configFile, []byte(tc.config1x), 0444)
|
||||||
os.Remove(configFileV2)
|
require.NoError(t, err)
|
||||||
}()
|
retval, err := upgradeConfig(configFile, targetOtions, zaptest.NewLogger(t))
|
||||||
retval, err := upgradeConfig(configFile, targetOtions, zap.NewNop())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue