package main

import (
	"bytes"
	"github.com/mitchellh/packer/packer"
	"testing"
)

// This is totally not isolated from the filesystem
func TestUpdateJsonFileWithString(t *testing.T) {
	file := "/tmp/testpathstring.json"
	paths := []string{"testpathstring"}
	ui := &packer.BasicUi{
		Reader:      new(bytes.Buffer),
		Writer:      new(bytes.Buffer),
		ErrorWriter: new(bytes.Buffer),
	}
	value := "simplevalue_string"
	_ = UpdateJsonFile(file, paths, value, ui, true)
}

func TestUpdateJsonFileWithMap(t *testing.T) {
	file := "/tmp/testpathmap.json"
	paths := []string{"testpathmap"}
	ui := &packer.BasicUi{
		Reader:      new(bytes.Buffer),
		Writer:      new(bytes.Buffer),
		ErrorWriter: new(bytes.Buffer),
	}
	value := map[string]string{"us-east-1": "ami-123456"}
	_ = UpdateJsonFile(file, paths, value, ui, true)
}

package main

import (
	"bytes"
	"testing"

	"github.com/mitchellh/packer/packer"
	"github.com/stretchr/testify/assert"
)

func TestUpdateJSONFileShouldGiveErrorWhenFileDoesNotExist(t *testing.T) {
	file := "testdata/some_inexisting_file.json"
	paths := []string{"some.path.foo.bar"}
	ui := &packer.BasicUi{
		Reader:      new(bytes.Buffer),
		Writer:      new(bytes.Buffer),
		ErrorWriter: new(bytes.Buffer),
	}
	value := "ami-12345"
	err := UpdateJSONFile(file, paths, value, ui)
	assert.Equal(t, err.Error(), "open testdata/some_inexisting_file.json: no such file or directory")
}

Update test to reflect multi-region revert.
Update test to reflect multi-region revert.
