From 83b2c36e67df2f29ad164629657d0362dbe5a53d Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 26 Jul 2022 17:56:37 -0400 Subject: [PATCH 01/13] update structs --- state_version.go | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/state_version.go b/state_version.go index 39173aafb..28931c693 100644 --- a/state_version.go +++ b/state_version.go @@ -55,12 +55,18 @@ type StateVersionList struct { // StateVersion represents a Terraform Enterprise state version. type StateVersion struct { - ID string `jsonapi:"primary,state-versions"` - CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` - DownloadURL string `jsonapi:"attr,hosted-state-download-url"` - Serial int64 `jsonapi:"attr,serial"` - VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` - VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` + ID string `jsonapi:"primary,state-versions"` + CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` + DownloadURL string `jsonapi:"attr,hosted-state-download-url"` + Serial int64 `jsonapi:"attr,serial"` + VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` + VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` + ResourcesProcessed bool `jsonapi:"attr,resources-processed"` + StateVersion int `jsonapi:"attr,state-version"` + TerraformVersion string `jsonapi:"attr,terraform-version"` + Modules *StateVersionModules `jsonapi:"attr,modules"` + Providers *StateVersionProviders `jsonapi:"attr,providers"` + Resources []StateVersionResources `jsonapi:"attr,resources"` // Relations Run *Run `jsonapi:"relation,run"` @@ -139,7 +145,7 @@ type StateVersionCreateOptions struct { // Optional: Specifies the run to associate the state with. Run *Run `jsonapi:"relation,run,omitempty"` - // Optional: The external, json representation of state outputs, base64 encoded. Supplying this field + // Optional: The external, json representation of state outputs, base64 encoded. Supplying this field // will provide more detailed output type information to TFE. // For more information on the contents of this field: https://www.terraform.io/internals/json-format#values-representation // about the current terraform state. @@ -148,6 +154,23 @@ type StateVersionCreateOptions struct { JSONStateOutputs *string `jsonapi:"attr,json-state-outputs,omitempty"` } +type StateVersionNullResrouce int +type StateVersionTerraformRemoteState int + +type StateVersionModules struct{} + +type StateVersionProviders struct { + Provider StateVersionTerraformRemoteState `jsonapi:"attr,providers"` +} + +type StateVersionResources struct { + Name string `jsonapi:"attr,name"` + Count string `jsonapi:"attr,count"` + Type int `jsonapi:"attr,type"` + Module string `jsonapi:"attr,module"` + Provider string `jsonapi:"attr,name"` +} + // List all the state versions for a given workspace. func (s *stateVersions) List(ctx context.Context, options *StateVersionListOptions) (*StateVersionList, error) { if err := options.valid(); err != nil { From fce39e6f23679d00eb4904c4bd540f75cf15a23d Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 26 Jul 2022 19:01:07 -0400 Subject: [PATCH 02/13] refactor --- state_version.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/state_version.go b/state_version.go index 28931c693..f50587159 100644 --- a/state_version.go +++ b/state_version.go @@ -154,14 +154,11 @@ type StateVersionCreateOptions struct { JSONStateOutputs *string `jsonapi:"attr,json-state-outputs,omitempty"` } -type StateVersionNullResrouce int -type StateVersionTerraformRemoteState int - -type StateVersionModules struct{} +type StateVersionModules map[string]interface{} +type StateVersionProviders map[string]interface{} -type StateVersionProviders struct { - Provider StateVersionTerraformRemoteState `jsonapi:"attr,providers"` -} +type StateVersionNullResource int +type StateVersionTerraformRemoteState int type StateVersionResources struct { Name string `jsonapi:"attr,name"` From 19d2d11ca26a1d3f1d2d567d7073699d2d740a66 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 26 Jul 2022 19:28:37 -0400 Subject: [PATCH 03/13] remove api endpoints --- state_version.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/state_version.go b/state_version.go index f50587159..b167fbd85 100644 --- a/state_version.go +++ b/state_version.go @@ -161,11 +161,11 @@ type StateVersionNullResource int type StateVersionTerraformRemoteState int type StateVersionResources struct { - Name string `jsonapi:"attr,name"` - Count string `jsonapi:"attr,count"` - Type int `jsonapi:"attr,type"` - Module string `jsonapi:"attr,module"` - Provider string `jsonapi:"attr,name"` + Name string + Count string + Type int + Module string + Provider string } // List all the state versions for a given workspace. From db4b02763ca063ccdcc18920e61322d295d5b6a0 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 26 Jul 2022 20:16:37 -0400 Subject: [PATCH 04/13] resolve failing tests --- state_version.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/state_version.go b/state_version.go index b167fbd85..cbcfc709c 100644 --- a/state_version.go +++ b/state_version.go @@ -154,8 +154,8 @@ type StateVersionCreateOptions struct { JSONStateOutputs *string `jsonapi:"attr,json-state-outputs,omitempty"` } -type StateVersionModules map[string]interface{} -type StateVersionProviders map[string]interface{} +type StateVersionModules map[string]map[string]interface{} +type StateVersionProviders map[string]map[string]interface{} type StateVersionNullResource int type StateVersionTerraformRemoteState int From 5396ac141365d24470e0ee61c614546efe8a8cc4 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 26 Jul 2022 20:38:57 -0400 Subject: [PATCH 05/13] still erroring --- state_version.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/state_version.go b/state_version.go index cbcfc709c..7fea0c88f 100644 --- a/state_version.go +++ b/state_version.go @@ -154,8 +154,8 @@ type StateVersionCreateOptions struct { JSONStateOutputs *string `jsonapi:"attr,json-state-outputs,omitempty"` } -type StateVersionModules map[string]map[string]interface{} -type StateVersionProviders map[string]map[string]interface{} +type StateVersionModules struct{} +type StateVersionProviders struct{} type StateVersionNullResource int type StateVersionTerraformRemoteState int From 83bc01b506b16f98c3989d692f5cb928f75d86e0 Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 27 Jul 2022 13:03:50 -0400 Subject: [PATCH 06/13] suspect last push was false positive --- state_version.go | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/state_version.go b/state_version.go index 7fea0c88f..8fe1f6f6a 100644 --- a/state_version.go +++ b/state_version.go @@ -55,18 +55,18 @@ type StateVersionList struct { // StateVersion represents a Terraform Enterprise state version. type StateVersion struct { - ID string `jsonapi:"primary,state-versions"` - CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` - DownloadURL string `jsonapi:"attr,hosted-state-download-url"` - Serial int64 `jsonapi:"attr,serial"` - VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` - VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` - ResourcesProcessed bool `jsonapi:"attr,resources-processed"` - StateVersion int `jsonapi:"attr,state-version"` - TerraformVersion string `jsonapi:"attr,terraform-version"` - Modules *StateVersionModules `jsonapi:"attr,modules"` - Providers *StateVersionProviders `jsonapi:"attr,providers"` - Resources []StateVersionResources `jsonapi:"attr,resources"` + ID string `jsonapi:"primary,state-versions"` + CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` + DownloadURL string `jsonapi:"attr,hosted-state-download-url"` + Serial int64 `jsonapi:"attr,serial"` + VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` + VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` + ResourcesProcessed bool `jsonapi:"attr,resources-processed"` + StateVersion int `jsonapi:"attr,state-version"` + TerraformVersion string `jsonapi:"attr,terraform-version"` + Modules *StateVersionModules `jsonapi:"attr,modules"` + Providers *StateVersionProviders `jsonapi:"attr,providers"` + Resources []*StateVersionResources `jsonapi:"attr,resources"` // Relations Run *Run `jsonapi:"relation,run"` @@ -154,18 +154,23 @@ type StateVersionCreateOptions struct { JSONStateOutputs *string `jsonapi:"attr,json-state-outputs,omitempty"` } -type StateVersionModules struct{} -type StateVersionProviders struct{} +type StateVersionModules struct { + Root *StateVersionModuleRoot `jsonapi:"attr,root"` +} + +type StateVersionModuleRoot struct { + NullResource int `jsonapi:"attr,null-resource"` + TerraformRemoteState int `jsonapi:"attr,data.terraform-remote-state"` +} -type StateVersionNullResource int -type StateVersionTerraformRemoteState int +type StateVersionProviders map[string]struct{} type StateVersionResources struct { - Name string - Count string - Type int - Module string - Provider string + Name string `jsonapi:"attr,name"` + Count string `jsonapi:"attr,count"` + Type int `jsonapi:"attr,type"` + Module string `jsonapi:"attr,module"` + Provider string `jsonapi:"attr,provider"` } // List all the state versions for a given workspace. From 816b6fcd1ec6c3106363d80f7e2646278e924c58 Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 27 Jul 2022 13:53:15 -0400 Subject: [PATCH 07/13] testing state version integration test failures --- state_version.go | 65 ++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/state_version.go b/state_version.go index 8fe1f6f6a..237253452 100644 --- a/state_version.go +++ b/state_version.go @@ -55,18 +55,18 @@ type StateVersionList struct { // StateVersion represents a Terraform Enterprise state version. type StateVersion struct { - ID string `jsonapi:"primary,state-versions"` - CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` - DownloadURL string `jsonapi:"attr,hosted-state-download-url"` - Serial int64 `jsonapi:"attr,serial"` - VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` - VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` - ResourcesProcessed bool `jsonapi:"attr,resources-processed"` - StateVersion int `jsonapi:"attr,state-version"` - TerraformVersion string `jsonapi:"attr,terraform-version"` - Modules *StateVersionModules `jsonapi:"attr,modules"` - Providers *StateVersionProviders `jsonapi:"attr,providers"` - Resources []*StateVersionResources `jsonapi:"attr,resources"` + ID string `jsonapi:"primary,state-versions"` + CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` + DownloadURL string `jsonapi:"attr,hosted-state-download-url"` + Serial int64 `jsonapi:"attr,serial"` + VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` + VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` + ResourcesProcessed bool `jsonapi:"attr,resources-processed"` + StateVersion int `jsonapi:"attr,state-version"` + TerraformVersion string `jsonapi:"attr,terraform-version"` + // Modules *StateVersionModules `jsonapi:"attr,modules"` + // Providers *StateVersionProviders `jsonapi:"attr,providers"` + // Resources []*StateVersionResources `jsonapi:"attr,resources"` // Relations Run *Run `jsonapi:"relation,run"` @@ -154,24 +154,29 @@ type StateVersionCreateOptions struct { JSONStateOutputs *string `jsonapi:"attr,json-state-outputs,omitempty"` } -type StateVersionModules struct { - Root *StateVersionModuleRoot `jsonapi:"attr,root"` -} - -type StateVersionModuleRoot struct { - NullResource int `jsonapi:"attr,null-resource"` - TerraformRemoteState int `jsonapi:"attr,data.terraform-remote-state"` -} - -type StateVersionProviders map[string]struct{} - -type StateVersionResources struct { - Name string `jsonapi:"attr,name"` - Count string `jsonapi:"attr,count"` - Type int `jsonapi:"attr,type"` - Module string `jsonapi:"attr,module"` - Provider string `jsonapi:"attr,provider"` -} +// type StateVersionModules struct { +// Root *StateVersionModuleRoot `jsonapi:"attr,root"` +// } + +// type StateVersionModuleRoot struct { +// NullResource int `jsonapi:"attr,null-resource"` +// TerraformRemoteState int `jsonapi:"attr,data.terraform-remote-state"` +// } + +// type StateVersionProviders map[string]ProviderData + +// type ProviderData struct { +// NullResource int `json:"null-resource"` +// TerraformRemoteState int `json:"data.terraform-remote-state"` +// } + +// type StateVersionResources struct { +// Name string `jsonapi:"attr,name"` +// Count string `jsonapi:"attr,count"` +// Type int `jsonapi:"attr,type"` +// Module string `jsonapi:"attr,module"` +// Provider string `jsonapi:"attr,provider"` +// } // List all the state versions for a given workspace. func (s *stateVersions) List(ctx context.Context, options *StateVersionListOptions) (*StateVersionList, error) { From 559d6a09d6ee64c54d485337fa7d1611b163e43a Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 27 Jul 2022 14:16:11 -0400 Subject: [PATCH 08/13] testing theory that state ver integration tests are failing --- state_version.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/state_version.go b/state_version.go index 237253452..eaf44fa47 100644 --- a/state_version.go +++ b/state_version.go @@ -55,15 +55,15 @@ type StateVersionList struct { // StateVersion represents a Terraform Enterprise state version. type StateVersion struct { - ID string `jsonapi:"primary,state-versions"` - CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` - DownloadURL string `jsonapi:"attr,hosted-state-download-url"` - Serial int64 `jsonapi:"attr,serial"` - VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` - VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` - ResourcesProcessed bool `jsonapi:"attr,resources-processed"` - StateVersion int `jsonapi:"attr,state-version"` - TerraformVersion string `jsonapi:"attr,terraform-version"` + ID string `jsonapi:"primary,state-versions"` + CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` + DownloadURL string `jsonapi:"attr,hosted-state-download-url"` + Serial int64 `jsonapi:"attr,serial"` + VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` + VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` + // ResourcesProcessed bool `jsonapi:"attr,resources-processed"` + // StateVersion int `jsonapi:"attr,state-version"` + // TerraformVersion string `jsonapi:"attr,terraform-version"` // Modules *StateVersionModules `jsonapi:"attr,modules"` // Providers *StateVersionProviders `jsonapi:"attr,providers"` // Resources []*StateVersionResources `jsonapi:"attr,resources"` From 6de864ae6353fdbf46e0a7a9926bc557b348a54d Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 28 Jul 2022 07:01:34 -0400 Subject: [PATCH 09/13] commit --- state_version.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/state_version.go b/state_version.go index eaf44fa47..43beb530e 100644 --- a/state_version.go +++ b/state_version.go @@ -55,18 +55,18 @@ type StateVersionList struct { // StateVersion represents a Terraform Enterprise state version. type StateVersion struct { - ID string `jsonapi:"primary,state-versions"` - CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` - DownloadURL string `jsonapi:"attr,hosted-state-download-url"` - Serial int64 `jsonapi:"attr,serial"` - VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` - VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` - // ResourcesProcessed bool `jsonapi:"attr,resources-processed"` - // StateVersion int `jsonapi:"attr,state-version"` - // TerraformVersion string `jsonapi:"attr,terraform-version"` + ID string `jsonapi:"primary,state-versions"` + CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` + DownloadURL string `jsonapi:"attr,hosted-state-download-url"` + Serial int64 `jsonapi:"attr,serial"` + VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` + VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` + ResourcesProcessed bool `jsonapi:"attr,resources-processed"` + StateVersion int `jsonapi:"attr,state-version"` + TerraformVersion string `jsonapi:"attr,terraform-version"` // Modules *StateVersionModules `jsonapi:"attr,modules"` // Providers *StateVersionProviders `jsonapi:"attr,providers"` - // Resources []*StateVersionResources `jsonapi:"attr,resources"` + // Resources []*StateVersionResources `jsonapi:"attr,resources"` // Relations Run *Run `jsonapi:"relation,run"` @@ -155,7 +155,7 @@ type StateVersionCreateOptions struct { } // type StateVersionModules struct { -// Root *StateVersionModuleRoot `jsonapi:"attr,root"` +// Root StateVersionModuleRoot `jsonapi:"attr,root"` // } // type StateVersionModuleRoot struct { From 5f2d2c1c84f4b46e8dcd026cbe0c1474822b319b Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 4 Aug 2022 13:32:21 -0400 Subject: [PATCH 10/13] merge main, re-run tests --- state_version.go | 70 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/state_version.go b/state_version.go index 43beb530e..609be1e6e 100644 --- a/state_version.go +++ b/state_version.go @@ -55,18 +55,18 @@ type StateVersionList struct { // StateVersion represents a Terraform Enterprise state version. type StateVersion struct { - ID string `jsonapi:"primary,state-versions"` - CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` - DownloadURL string `jsonapi:"attr,hosted-state-download-url"` - Serial int64 `jsonapi:"attr,serial"` - VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` - VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` - ResourcesProcessed bool `jsonapi:"attr,resources-processed"` - StateVersion int `jsonapi:"attr,state-version"` - TerraformVersion string `jsonapi:"attr,terraform-version"` - // Modules *StateVersionModules `jsonapi:"attr,modules"` - // Providers *StateVersionProviders `jsonapi:"attr,providers"` - // Resources []*StateVersionResources `jsonapi:"attr,resources"` + ID string `jsonapi:"primary,state-versions"` + CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` + DownloadURL string `jsonapi:"attr,hosted-state-download-url"` + Serial int64 `jsonapi:"attr,serial"` + VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"` + VCSCommitURL string `jsonapi:"attr,vcs-commit-url"` + ResourcesProcessed bool `jsonapi:"attr,resources-processed"` + StateVersion int `jsonapi:"attr,state-version"` + TerraformVersion string `jsonapi:"attr,terraform-version"` + Modules *StateVersionModules `jsonapi:"attr,modules"` + Providers *StateVersionProviders `jsonapi:"attr,providers"` + Resources []*StateVersionResources `jsonapi:"attr,resources"` // Relations Run *Run `jsonapi:"relation,run"` @@ -154,29 +154,29 @@ type StateVersionCreateOptions struct { JSONStateOutputs *string `jsonapi:"attr,json-state-outputs,omitempty"` } -// type StateVersionModules struct { -// Root StateVersionModuleRoot `jsonapi:"attr,root"` -// } - -// type StateVersionModuleRoot struct { -// NullResource int `jsonapi:"attr,null-resource"` -// TerraformRemoteState int `jsonapi:"attr,data.terraform-remote-state"` -// } - -// type StateVersionProviders map[string]ProviderData - -// type ProviderData struct { -// NullResource int `json:"null-resource"` -// TerraformRemoteState int `json:"data.terraform-remote-state"` -// } - -// type StateVersionResources struct { -// Name string `jsonapi:"attr,name"` -// Count string `jsonapi:"attr,count"` -// Type int `jsonapi:"attr,type"` -// Module string `jsonapi:"attr,module"` -// Provider string `jsonapi:"attr,provider"` -// } +type StateVersionModules struct { + Root StateVersionModuleRoot `jsonapi:"attr,root"` +} + +type StateVersionModuleRoot struct { + NullResource int `jsonapi:"attr,null-resource"` + TerraformRemoteState int `jsonapi:"attr,data.terraform-remote-state"` +} + +type StateVersionProviders map[string]ProviderData + +type ProviderData struct { + NullResource int `json:"null-resource"` + TerraformRemoteState int `json:"data.terraform-remote-state"` +} + +type StateVersionResources struct { + Name string `jsonapi:"attr,name"` + Count string `jsonapi:"attr,count"` + Type int `jsonapi:"attr,type"` + Module string `jsonapi:"attr,module"` + Provider string `jsonapi:"attr,provider"` +} // List all the state versions for a given workspace. func (s *stateVersions) List(ctx context.Context, options *StateVersionListOptions) (*StateVersionList, error) { From e1bdc12ee7439b849ea9d020f4c55aeb9e987d39 Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 4 Aug 2022 13:45:33 -0400 Subject: [PATCH 11/13] resolve cannot unmarshal provider --- state_version.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/state_version.go b/state_version.go index 609be1e6e..587286eb7 100644 --- a/state_version.go +++ b/state_version.go @@ -163,7 +163,9 @@ type StateVersionModuleRoot struct { TerraformRemoteState int `jsonapi:"attr,data.terraform-remote-state"` } -type StateVersionProviders map[string]ProviderData +type StateVersionProviders struct { + Data ProviderData `jsonapi:"attr,provider[map]string"` +} type ProviderData struct { NullResource int `json:"null-resource"` From f9669b127f8805dba6d56a4a7d72db36e75184d9 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 5 Aug 2022 14:18:35 -0400 Subject: [PATCH 12/13] replace all defers with t.Cleanup() --- state_version_integration_test.go | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/state_version_integration_test.go b/state_version_integration_test.go index 37cf688ae..a37ea99d7 100644 --- a/state_version_integration_test.go +++ b/state_version_integration_test.go @@ -20,15 +20,15 @@ func TestStateVersionsList(t *testing.T) { ctx := context.Background() orgTest, orgTestCleanup := createOrganization(t, client) - defer orgTestCleanup() + t.Cleanup(orgTestCleanup) wTest, wTestCleanup := createWorkspace(t, client, orgTest) - defer wTestCleanup() + t.Cleanup(wTestCleanup) svTest1, svTestCleanup1 := createStateVersion(t, client, 0, wTest) - defer svTestCleanup1() + t.Cleanup(svTestCleanup1) svTest2, svTestCleanup2 := createStateVersion(t, client, 1, wTest) - defer svTestCleanup2() + t.Cleanup(svTestCleanup2) t.Run("without StateVersionListOptions", func(t *testing.T) { svl, err := client.StateVersions.List(ctx, nil) @@ -115,7 +115,7 @@ func TestStateVersionsCreate(t *testing.T) { ctx := context.Background() wTest, wTestCleanup := createWorkspace(t, client, nil) - defer wTestCleanup() + t.Cleanup(wTestCleanup) state, err := ioutil.ReadFile("test-fixtures/state-version/terraform.tfstate") if err != nil { @@ -248,7 +248,7 @@ func TestStateVersionsCreate(t *testing.T) { t.Skip("This can only be tested with the run specific token") rTest, rTestCleanup := createRun(t, client, wTest) - defer rTestCleanup() + t.Cleanup(rTestCleanup) ctx := context.Background() sv, err := client.StateVersions.Create(ctx, wTest.ID, StateVersionCreateOptions{ @@ -316,7 +316,7 @@ func TestStateVersionsRead(t *testing.T) { ctx := context.Background() svTest, svTestCleanup := createStateVersion(t, client, 0, nil) - defer svTestCleanup() + t.Cleanup(svTestCleanup) t.Run("when the state version exists", func(t *testing.T) { sv, err := client.StateVersions.Read(ctx, svTest.ID) @@ -353,7 +353,7 @@ func TestStateVersionsReadWithOptions(t *testing.T) { ctx := context.Background() svTest, svTestCleanup := createStateVersion(t, client, 0, nil) - defer svTestCleanup() + t.Cleanup(svTestCleanup) // give TFC some time to process the statefile and extract the outputs. waitForSVOutputs(t, client, svTest.ID) @@ -375,13 +375,13 @@ func TestStateVersionsCurrent(t *testing.T) { ctx := context.Background() wTest1, wTest1Cleanup := createWorkspace(t, client, nil) - defer wTest1Cleanup() + t.Cleanup(wTest1Cleanup) wTest2, wTest2Cleanup := createWorkspace(t, client, nil) - defer wTest2Cleanup() + t.Cleanup(wTest2Cleanup) svTest, svTestCleanup := createStateVersion(t, client, 0, wTest1) - defer svTestCleanup() + t.Cleanup(svTestCleanup) t.Run("when a state version exists", func(t *testing.T) { sv, err := client.StateVersions.ReadCurrent(ctx, wTest1.ID) @@ -418,10 +418,10 @@ func TestStateVersionsCurrentWithOptions(t *testing.T) { ctx := context.Background() wTest1, wTest1Cleanup := createWorkspace(t, client, nil) - defer wTest1Cleanup() + t.Cleanup(wTest1Cleanup) svTest, svTestCleanup := createStateVersion(t, client, 0, wTest1) - defer svTestCleanup() + t.Cleanup(svTestCleanup) // give TFC some time to process the statefile and extract the outputs. waitForSVOutputs(t, client, svTest.ID) @@ -443,7 +443,7 @@ func TestStateVersionsDownload(t *testing.T) { ctx := context.Background() svTest, svTestCleanup := createStateVersion(t, client, 0, nil) - defer svTestCleanup() + t.Cleanup(svTestCleanup) stateTest, err := ioutil.ReadFile("test-fixtures/state-version/terraform.tfstate") require.NoError(t, err) @@ -475,10 +475,10 @@ func TestStateVersionOutputs(t *testing.T) { ctx := context.Background() wTest1, wTest1Cleanup := createWorkspace(t, client, nil) - defer wTest1Cleanup() + t.Cleanup(wTest1Cleanup) sv, svTestCleanup := createStateVersion(t, client, 0, wTest1) - defer svTestCleanup() + t.Cleanup(svTestCleanup) // give TFC some time to process the statefile and extract the outputs. waitForSVOutputs(t, client, sv.ID) From fee64a9950d26f7fd5a5fb029daa14687044d064 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 5 Aug 2022 15:22:33 -0400 Subject: [PATCH 13/13] add assertions --- state_version_integration_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/state_version_integration_test.go b/state_version_integration_test.go index a37ea99d7..09b6144cb 100644 --- a/state_version_integration_test.go +++ b/state_version_integration_test.go @@ -333,6 +333,12 @@ func TestStateVersionsRead(t *testing.T) { sv.Outputs = nil assert.Equal(t, svTest, sv) + assert.NotEmpty(t, svTest, svTest.ResourcesProcessed) + assert.NotEmpty(t, svTest, svTest.StateVersion) + assert.NotEmpty(t, svTest, svTest.TerraformVersion) + assert.NotEmpty(t, svTest, svTest.Modules) + assert.NotEmpty(t, svTest, svTest.Providers) + assert.NotEmpty(t, svTest, svTest.Resources) }) t.Run("when the state version does not exist", func(t *testing.T) {