Skip to content

Commit 6dd5983

Browse files
committed
Ensure migrations actually run for users
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 50a9aa7 commit 6dd5983

3 files changed

Lines changed: 14 additions & 14 deletions

github/resource_github_repository_autolink_reference.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func resourceGithubRepositoryAutolinkReference() *schema.Resource {
2929

3030
CustomizeDiff: diffRepository,
3131

32-
SchemaVersion: 1,
32+
SchemaVersion: 2,
3333
StateUpgraders: []schema.StateUpgrader{
3434
{
35-
Type: resourceGithubRepositoryAutolinkReferenceV0().CoreConfigSchema().ImpliedType(),
36-
Upgrade: resourceGithubRepositoryAutolinkReferenceStateUpgradeV0,
37-
Version: 0,
35+
Type: resourceGithubRepositoryAutolinkReferenceV1().CoreConfigSchema().ImpliedType(),
36+
Upgrade: resourceGithubRepositoryAutolinkReferenceStateUpgradeV1,
37+
Version: 1,
3838
},
3939
},
4040
Schema: map[string]*schema.Schema{

github/resource_github_repository_autolink_reference_migration.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
)
1010

11-
func resourceGithubRepositoryAutolinkReferenceV0() *schema.Resource {
11+
func resourceGithubRepositoryAutolinkReferenceV1() *schema.Resource {
1212
return &schema.Resource{
1313
Schema: map[string]*schema.Schema{
1414
"repository": {
@@ -40,8 +40,8 @@ func resourceGithubRepositoryAutolinkReferenceV0() *schema.Resource {
4040
}
4141
}
4242

43-
func resourceGithubRepositoryAutolinkReferenceStateUpgradeV0(ctx context.Context, rawState map[string]any, m any) (map[string]any, error) {
44-
tflog.Debug(ctx, "GitHub Repository Autolink Reference state before v0 migration", rawState)
43+
func resourceGithubRepositoryAutolinkReferenceStateUpgradeV1(ctx context.Context, rawState map[string]any, m any) (map[string]any, error) {
44+
tflog.Debug(ctx, "GitHub Repository Autolink Reference state before v1 migration", rawState)
4545

4646
meta, _ := m.(*Owner)
4747
client := meta.v3client
@@ -54,17 +54,17 @@ func resourceGithubRepositoryAutolinkReferenceStateUpgradeV0(ctx context.Context
5454
}
5555
}
5656
if repoName == "" {
57-
return nil, fmt.Errorf("state upgrade v0: repository is not a string or not set")
57+
return nil, fmt.Errorf("state upgrade v1: repository is not a string or not set")
5858
}
5959

6060
repo, _, err := client.Repositories.Get(ctx, owner, repoName)
6161
if err != nil {
62-
return nil, fmt.Errorf("state upgrade v0: failed to retrieve repository '%s': %w", repoName, err)
62+
return nil, fmt.Errorf("state upgrade v1: failed to retrieve repository '%s/%s': %w", owner, repoName, err)
6363
}
6464

6565
rawState["repository_id"] = int(repo.GetID())
6666

67-
tflog.Debug(ctx, "GitHub Repository Autolink Reference state after v0 migration", rawState)
67+
tflog.Debug(ctx, "GitHub Repository Autolink Reference state after v1 migration", rawState)
6868

6969
return rawState, nil
7070
}

github/resource_github_repository_autolink_reference_migration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/google/go-github/v88/github"
1111
)
1212

13-
func buildMockResponsesForRepositoryAutolinkReferenceMigrationV0toV1(mockOwner, mockRepo string, wantRepoID int) []*mockResponse {
13+
func buildMockResponsesForRepositoryAutolinkReferenceMigrationV1toV2(mockOwner, mockRepo string, wantRepoID int) []*mockResponse {
1414
responseBodyJSON, err := json.Marshal(github.Repository{
1515
ID: new(int64(wantRepoID)),
1616
Name: new(mockRepo),
@@ -29,7 +29,7 @@ func buildMockResponsesForRepositoryAutolinkReferenceMigrationV0toV1(mockOwner,
2929
}}
3030
}
3131

32-
func Test_resourceGithubRepositoryAutolinkReferenceStateUpgradeV0toV1(t *testing.T) {
32+
func Test_resourceGithubRepositoryAutolinkReferenceStateUpgradeV1toV2(t *testing.T) {
3333
t.Parallel()
3434

3535
for _, d := range []struct {
@@ -62,12 +62,12 @@ func Test_resourceGithubRepositoryAutolinkReferenceStateUpgradeV0toV1(t *testing
6262
t.Parallel()
6363

6464
meta := &Owner{name: "test-org"}
65-
ts := githubApiMock(buildMockResponsesForRepositoryAutolinkReferenceMigrationV0toV1(meta.name, "test-repo", 1234567890))
65+
ts := githubApiMock(buildMockResponsesForRepositoryAutolinkReferenceMigrationV1toV2(meta.name, "test-repo", 1234567890))
6666
defer ts.Close()
6767

6868
meta.v3client = mustCreateTestGitHubClient(t, ts.URL)
6969

70-
got, err := resourceGithubRepositoryAutolinkReferenceStateUpgradeV0(t.Context(), d.rawState, meta)
70+
got, err := resourceGithubRepositoryAutolinkReferenceStateUpgradeV1(t.Context(), d.rawState, meta)
7171
if (err != nil) != d.shouldError {
7272
t.Fatalf("unexpected error state: got error %v, shouldError %v", err, d.shouldError)
7373
}

0 commit comments

Comments
 (0)