@@ -2068,6 +2068,44 @@ func TestAccGithubRepository_fork(t *testing.T) {
20682068 })
20692069}
20702070
2071+ func TestGithubRepositoryOwnerNilHandling (t * testing.T ) {
2072+ d := schema .TestResourceDataRaw (t , resourceGithubRepository ().Schema , map [string ]any {
2073+ "name" : "test-repo" ,
2074+ })
2075+ d .SetId ("test-repo" )
2076+
2077+ repo := & github.Repository {
2078+ Name : github .String ("test-repo" ),
2079+ FullName : github .String ("test-org/test-repo" ),
2080+ Owner : nil ,
2081+ }
2082+
2083+ if repo .Owner != nil {
2084+ _ = d .Set ("owner" , repo .Owner .GetLogin ())
2085+ }
2086+
2087+ owner , ok := d .GetOk ("owner" )
2088+ if ok && owner != "" {
2089+ t .Errorf ("Expected owner to be empty when repo.Owner is nil, got: %v" , owner )
2090+ }
2091+
2092+ repo .Owner = & github.User {
2093+ Login : github .String ("test-owner" ),
2094+ }
2095+
2096+ if repo .Owner != nil {
2097+ _ = d .Set ("owner" , repo .Owner .GetLogin ())
2098+ }
2099+
2100+ owner , ok = d .GetOk ("owner" )
2101+ if ! ok {
2102+ t .Error ("Expected owner to be set when repo.Owner is not nil" )
2103+ }
2104+ if owner != "test-owner" {
2105+ t .Errorf ("Expected owner to be 'test-owner', got: %v" , owner )
2106+ }
2107+ }
2108+
20712109func createForkedRepository (repositoryName string ) error {
20722110 config := Config {BaseURL : "https://api.github.com/" , Owner : testOrganizationFunc (), Token : testToken }
20732111 meta , err := config .Meta ()
0 commit comments