Skip to content

Commit 4cebab8

Browse files
bradam12nickfloydkfcampbell
authored
fix: error if autolink reference not found (#2164)
* fix: error if autolink reference not found * Add test for importing an invalid key --------- Co-authored-by: Nick Floyd <[email protected]> Co-authored-by: Keegan Campbell <[email protected]>
1 parent 39c5e06 commit 4cebab8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

github/repository_utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func getAutolinkByKeyPrefix(client *github.Client, owner, repo, keyPrefix string
9898
}
9999
}
100100

101-
return nil, nil
101+
return nil, fmt.Errorf("cannot find autolink reference %s in repo %s/%s", keyPrefix, owner, repo)
102102
}
103103

104104
// listAutolinks returns all autolink references for the given repository.

github/resource_github_repository_autolink_reference_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"fmt"
5+
"regexp"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -288,6 +289,12 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
288289
ImportStateVerify: true,
289290
ImportStateId: fmt.Sprintf("oof-%s/OOF-", randomID),
290291
},
292+
{
293+
ResourceName: "github_repository_autolink_reference.autolink",
294+
ImportState: true,
295+
ImportStateId: fmt.Sprintf("oof-%s/OCTOCAT-", randomID),
296+
ExpectError: regexp.MustCompile(`cannot find autolink reference`),
297+
},
291298
},
292299
})
293300
}

0 commit comments

Comments
 (0)