Skip to content

Commit

Permalink
fix: error if autolink reference not found (#2164)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Mar 8, 2024
1 parent 39c5e06 commit 4cebab8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion github/repository_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func getAutolinkByKeyPrefix(client *github.Client, owner, repo, keyPrefix string
}
}

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

// listAutolinks returns all autolink references for the given repository.
Expand Down
7 changes: 7 additions & 0 deletions github/resource_github_repository_autolink_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package github

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
Expand Down Expand Up @@ -288,6 +289,12 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
ImportStateVerify: true,
ImportStateId: fmt.Sprintf("oof-%s/OOF-", randomID),
},
{
ResourceName: "github_repository_autolink_reference.autolink",
ImportState: true,
ImportStateId: fmt.Sprintf("oof-%s/OCTOCAT-", randomID),
ExpectError: regexp.MustCompile(`cannot find autolink reference`),
},
},
})
}
Expand Down

0 comments on commit 4cebab8

Please sign in to comment.