failing test for backend re-init

This commit is contained in:
James Bardin 2019-05-23 18:21:52 -04:00
parent c7c69a5e99
commit cefc927e48
3 changed files with 49 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package command package command
import ( import (
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
@ -410,6 +411,51 @@ func TestInit_backendConfigKV(t *testing.T) {
} }
} }
func TestInit_backendConfigKVReInit(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("init-backend-config-kv"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
ui := new(cli.MockUi)
c := &InitCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
},
}
args := []string{"-backend-config", "path=test"}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
ui = new(cli.MockUi)
c = &InitCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
},
}
// a second init should require no changes, nor should it change the backend.
args = []string{"-input=false"}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
// make sure the backend is configured how we expect
configState := testDataStateRead(t, filepath.Join(DefaultDataDir, DefaultStateFilename))
cfg := map[string]interface{}{}
if err := json.Unmarshal(configState.Backend.ConfigRaw, &cfg); err != nil {
t.Fatal(err)
}
if cfg["path"] != "test" {
t.Fatalf(`expected backend path="test", got path="%v"`, cfg["path"])
}
}
func TestInit_targetSubdir(t *testing.T) { func TestInit_targetSubdir(t *testing.T) {
// Create a temporary working directory that is empty // Create a temporary working directory that is empty
td := tempDir(t) td := tempDir(t)

View File

@ -823,6 +823,8 @@ func (m *Meta) backend_C_r_S_changed(c *configs.Backend, cHash int, sMgr *state.
return nil, diags return nil, diags
} }
fmt.Println("HERE")
// Perform the migration // Perform the migration
err := m.backendMigrateState(&backendMigrateOpts{ err := m.backendMigrateState(&backendMigrateOpts{
OneType: s.Backend.Type, OneType: s.Backend.Type,

View File

@ -98,6 +98,7 @@ func (m *Meta) backendMigrateState(opts *backendMigrateOpts) error {
// Multi-state to multi-state. We merge the states together (migrating // Multi-state to multi-state. We merge the states together (migrating
// each from the source to the destination one by one). // each from the source to the destination one by one).
case !oneSingle && !twoSingle: case !oneSingle && !twoSingle:
fmt.Printf("STATES: %q\n", oneStates)
// If the source only has one state and it is the default, // If the source only has one state and it is the default,
// treat it as if it doesn't support multi-state. // treat it as if it doesn't support multi-state.
if len(oneStates) == 1 && oneStates[0] == backend.DefaultStateName { if len(oneStates) == 1 && oneStates[0] == backend.DefaultStateName {