Skip to content

Commit 80040ed

Browse files
committed
Fix the tests
1 parent 5090358 commit 80040ed

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

gitlab/resource_gitlab_project_access_token.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ func resourceGitlabProjectAccessToken() *schema.Resource {
8282
func resourceGitlabProjectAccessTokenCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
8383
client := meta.(*gitlab.Client)
8484

85-
project := d.Get("project").(int)
85+
project := d.Get("project").(string)
8686
options := &gitlab.CreateProjectAccessTokenOptions{
8787
Name: gitlab.String(d.Get("name").(string)),
8888
Scopes: *stringSetToStringSlice(d.Get("scopes").(*schema.Set)),
8989
}
9090

91-
log.Printf("[DEBUG] create gitlab ProjectAccessToken %s %s for project ID %d", *options.Name, options.Scopes, project)
91+
log.Printf("[DEBUG] create gitlab ProjectAccessToken %s %s for project ID %s", *options.Name, options.Scopes, project)
9292

9393
if v, ok := d.GetOk("expires_at"); ok {
9494
parsedExpiresAt, err := time.Parse("2006-01-02", v.(string))
@@ -97,44 +97,38 @@ func resourceGitlabProjectAccessTokenCreate(ctx context.Context, d *schema.Resou
9797
}
9898
parsedExpiresAtISOTime := gitlab.ISOTime(parsedExpiresAt)
9999
options.ExpiresAt = &parsedExpiresAtISOTime
100-
log.Printf("[DEBUG] create gitlab ProjectAccessToken %s with expires_at %s for project ID %d", *options.Name, *options.ExpiresAt, project)
100+
log.Printf("[DEBUG] create gitlab ProjectAccessToken %s with expires_at %s for project ID %s", *options.Name, *options.ExpiresAt, project)
101101
}
102102

103103
projectAccessToken, _, err := client.ProjectAccessTokens.CreateProjectAccessToken(project, options, gitlab.WithContext(ctx))
104104
if err != nil {
105105
return diag.FromErr(err)
106106
}
107107

108-
log.Printf("[DEBUG] created gitlab ProjectAccessToken %d - %s for project ID %d", projectAccessToken.ID, *options.Name, project)
108+
log.Printf("[DEBUG] created gitlab ProjectAccessToken %d - %s for project ID %s", projectAccessToken.ID, *options.Name, project)
109109

110-
projectString := strconv.Itoa(project)
111110
PATstring := strconv.Itoa(projectAccessToken.ID)
112-
d.SetId(buildTwoPartID(&projectString, &PATstring))
111+
d.SetId(buildTwoPartID(&project, &PATstring))
113112
d.Set("token", projectAccessToken.Token)
114113

115114
return resourceGitlabProjectAccessTokenRead(ctx, d, meta)
116115
}
117116

118117
func resourceGitlabProjectAccessTokenRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
119118

120-
projectString, PATstring, err := parseTwoPartID(d.Id())
119+
project, PATstring, err := parseTwoPartID(d.Id())
121120
if err != nil {
122121
return diag.Errorf("Error parsing ID: %s", d.Id())
123122
}
124123

125124
client := meta.(*gitlab.Client)
126125

127-
project, err := strconv.Atoi(projectString)
128-
if err != nil {
129-
return diag.Errorf("%s cannot be converted to int", projectString)
130-
}
131-
132126
projectAccessTokenID, err := strconv.Atoi(PATstring)
133127
if err != nil {
134128
return diag.Errorf("%s cannot be converted to int", PATstring)
135129
}
136130

137-
log.Printf("[DEBUG] read gitlab ProjectAccessToken %d, project ID %d", projectAccessTokenID, project)
131+
log.Printf("[DEBUG] read gitlab ProjectAccessToken %d, project ID %s", projectAccessTokenID, project)
138132

139133
//there is a slight possibility to not find an existing item, for example
140134
// 1. item is #101 (ie, in the 2nd page)
@@ -172,25 +166,20 @@ func resourceGitlabProjectAccessTokenRead(ctx context.Context, d *schema.Resourc
172166
page = response.NextPage
173167
}
174168

175-
log.Printf("[DEBUG] failed to read gitlab ProjectAccessToken %d, project ID %d", projectAccessTokenID, project)
169+
log.Printf("[DEBUG] failed to read gitlab ProjectAccessToken %d, project ID %s", projectAccessTokenID, project)
176170
d.SetId("")
177171
return nil
178172
}
179173

180174
func resourceGitlabProjectAccessTokenDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
181175

182-
projectString, PATstring, err := parseTwoPartID(d.Id())
176+
project, PATstring, err := parseTwoPartID(d.Id())
183177
if err != nil {
184178
return diag.Errorf("Error parsing ID: %s", d.Id())
185179
}
186180

187181
client := meta.(*gitlab.Client)
188182

189-
project, err := strconv.Atoi(projectString)
190-
if err != nil {
191-
return diag.Errorf("%s cannot be converted to int", projectString)
192-
}
193-
194183
projectAccessTokenID, err := strconv.Atoi(PATstring)
195184
if err != nil {
196185
return diag.Errorf("%s cannot be converted to int", PATstring)

gitlab/resource_gitlab_project_access_token_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func testAccCheckGitlabProjectAccessTokenExists(n string, pat *testAccGitlabProj
110110
return fmt.Errorf("Not Found: %s", n)
111111
}
112112

113-
projectString, PATstring, err := parseTwoPartID(rs.Primary.ID)
113+
project, PATstring, err := parseTwoPartID(rs.Primary.ID)
114114
if err != nil {
115115
return fmt.Errorf("Error parsing ID: %s", rs.Primary.ID)
116116
}
@@ -123,8 +123,8 @@ func testAccCheckGitlabProjectAccessTokenExists(n string, pat *testAccGitlabProj
123123
if repoName == "" {
124124
return fmt.Errorf("No project ID is set")
125125
}
126-
if repoName != projectString {
127-
return fmt.Errorf("Project [%s] in project identifier [%s] it's different from project stored into the state [%s]", projectString, rs.Primary.ID, repoName)
126+
if repoName != project {
127+
return fmt.Errorf("Project [%s] in project identifier [%s] it's different from project stored into the state [%s]", project, rs.Primary.ID, repoName)
128128
}
129129

130130
conn := testAccProvider.Meta().(*gitlab.Client)

0 commit comments

Comments
 (0)