2014-10-10 18:20:42 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2015-02-23 12:20:40 -06:00
|
|
|
"path/filepath"
|
2014-10-10 18:20:42 -05:00
|
|
|
"testing"
|
|
|
|
|
2015-02-23 12:20:40 -06:00
|
|
|
"github.com/hashicorp/terraform/state"
|
2014-10-10 18:20:42 -05:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Test disabling remote management
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_disable(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
// Create remote state file, this should be pulled
|
|
|
|
s := terraform.NewState()
|
|
|
|
s.Serial = 10
|
|
|
|
conf, srv := testRemoteState(t, s, 200)
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
// Persist local remote state
|
|
|
|
s = terraform.NewState()
|
|
|
|
s.Serial = 5
|
|
|
|
s.Remote = conf
|
2015-02-23 12:36:31 -06:00
|
|
|
|
|
|
|
// Write the state
|
|
|
|
statePath := filepath.Join(tmp, DefaultDataDir, DefaultStateFilename)
|
|
|
|
state := &state.LocalState{Path: statePath}
|
|
|
|
if err := state.WriteState(s); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
if err := state.PersistState(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
args := []string{"-disable"}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2015-02-23 12:36:31 -06:00
|
|
|
// Local state file should be removed and the local cache should exist
|
|
|
|
testRemoteLocal(t, true)
|
|
|
|
testRemoteLocalCache(t, false)
|
2014-10-10 18:20:42 -05:00
|
|
|
|
|
|
|
// Check that the state file was updated
|
|
|
|
raw, _ := ioutil.ReadFile(DefaultStateFilename)
|
|
|
|
newState, err := terraform.ReadState(bytes.NewReader(raw))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure we updated
|
|
|
|
if newState.Remote != nil {
|
|
|
|
t.Fatalf("remote configuration not removed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test disabling remote management without pulling
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_disable_noPull(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
// Create remote state file, this should be pulled
|
|
|
|
s := terraform.NewState()
|
|
|
|
s.Serial = 10
|
|
|
|
conf, srv := testRemoteState(t, s, 200)
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
// Persist local remote state
|
|
|
|
s = terraform.NewState()
|
|
|
|
s.Serial = 5
|
|
|
|
s.Remote = conf
|
2015-02-23 12:20:40 -06:00
|
|
|
|
|
|
|
// Write the state
|
|
|
|
statePath := filepath.Join(tmp, DefaultDataDir, DefaultStateFilename)
|
|
|
|
state := &state.LocalState{Path: statePath}
|
|
|
|
if err := state.WriteState(s); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:20:40 -06:00
|
|
|
if err := state.PersistState(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
args := []string{"-disable", "-pull=false"}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2015-02-23 12:36:31 -06:00
|
|
|
// Local state file should be removed and the local cache should exist
|
|
|
|
testRemoteLocal(t, true)
|
|
|
|
testRemoteLocalCache(t, false)
|
2014-10-10 18:20:42 -05:00
|
|
|
|
|
|
|
// Check that the state file was updated
|
|
|
|
raw, _ := ioutil.ReadFile(DefaultStateFilename)
|
|
|
|
newState, err := terraform.ReadState(bytes.NewReader(raw))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if newState.Remote != nil {
|
|
|
|
t.Fatalf("remote configuration not removed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test disabling remote management when not enabled
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_disable_notEnabled(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{"-disable"}
|
|
|
|
if code := c.Run(args); code != 1 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test disabling remote management with a state file in the way
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_disable_otherState(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
// Persist local remote state
|
|
|
|
s := terraform.NewState()
|
|
|
|
s.Serial = 5
|
2015-02-23 12:36:31 -06:00
|
|
|
|
|
|
|
// Write the state
|
|
|
|
statePath := filepath.Join(tmp, DefaultDataDir, DefaultStateFilename)
|
|
|
|
state := &state.LocalState{Path: statePath}
|
|
|
|
if err := state.WriteState(s); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
if err := state.PersistState(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Also put a file at the default path
|
|
|
|
fh, err := os.Create(DefaultStateFilename)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
err = terraform.WriteState(s, fh)
|
|
|
|
fh.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{"-disable"}
|
|
|
|
if code := c.Run(args); code != 1 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the case where both managed and non managed state present
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_managedAndNonManaged(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
// Persist local remote state
|
|
|
|
s := terraform.NewState()
|
|
|
|
s.Serial = 5
|
2015-02-23 12:36:31 -06:00
|
|
|
|
|
|
|
// Write the state
|
|
|
|
statePath := filepath.Join(tmp, DefaultDataDir, DefaultStateFilename)
|
|
|
|
state := &state.LocalState{Path: statePath}
|
|
|
|
if err := state.WriteState(s); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
if err := state.PersistState(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Also put a file at the default path
|
|
|
|
fh, err := os.Create(DefaultStateFilename)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
err = terraform.WriteState(s, fh)
|
|
|
|
fh.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{}
|
|
|
|
if code := c.Run(args); code != 1 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test initializing blank state
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_initBlank(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
2014-12-04 21:12:53 -06:00
|
|
|
"-backend=http",
|
2015-02-23 12:58:39 -06:00
|
|
|
"-backend-config", "address=http://example.com",
|
|
|
|
"-backend-config", "access_token=test",
|
2015-03-26 20:14:24 -05:00
|
|
|
"-pull=false",
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2015-02-23 12:36:31 -06:00
|
|
|
remotePath := filepath.Join(DefaultDataDir, DefaultStateFilename)
|
|
|
|
ls := &state.LocalState{Path: remotePath}
|
|
|
|
if err := ls.RefreshState(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
|
2015-02-23 12:36:31 -06:00
|
|
|
local := ls.State()
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Type != "http" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Config["address"] != "http://example.com" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Config["access_token"] != "test" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test initializing without remote settings
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_initBlank_missingRemote(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{}
|
|
|
|
if code := c.Run(args); code != 1 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test updating remote config
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_updateRemote(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
// Persist local remote state
|
|
|
|
s := terraform.NewState()
|
|
|
|
s.Serial = 5
|
|
|
|
s.Remote = &terraform.RemoteState{
|
2014-12-04 21:12:53 -06:00
|
|
|
Type: "invalid",
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
|
|
|
|
// Write the state
|
|
|
|
statePath := filepath.Join(tmp, DefaultDataDir, DefaultStateFilename)
|
|
|
|
ls := &state.LocalState{Path: statePath}
|
|
|
|
if err := ls.WriteState(s); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
if err := ls.PersistState(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
2014-12-04 21:12:53 -06:00
|
|
|
"-backend=http",
|
2015-02-23 12:58:39 -06:00
|
|
|
"-backend-config", "address=http://example.com",
|
|
|
|
"-backend-config", "access_token=test",
|
2015-03-26 20:14:24 -05:00
|
|
|
"-pull=false",
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2015-02-23 12:36:31 -06:00
|
|
|
remotePath := filepath.Join(DefaultDataDir, DefaultStateFilename)
|
|
|
|
ls = &state.LocalState{Path: remotePath}
|
|
|
|
if err := ls.RefreshState(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
local := ls.State()
|
2014-10-10 18:20:42 -05:00
|
|
|
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Type != "http" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Config["address"] != "http://example.com" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Config["access_token"] != "test" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test enabling remote state
|
2015-03-04 18:17:30 -06:00
|
|
|
func TestRemoteConfig_enableRemote(t *testing.T) {
|
2014-10-10 18:20:42 -05:00
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
// Create a non-remote enabled state
|
|
|
|
s := terraform.NewState()
|
|
|
|
s.Serial = 5
|
|
|
|
|
|
|
|
// Add the state at the default path
|
|
|
|
fh, err := os.Create(DefaultStateFilename)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
err = terraform.WriteState(s, fh)
|
|
|
|
fh.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
2015-03-04 18:17:30 -06:00
|
|
|
c := &RemoteConfigCommand{
|
2014-10-10 18:20:42 -05:00
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
2014-12-04 21:12:53 -06:00
|
|
|
"-backend=http",
|
2015-02-23 12:58:39 -06:00
|
|
|
"-backend-config", "address=http://example.com",
|
|
|
|
"-backend-config", "access_token=test",
|
2015-03-26 20:14:24 -05:00
|
|
|
"-pull=false",
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
2015-02-23 12:36:31 -06:00
|
|
|
remotePath := filepath.Join(DefaultDataDir, DefaultStateFilename)
|
|
|
|
ls := &state.LocalState{Path: remotePath}
|
|
|
|
if err := ls.RefreshState(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
local := ls.State()
|
2014-10-10 18:20:42 -05:00
|
|
|
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Type != "http" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Config["address"] != "http://example.com" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
2014-12-04 21:12:53 -06:00
|
|
|
if local.Remote.Config["access_token"] != "test" {
|
2014-10-10 18:20:42 -05:00
|
|
|
t.Fatalf("Bad: %#v", local.Remote)
|
|
|
|
}
|
|
|
|
|
2015-02-23 12:36:31 -06:00
|
|
|
// Backup file should exist, state file should not
|
|
|
|
testRemoteLocal(t, false)
|
|
|
|
testRemoteLocalBackup(t, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRemoteLocal(t *testing.T, exists bool) {
|
|
|
|
_, err := os.Stat(DefaultStateFilename)
|
|
|
|
if os.IsNotExist(err) && !exists {
|
|
|
|
return
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
if err == nil && exists {
|
|
|
|
return
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
|
|
|
|
2015-02-23 12:36:31 -06:00
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRemoteLocalBackup(t *testing.T, exists bool) {
|
2015-09-11 13:56:20 -05:00
|
|
|
_, err := os.Stat(DefaultStateFilename + DefaultBackupExtension)
|
2015-02-23 12:36:31 -06:00
|
|
|
if os.IsNotExist(err) && !exists {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err == nil && exists {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err == nil && !exists {
|
|
|
|
t.Fatal("expected local backup to exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRemoteLocalCache(t *testing.T, exists bool) {
|
|
|
|
_, err := os.Stat(filepath.Join(DefaultDataDir, DefaultStateFilename))
|
|
|
|
if os.IsNotExist(err) && !exists {
|
|
|
|
return
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
if err == nil && exists {
|
|
|
|
return
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|
2015-02-23 12:36:31 -06:00
|
|
|
if err == nil && !exists {
|
|
|
|
t.Fatal("expected local cache to exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", err)
|
2014-10-10 18:20:42 -05:00
|
|
|
}
|