@@ -540,8 +540,10 @@ func TestAccGitlabProject_importURL(t *testing.T) {
540
540
}
541
541
542
542
type testAccGitlabProjectMirroredExpectedAttributes struct {
543
- Mirror bool
544
- MirrorTriggerBuilds bool
543
+ Mirror bool
544
+ MirrorTriggerBuilds bool
545
+ MirrorOverwritesDivergedBranches bool
546
+ OnlyMirrorProtectedBranches bool
545
547
}
546
548
547
549
func testAccCheckGitlabProjectMirroredAttributes (project * gitlab.Project , want * testAccGitlabProjectMirroredExpectedAttributes ) resource.TestCheckFunc {
@@ -553,6 +555,14 @@ func testAccCheckGitlabProjectMirroredAttributes(project *gitlab.Project, want *
553
555
if project .MirrorTriggerBuilds != want .MirrorTriggerBuilds {
554
556
return fmt .Errorf ("got mirror_trigger_builds %t; want %t" , project .MirrorTriggerBuilds , want .MirrorTriggerBuilds )
555
557
}
558
+
559
+ if project .MirrorOverwritesDivergedBranches != want .MirrorOverwritesDivergedBranches {
560
+ return fmt .Errorf ("got mirror_overwrites_diverged_branches %t; want %t" , project .MirrorOverwritesDivergedBranches , want .MirrorOverwritesDivergedBranches )
561
+ }
562
+
563
+ if project .OnlyMirrorProtectedBranches != want .OnlyMirrorProtectedBranches {
564
+ return fmt .Errorf ("got only_mirror_protected_branches %t; want %t" , project .OnlyMirrorProtectedBranches , want .OnlyMirrorProtectedBranches )
565
+ }
556
566
return nil
557
567
}
558
568
}
@@ -601,10 +611,39 @@ func TestAccGitlabProject_importURLMirrored(t *testing.T) {
601
611
testAccCheckGitlabProjectExists ("gitlab_project.imported" , & mirror ),
602
612
resource .TestCheckResourceAttr ("gitlab_project.imported" , "import_url" , baseProject .HTTPURLToRepo ),
603
613
testAccCheckGitlabProjectMirroredAttributes (& mirror , & testAccGitlabProjectMirroredExpectedAttributes {
604
- Mirror : true ,
605
- MirrorTriggerBuilds : true ,
614
+ Mirror : true ,
615
+ MirrorTriggerBuilds : true ,
616
+ MirrorOverwritesDivergedBranches : true ,
617
+ OnlyMirrorProtectedBranches : true ,
618
+ }),
619
+
620
+ func (state * terraform.State ) error {
621
+ projectID := state .RootModule ().Resources ["gitlab_project.imported" ].Primary .ID
622
+
623
+ _ , _ , err := client .RepositoryFiles .GetFile (projectID , "foo.txt" , & gitlab.GetFileOptions {Ref : gitlab .String ("master" )}, nil )
624
+ if err != nil {
625
+ return fmt .Errorf ("failed to get file from imported project: %w" , err )
626
+ }
627
+
628
+ return nil
629
+ },
630
+ ),
631
+ },
632
+ {
633
+ // Second, disable all optional mirroring options
634
+ Config : testAccGitlabProjectConfigImportURLMirrorDisabledOptionals (rInt , baseProject .HTTPURLToRepo ),
635
+ SkipFunc : isRunningInCE ,
636
+ Check : resource .ComposeTestCheckFunc (
637
+ testAccCheckGitlabProjectExists ("gitlab_project.imported" , & mirror ),
638
+ resource .TestCheckResourceAttr ("gitlab_project.imported" , "import_url" , baseProject .HTTPURLToRepo ),
639
+ testAccCheckGitlabProjectMirroredAttributes (& mirror , & testAccGitlabProjectMirroredExpectedAttributes {
640
+ Mirror : true ,
641
+ MirrorTriggerBuilds : false ,
642
+ MirrorOverwritesDivergedBranches : false ,
643
+ OnlyMirrorProtectedBranches : false ,
606
644
}),
607
645
646
+ // Ensure the test file still is as expected
608
647
func (state * terraform.State ) error {
609
648
projectID := state .RootModule ().Resources ["gitlab_project.imported" ].Primary .ID
610
649
@@ -618,15 +657,17 @@ func TestAccGitlabProject_importURLMirrored(t *testing.T) {
618
657
),
619
658
},
620
659
{
621
- // Second , disable mirroring, using the original ImportURL acceptance test
660
+ // Third , disable mirroring, using the original ImportURL acceptance test
622
661
Config : testAccGitlabProjectConfigImportURLMirrorDisabled (rInt , baseProject .HTTPURLToRepo ),
623
662
SkipFunc : isRunningInCE ,
624
663
Check : resource .ComposeTestCheckFunc (
625
664
testAccCheckGitlabProjectExists ("gitlab_project.imported" , & mirror ),
626
665
resource .TestCheckResourceAttr ("gitlab_project.imported" , "import_url" , baseProject .HTTPURLToRepo ),
627
666
testAccCheckGitlabProjectMirroredAttributes (& mirror , & testAccGitlabProjectMirroredExpectedAttributes {
628
- Mirror : false ,
629
- MirrorTriggerBuilds : false ,
667
+ Mirror : false ,
668
+ MirrorTriggerBuilds : false ,
669
+ MirrorOverwritesDivergedBranches : false ,
670
+ OnlyMirrorProtectedBranches : false ,
630
671
}),
631
672
632
673
// Ensure the test file still is as expected
@@ -992,6 +1033,26 @@ resource "gitlab_project" "imported" {
992
1033
import_url = "%s"
993
1034
mirror = true
994
1035
mirror_trigger_builds = true
1036
+ mirror_overwrites_diverged_branches = true
1037
+ only_mirror_protected_branches = true
1038
+
1039
+ # So that acceptance tests can be run in a gitlab organization
1040
+ # with no billing
1041
+ visibility_level = "public"
1042
+ }
1043
+ ` , rInt , importURL )
1044
+ }
1045
+
1046
+ func testAccGitlabProjectConfigImportURLMirrorDisabledOptionals (rInt int , importURL string ) string {
1047
+ return fmt .Sprintf (`
1048
+ resource "gitlab_project" "imported" {
1049
+ name = "imported-%d"
1050
+ default_branch = "master"
1051
+ import_url = "%s"
1052
+ mirror = true
1053
+ mirror_trigger_builds = false
1054
+ mirror_overwrites_diverged_branches = false
1055
+ only_mirror_protected_branches = false
995
1056
996
1057
# So that acceptance tests can be run in a gitlab organization
997
1058
# with no billing
@@ -1008,6 +1069,8 @@ resource "gitlab_project" "imported" {
1008
1069
import_url = "%s"
1009
1070
mirror = false
1010
1071
mirror_trigger_builds = false
1072
+ mirror_overwrites_diverged_branches = false
1073
+ only_mirror_protected_branches = false
1011
1074
1012
1075
# So that acceptance tests can be run in a gitlab organization
1013
1076
# with no billing
0 commit comments