mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-22 21:02:08 -04:00
Add Env and SetEnv methods to command.Meta to retrieve the current environment name inside any command. Make sure all calls to Backend.State contain an environment name, and make the package compile against the update backend package.
42 lines
819 B
Go
42 lines
819 B
Go
package command
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
func TestStatePull(t *testing.T) {
|
|
tmp, cwd := testCwd(t)
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
// Create some legacy remote state
|
|
legacyState := testState()
|
|
_, srv := testRemoteState(t, legacyState, 200)
|
|
defer srv.Close()
|
|
testStateFileRemote(t, legacyState)
|
|
|
|
p := testProvider()
|
|
ui := new(cli.MockUi)
|
|
c := &StatePullCommand{
|
|
StateMeta: StateMeta{
|
|
Meta: Meta{
|
|
ContextOpts: testCtxConfig(p),
|
|
Ui: ui,
|
|
},
|
|
},
|
|
}
|
|
|
|
args := []string{}
|
|
if code := c.Run(args); code != 0 {
|
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
|
}
|
|
|
|
expected := "test_instance.foo"
|
|
actual := ui.OutputWriter.String()
|
|
if !strings.Contains(actual, expected) {
|
|
t.Fatalf("expected:\n%s\n\nto include: %q", actual, expected)
|
|
}
|
|
}
|