@@ -269,4 +269,111 @@ func TestAccGithubRepositoryDataSource(t *testing.T) {
269269 })
270270
271271 })
272+
273+ t .Run ("queries a repository that has no primary_language" , func (t * testing.T ) {
274+
275+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
276+
277+ config := fmt .Sprintf (`
278+ resource "github_repository" "test" {
279+ name = "tf-acc-%s"
280+ }
281+
282+ data "github_repository" "test" {
283+ name = github_repository.test.name
284+ }
285+ ` , randomID )
286+
287+ check := resource .ComposeTestCheckFunc (
288+ resource .TestCheckResourceAttr (
289+ "data.github_repository.test" , "primary_language" ,
290+ "" ,
291+ ),
292+ )
293+
294+ testCase := func (t * testing.T , mode string ) {
295+ resource .Test (t , resource.TestCase {
296+ PreCheck : func () { skipUnlessMode (t , mode ) },
297+ Providers : testAccProviders ,
298+ Steps : []resource.TestStep {
299+ {
300+ Config : config ,
301+ Check : check ,
302+ },
303+ },
304+ })
305+ }
306+
307+ t .Run ("with an anonymous account" , func (t * testing.T ) {
308+ t .Skip ("anonymous account not supported for this operation" )
309+ })
310+
311+ t .Run ("with an individual account" , func (t * testing.T ) {
312+ testCase (t , individual )
313+ })
314+
315+ t .Run ("with an organization account" , func (t * testing.T ) {
316+ testCase (t , organization )
317+ })
318+
319+ })
320+
321+ t .Run ("queries a repository that has go as primary_language" , func (t * testing.T ) {
322+
323+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
324+
325+ config := fmt .Sprintf (`
326+ resource "github_repository" "test" {
327+ name = "tf-acc-%s"
328+ auto_init = true
329+ }
330+ resource "github_repository_file" "test" {
331+ repository = github_repository.test.name
332+ file = "test.go"
333+ content = "package main"
334+ }
335+
336+ data "github_repository" "test" {
337+ name = github_repository_file.test.repository
338+ }
339+ ` , randomID )
340+
341+ check := resource .ComposeTestCheckFunc (
342+ resource .TestCheckResourceAttr (
343+ "data.github_repository.test" , "primary_language" ,
344+ "Go" ,
345+ ),
346+ )
347+
348+ testCase := func (t * testing.T , mode string ) {
349+ resource .Test (t , resource.TestCase {
350+ PreCheck : func () { skipUnlessMode (t , mode ) },
351+ Providers : testAccProviders ,
352+ Steps : []resource.TestStep {
353+ {
354+ // Not doing any checks since the language doesnt have time to be updated on the first apply
355+ Config : config ,
356+ },
357+ {
358+ // Re-running the terraform will refresh the language since the go-file has been created
359+ Config : config ,
360+ Check : check ,
361+ },
362+ },
363+ })
364+ }
365+
366+ t .Run ("with an anonymous account" , func (t * testing.T ) {
367+ t .Skip ("anonymous account not supported for this operation" )
368+ })
369+
370+ t .Run ("with an individual account" , func (t * testing.T ) {
371+ testCase (t , individual )
372+ })
373+
374+ t .Run ("with an organization account" , func (t * testing.T ) {
375+ testCase (t , organization )
376+ })
377+
378+ })
272379}
0 commit comments