Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/command/workdir/backend_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
version "github.com/hashicorp/terraform/version"
)

func TestParseBackendStateFile(t *testing.T) {
Expand Down Expand Up @@ -152,7 +153,7 @@ func TestParseBackendStateFile(t *testing.T) {
}

func TestEncodeBackendStateFile(t *testing.T) {

tfVersion := version.Version
tests := map[string]struct {
Input *BackendStateFile
Want []byte
Expand All @@ -167,11 +168,11 @@ func TestEncodeBackendStateFile(t *testing.T) {
Hash: 123,
},
},
Want: []byte("{\n \"version\": 3,\n \"terraform_version\": \"1.13.0\",\n \"state_store\": {\n \"type\": \"foobar_baz\",\n \"provider\": {\n \"version\": \"1.2.3\",\n \"source\": \"registry.terraform.io/my-org/foobar\",\n \"config\": {\n \"foo\": \"bar\"\n }\n },\n \"config\": {\n \"foo\": \"bar\"\n },\n \"hash\": 123\n }\n}"),
Want: []byte("{\n \"version\": 3,\n \"terraform_version\": \"" + tfVersion + "\",\n \"state_store\": {\n \"type\": \"foobar_baz\",\n \"provider\": {\n \"version\": \"1.2.3\",\n \"source\": \"registry.terraform.io/my-org/foobar\",\n \"config\": {\n \"foo\": \"bar\"\n }\n },\n \"config\": {\n \"foo\": \"bar\"\n },\n \"hash\": 123\n }\n}"),
},
"it returns an error when neither backend nor state_store config state are present": {
Input: &BackendStateFile{},
Want: []byte("{\n \"version\": 3,\n \"terraform_version\": \"1.13.0\"\n}"),
Want: []byte("{\n \"version\": 3,\n \"terraform_version\": \"" + tfVersion + "\"\n}"),
},
"it returns an error when the provider source's hostname is missing": {
Input: &BackendStateFile{
Expand Down