2023-04-26 18:16:42 +03:00
|
|
|
package v0_34_0_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-04-26 18:16:42 +03:00
|
|
|
"github.com/neilotoole/sq/cli"
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/neilotoole/sq/cli/config"
|
2023-04-26 18:16:42 +03:00
|
|
|
"github.com/neilotoole/sq/cli/config/yamlstore"
|
2024-01-15 04:45:34 +03:00
|
|
|
v0_34_0 "github.com/neilotoole/sq/cli/config/yamlstore/upgrades/v0.34.0" //nolint:revive
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/neilotoole/sq/cli/output/format"
|
|
|
|
"github.com/neilotoole/sq/libsq/core/lg"
|
2024-01-15 04:45:34 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/core/lg/lgt"
|
2023-04-26 18:16:42 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/core/options"
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/driver"
|
2024-01-25 09:29:55 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/source/drivertype"
|
2023-04-26 18:16:42 +03:00
|
|
|
"github.com/neilotoole/sq/testh"
|
2024-01-15 04:45:34 +03:00
|
|
|
"github.com/neilotoole/sq/testh/tu"
|
2023-04-26 18:16:42 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUpgrade(t *testing.T) {
|
2024-01-15 04:45:34 +03:00
|
|
|
log := lgt.New(t)
|
2023-04-26 18:16:42 +03:00
|
|
|
ctx := lg.NewContext(context.Background(), log)
|
|
|
|
|
|
|
|
const (
|
|
|
|
prevVers = "v0.33.0"
|
|
|
|
nextVers = "v0.34.0"
|
|
|
|
handlePg = "@prod/pg"
|
|
|
|
handleCSV = "@csv"
|
|
|
|
handleXLSX = "@xlsx"
|
|
|
|
)
|
|
|
|
|
|
|
|
testh.SetBuildVersion(t, nextVers)
|
|
|
|
|
|
|
|
// The sq.yml file in cfgDir is on v0.33.0
|
2024-01-30 05:34:10 +03:00
|
|
|
cfgDir := tu.DirCopy(t, "testdata")
|
2023-04-26 18:16:42 +03:00
|
|
|
t.Setenv(config.EnvarConfig, cfgDir)
|
|
|
|
|
|
|
|
cfgFilePath := filepath.Join(cfgDir, "sq.yml")
|
|
|
|
|
|
|
|
gotPrevVers, err := yamlstore.LoadVersionFromFile(cfgFilePath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, prevVers, gotPrevVers)
|
|
|
|
|
|
|
|
upgrades := yamlstore.UpgradeRegistry{
|
|
|
|
v0_34_0.Version: v0_34_0.Upgrade,
|
|
|
|
}
|
|
|
|
|
|
|
|
optsReg := &options.Registry{}
|
|
|
|
cli.RegisterDefaultOpts(optsReg)
|
|
|
|
|
|
|
|
cfg, cfgStore, err := yamlstore.Load(ctx, nil, optsReg, upgrades)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, cfgDir, cfgStore.Location())
|
|
|
|
require.Equal(t, nextVers, cfg.Version)
|
2023-05-07 05:36:34 +03:00
|
|
|
require.Equal(t, format.JSON, cli.OptFormat.Get(cfg.Options))
|
2023-05-22 18:08:14 +03:00
|
|
|
require.Equal(t, time.Second*100, cli.OptPingCmdTimeout.Get(cfg.Options))
|
2023-04-26 18:16:42 +03:00
|
|
|
require.Len(t, cfg.Collection.Sources(), 3)
|
|
|
|
src0 := cfg.Collection.Sources()[0]
|
|
|
|
require.Equal(t, handlePg, src0.Handle)
|
2024-01-25 09:29:55 +03:00
|
|
|
require.Equal(t, drivertype.Pg, src0.Type)
|
2023-04-26 18:16:42 +03:00
|
|
|
require.Equal(t, "prod", cfg.Collection.ActiveGroup())
|
|
|
|
require.NotNil(t, cfg.Collection.Active())
|
|
|
|
require.Equal(t, handlePg, cfg.Collection.Active().Handle)
|
|
|
|
|
|
|
|
src1 := cfg.Collection.Sources()[1]
|
|
|
|
require.Equal(t, handleCSV, src1.Handle)
|
2024-01-25 09:29:55 +03:00
|
|
|
require.Equal(t, drivertype.CSV, src1.Type)
|
2023-07-04 20:31:47 +03:00
|
|
|
require.Equal(t, true, src1.Options[driver.OptIngestHeader.Key()])
|
2023-04-26 18:16:42 +03:00
|
|
|
|
|
|
|
src2 := cfg.Collection.Sources()[2]
|
|
|
|
require.Equal(t, handleXLSX, src2.Handle)
|
2024-01-25 09:29:55 +03:00
|
|
|
require.Equal(t, drivertype.XLSX, src2.Type)
|
2023-07-04 20:31:47 +03:00
|
|
|
require.Equal(t, false, src2.Options[driver.OptIngestHeader.Key()])
|
2023-04-26 18:16:42 +03:00
|
|
|
|
|
|
|
wantCfgRaw, err := os.ReadFile(filepath.Join("testdata", "want.sq.yml"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
gotCfgRaw, err := os.ReadFile(filepath.Join(cfgDir, "sq.yml"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Logf("Output written to: %s", filepath.Join(cfgDir, "sq.yml"))
|
|
|
|
|
|
|
|
require.Equal(t, strings.TrimSpace(string(wantCfgRaw)), strings.TrimSpace(string(gotCfgRaw)))
|
|
|
|
}
|