@@ -2,11 +2,12 @@ package provider
2
2
3
3
import (
4
4
"fmt"
5
- "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
6
5
"strconv"
7
6
"strings"
8
7
"testing"
9
8
9
+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
10
+
10
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
11
12
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12
13
)
@@ -96,6 +97,52 @@ func TestAccDataGitlabProjectsGroups(t *testing.T) {
96
97
})
97
98
}
98
99
100
+ func TestAccDataGitlabProjects_searchArchivedRepository (t * testing.T ) {
101
+ rInt := acctest .RandInt ()
102
+
103
+ resource .Test (t , resource.TestCase {
104
+ PreCheck : func () { testAccPreCheck (t ) },
105
+ ProviderFactories : providerFactories ,
106
+ Steps : []resource.TestStep {
107
+ {
108
+ Config : testAccDataGitlabProjectsConfigGetProjectArchivedRepositoryAll (rInt ),
109
+ Check : resource .ComposeAggregateTestCheckFunc (
110
+ resource .TestCheckResourceAttr (
111
+ "data.gitlab_projects.search" ,
112
+ "projects.0.name" ,
113
+ fmt .Sprintf ("archived-%d" , rInt ),
114
+ ),
115
+ resource .TestCheckResourceAttr (
116
+ "data.gitlab_projects.search" ,
117
+ "projects.1.name" ,
118
+ fmt .Sprintf ("not-archived-%d" , rInt ),
119
+ ),
120
+ ),
121
+ },
122
+ {
123
+ Config : testAccDataGitlabProjectsConfigGetProjectArchivedRepository (rInt , "true" ),
124
+ Check : resource .ComposeAggregateTestCheckFunc (
125
+ resource .TestCheckResourceAttr (
126
+ "data.gitlab_projects.search" ,
127
+ "projects.0.name" ,
128
+ fmt .Sprintf ("archived-%d" , rInt ),
129
+ ),
130
+ ),
131
+ },
132
+ {
133
+ Config : testAccDataGitlabProjectsConfigGetProjectArchivedRepository (rInt , "false" ),
134
+ Check : resource .ComposeAggregateTestCheckFunc (
135
+ resource .TestCheckResourceAttr (
136
+ "data.gitlab_projects.search" ,
137
+ "projects.0.name" ,
138
+ fmt .Sprintf ("not-archived-%d" , rInt ),
139
+ ),
140
+ ),
141
+ },
142
+ },
143
+ })
144
+ }
145
+
99
146
func testAccDataSourceGitlabProjects (src string , n string ) resource.TestCheckFunc {
100
147
return func (s * terraform.State ) error {
101
148
@@ -167,6 +214,68 @@ data "gitlab_projects" "search" {
167
214
` , projectName , projectName )
168
215
}
169
216
217
+ func testAccDataGitlabProjectsConfigGetProjectArchivedRepositoryAll (rInt int ) string {
218
+ return fmt .Sprintf (`
219
+ resource "gitlab_group" "test" {
220
+ name = "test-%d"
221
+ path = "test-%d"
222
+ }
223
+
224
+ resource "gitlab_project" "archived_repo" {
225
+ name = "archived-%d"
226
+ namespace_id = gitlab_group.test.id
227
+ archived = true
228
+ }
229
+
230
+ resource "gitlab_project" "not_archived_repo" {
231
+ name = "not-archived-%d"
232
+ namespace_id = gitlab_group.test.id
233
+ archived = false
234
+ }
235
+
236
+ data "gitlab_projects" "search" {
237
+ group_id = gitlab_group.test.id
238
+ // NOTE: is required to have deterministic results
239
+ order_by = "name"
240
+ sort = "asc"
241
+
242
+ depends_on = [gitlab_project.archived_repo, gitlab_project.not_archived_repo]
243
+ }
244
+ ` , rInt , rInt , rInt , rInt )
245
+ }
246
+
247
+ func testAccDataGitlabProjectsConfigGetProjectArchivedRepository (rInt int , archived string ) string {
248
+ return fmt .Sprintf (`
249
+ resource "gitlab_group" "test" {
250
+ name = "test-%d"
251
+ path = "test-%d"
252
+ }
253
+
254
+ resource "gitlab_project" "archived_repo" {
255
+ name = "archived-%d"
256
+ namespace_id = gitlab_group.test.id
257
+ archived = true
258
+ }
259
+
260
+ resource "gitlab_project" "not_archived_repo" {
261
+ name = "not-archived-%d"
262
+ namespace_id = gitlab_group.test.id
263
+ archived = false
264
+ }
265
+
266
+ data "gitlab_projects" "search" {
267
+ group_id = gitlab_group.test.id
268
+ // NOTE: is required to have deterministic results
269
+ order_by = "name"
270
+ sort = "asc"
271
+
272
+ archived = %s
273
+
274
+ depends_on = [gitlab_project.archived_repo, gitlab_project.not_archived_repo]
275
+ }
276
+ ` , rInt , rInt , rInt , rInt , archived )
277
+ }
278
+
170
279
func testAccDataGitlabProjectsConfigGetGroupProjectsByGroupId (groupName string , projectName string ) string {
171
280
return fmt .Sprintf (`
172
281
resource "gitlab_group" "testGroup" {
0 commit comments