command: compilation works

This still isn't ready. But this gets tests passing and compilation
working
This commit is contained in:
Mitchell Hashimoto 2016-05-10 17:03:58 -07:00
parent 9ddf73ad81
commit f34ef1f92a
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
5 changed files with 33 additions and 16 deletions

View File

@ -224,21 +224,7 @@ func testProvider() *terraform.MockResourceProvider {
} }
func testTempFile(t *testing.T) string { func testTempFile(t *testing.T) string {
tf, err := ioutil.TempFile("", "tf") return filepath.Join(testTempDir(t), "state.tfstate")
if err != nil {
t.Fatalf("err: %s", err)
}
result := tf.Name()
if err := tf.Close(); err != nil {
t.Fatalf("err: %s", err)
}
if err := os.Remove(result); err != nil {
t.Fatalf("err: %s", err)
}
return result
} }
func testTempDir(t *testing.T) string { func testTempDir(t *testing.T) string {

View File

@ -108,6 +108,9 @@ func TestPlan_destroy(t *testing.T) {
} }
func TestPlan_noState(t *testing.T) { func TestPlan_noState(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &PlanCommand{ c := &PlanCommand{

View File

@ -3,12 +3,18 @@ package command
import ( import (
"errors" "errors"
"github.com/hashicorp/terraform/state"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
// StateMeta is the meta struct that should be embedded in state subcommands. // StateMeta is the meta struct that should be embedded in state subcommands.
type StateMeta struct{} type StateMeta struct{}
// State returns the state for this meta.
func (m *StateMeta) State(cm *Meta) (state.State, error) {
return cm.State()
}
// filterInstance filters a single instance out of filter results. // filterInstance filters a single instance out of filter results.
func (c *StateMeta) filterInstance(rs []*terraform.StateFilterResult) (*terraform.StateFilterResult, error) { func (c *StateMeta) filterInstance(rs []*terraform.StateFilterResult) (*terraform.StateFilterResult, error) {
var result *terraform.StateFilterResult var result *terraform.StateFilterResult

View File

@ -26,7 +26,7 @@ func (c *StateShowCommand) Run(args []string) int {
} }
args = cmdFlags.Args() args = cmdFlags.Args()
state, err := c.State() state, err := c.Meta.State()
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf(errStateLoadingState, err)) c.Ui.Error(fmt.Sprintf(errStateLoadingState, err))
return cli.RunResultHelp return cli.RunResultHelp

22
command/state_test.go Normal file
View File

@ -0,0 +1,22 @@
package command
import (
"path/filepath"
"sort"
"testing"
)
// testStateBackups returns the list of backups in order of creation
// (oldest first) in the given directory.
func testStateBackups(t *testing.T, dir string) []string {
// Find all the backups
list, err := filepath.Glob(filepath.Join(dir, "*"+DefaultBackupExtension))
if err != nil {
t.Fatalf("err: %s", err)
}
// Sort them which will put them naturally in the right order
sort.Strings(list)
return list
}