Skip to content

Commit

Permalink
Properly handle when user group is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
micahlmartin committed Sep 15, 2021
1 parent 7bfe91e commit 5aa3440
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/provider/data_source_user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, meta i
return diag.Errorf("id or name must be set")
}

if userGroup == nil {
return diag.Errorf("user group not found")
}

d.SetId(userGroup.Id)
d.Set("name", userGroup.Name)

Expand Down
21 changes: 21 additions & 0 deletions internal/provider/data_source_user_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ func TestAccDataSourceUserGroup_Name(t *testing.T) {
})
}

func TestAccDataSourceUserGroup_NotFound(t *testing.T) {

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceUserGroupById_NotFound(),
},
},
})
}

func testAccDataSourceUserGroupById_NotFound() string {
return `
data "harness_user_group" "test" {
id = "somebadid"
}
`
}

func testAccDataSourceUserGroupById(name string) string {
return fmt.Sprintf(`
resource "harness_user_group" "test" {
Expand Down

0 comments on commit 5aa3440

Please sign in to comment.