Skip to content

Commit 9136561

Browse files
authored
Fix group_share_group nil pointer reference (#555)
* Fix gitlab_group_share_group expires_at bug Only set expires_at field when time is not nil. Update associated tests. * Add empty string for gitlab_group_share_group read Add empty string when gitlab_group_share_group expires_at time is null * Added extra check for share_group import test
1 parent bff9621 commit 9136561

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

gitlab/resource_gitlab_group_share_group.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ func resourceGitlabGroupShareGroupRead(d *schema.ResourceData, meta interface{})
105105
d.Set("group_id", groupId)
106106
d.Set("share_group_id", sharedGroup.GroupID)
107107
d.Set("group_access", accessLevel[convertedAccessLevel])
108-
d.Set("expires_at", sharedGroup.ExpiresAt.String())
108+
109+
if sharedGroup.ExpiresAt == nil {
110+
d.Set("expires_at", "")
111+
} else {
112+
d.Set("expires_at", sharedGroup.ExpiresAt.String())
113+
}
109114

110115
return nil
111116
}

gitlab/resource_gitlab_group_share_group_test.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ func TestAccGitlabGroupShareGroup_basic(t *testing.T) {
1919
Steps: []resource.TestStep{
2020
// Share a new group with another group
2121
{
22-
Config: testAccGitlabGroupShareGroupConfig(randName, "guest", "2099-01-01"),
23-
Check: testAccCheckGitlabGroupSharedWithGroup(randName, "2099-01-01", gitlab.GuestPermissions),
22+
Config: testAccGitlabGroupShareGroupConfig(
23+
randName,
24+
`
25+
group_access = "guest"
26+
expires_at = "2099-01-01"
27+
`,
28+
),
29+
Check: testAccCheckGitlabGroupSharedWithGroup(randName, "2099-01-01", gitlab.GuestPermissions),
2430
},
2531
// Update the share group
2632
{
27-
Config: testAccGitlabGroupShareGroupConfig(randName, "reporter", "2099-02-02"),
28-
Check: testAccCheckGitlabGroupSharedWithGroup(randName, "2099-02-02", gitlab.ReporterPermissions),
33+
Config: testAccGitlabGroupShareGroupConfig(randName, `group_access = "reporter"`),
34+
Check: testAccCheckGitlabGroupSharedWithGroup(randName, "", gitlab.ReporterPermissions),
2935
},
3036
// Delete the gitlab_group_share_group resource
3137
{
@@ -46,8 +52,14 @@ func TestAccGitlabGroupShareGroup_import(t *testing.T) {
4652
Steps: []resource.TestStep{
4753
{
4854
// create shared groups
49-
Config: testAccGitlabGroupShareGroupConfig(randName, "guest", "2099-03-03"),
50-
Check: testAccCheckGitlabGroupSharedWithGroup(randName, "2099-03-03", gitlab.GuestPermissions),
55+
Config: testAccGitlabGroupShareGroupConfig(
56+
randName,
57+
`
58+
group_access = "guest"
59+
expires_at = "2099-03-03"
60+
`,
61+
),
62+
Check: testAccCheckGitlabGroupSharedWithGroup(randName, "2099-03-03", gitlab.GuestPermissions),
5163
},
5264
{
5365
// Verify Import
@@ -87,8 +99,10 @@ func testAccCheckGitlabGroupSharedWithGroup(
8799
return fmt.Errorf("groupAccessLevel was %d (wanted %d)", sharedGroup.GroupAccessLevel, accessLevel)
88100
}
89101

90-
if sharedGroup.ExpiresAt.String() != expireTime {
91-
return fmt.Errorf("expired time was %s (wanted %s)", sharedGroup.ExpiresAt.String(), expireTime)
102+
if sharedGroup.ExpiresAt == nil && expireTime != "" {
103+
return fmt.Errorf("expire time was nil (wanted %s)", expireTime)
104+
} else if sharedGroup.ExpiresAt != nil && sharedGroup.ExpiresAt.String() != expireTime {
105+
return fmt.Errorf("expire time was %s (wanted %s)", sharedGroup.ExpiresAt.String(), expireTime)
92106
}
93107

94108
return nil
@@ -115,8 +129,7 @@ func testAccCheckGitlabGroupIsNotShared(groupName string) resource.TestCheckFunc
115129

116130
func testAccGitlabGroupShareGroupConfig(
117131
randName string,
118-
accessLevel string,
119-
expireTime string,
132+
shareGroupSettings string,
120133
) string {
121134
return fmt.Sprintf(
122135
`
@@ -133,13 +146,11 @@ func testAccGitlabGroupShareGroupConfig(
133146
resource "gitlab_group_share_group" "test" {
134147
group_id = gitlab_group.test_main.id
135148
share_group_id = gitlab_group.test_share.id
136-
group_access = "%[2]s"
137-
expires_at = "%[3]s"
149+
%[2]s
138150
}
139151
`,
140152
randName,
141-
accessLevel,
142-
expireTime,
153+
shareGroupSettings,
143154
)
144155
}
145156

0 commit comments

Comments
 (0)