Skip to content

Commit c206d24

Browse files
Add missing import tests (#399)
Helped me find a bug in `grafana_team`, the `team_id` attribute wasn't being set on a read Closes #190
1 parent 40852db commit c206d24

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

grafana/resource_organization_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ func TestAccOrganization_basic(t *testing.T) {
4444
),
4545
),
4646
},
47+
{
48+
ResourceName: "grafana_organization.test",
49+
ImportState: true,
50+
ImportStateVerify: true,
51+
ImportStateVerifyIgnore: []string{"admins", "admin_user", "create_users"}, // Users are imported explicitly (with create_users == false)
52+
ImportStateCheck: func(s []*terraform.InstanceState) error {
53+
if len(s) != 1 {
54+
return fmt.Errorf("expected 1 state: %#v", s)
55+
}
56+
admin := s[0].Attributes["admins.0"]
57+
if admin != "admin@localhost" {
58+
return fmt.Errorf("expected admin@localhost: %s", admin)
59+
}
60+
return nil
61+
},
62+
},
4763
},
4864
})
4965
}
@@ -168,6 +184,12 @@ func TestAccOrganization_defaultAdmin(t *testing.T) {
168184
),
169185
),
170186
},
187+
{
188+
ResourceName: "grafana_organization.test",
189+
ImportState: true,
190+
ImportStateVerify: true,
191+
ImportStateVerifyIgnore: []string{"admin_user", "create_user"}, // These are provider-side attributes and aren't returned by the API
192+
},
171193
},
172194
})
173195
}

grafana/resource_team.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func ReadTeam(ctx context.Context, d *schema.ResourceData, meta interface{}) dia
106106
if err != nil {
107107
return diag.FromErr(err)
108108
}
109+
d.Set("team_id", teamID)
109110
d.Set("name", resp.Name)
110111
if resp.Email != "" {
111112
d.Set("email", resp.Email)

grafana/resource_team_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func TestAccTeam_basic(t *testing.T) {
4747
),
4848
),
4949
},
50+
{
51+
ResourceName: "grafana_team.test",
52+
ImportState: true,
53+
ImportStateVerify: true,
54+
},
5055
},
5156
})
5257
}
@@ -97,6 +102,12 @@ func TestAccTeam_Members(t *testing.T) {
97102
),
98103
),
99104
},
105+
// Test the import with members
106+
{
107+
ResourceName: "grafana_team.test",
108+
ImportState: true,
109+
ImportStateVerify: true,
110+
},
100111
{
101112
Config: testAccTeamConfig_memberRemove,
102113
Check: resource.ComposeTestCheckFunc(

grafana/resource_user_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ func TestAccUser_basic(t *testing.T) {
6262
),
6363
),
6464
},
65+
{
66+
ResourceName: "grafana_user.test",
67+
ImportState: true,
68+
ImportStateVerify: true,
69+
ImportStateVerifyIgnore: []string{"password"},
70+
},
6571
},
6672
})
6773
}

0 commit comments

Comments
 (0)