@@ -911,8 +911,7 @@ go 1.17`
911
911
expect : expectations {
912
912
envVars : []string {"GOPRIVATE=*.example.com" },
913
913
commandsExecuted : [][]string {
914
- {
"git" ,
"config" ,
"--global" ,
"url.https://[email protected] /private/repo.git.insteadOf" ,
"https://private1.example.com/private/repo.git" },
915
- {
"git" ,
"config" ,
"--global" ,
"url.https://[email protected] /another/repo.git.insteadOf" ,
"https://private2.example.com/another/repo.git" },
914
+ {
"git" ,
"config" ,
"--global" ,
"url.https://[email protected] " ,
"https://example.com" },
916
915
},
917
916
},
918
917
},
@@ -943,89 +942,6 @@ go 1.17`
943
942
}
944
943
}
945
944
946
- func TestLookupGolangPrivateModulesRepositories (t * testing.T ) {
947
- t .Parallel ()
948
-
949
- modTestFile := `
950
- module private.example.com/m
951
-
952
- require (
953
- example.com/public/module v1.0.0
954
- private1.example.com/private/repo v0.1.0
955
- private2.example.com/another/repo v0.2.0
956
- )
957
-
958
- go 1.17`
959
-
960
- type expectations struct {
961
- repos []string
962
- errorMessage string
963
- }
964
- tests := []struct {
965
- name string
966
- modFileContent string
967
- globPattern string
968
- expect expectations
969
- }{
970
- {
971
- name : "Does nothing if glob pattern is empty" ,
972
- modFileContent : modTestFile ,
973
- expect : expectations {
974
- repos : []string {},
975
- },
976
- },
977
- {
978
- name : "Does nothing if there is no go.mod file" ,
979
- globPattern : "private.example.com" ,
980
- modFileContent : "" ,
981
- expect : expectations {
982
- repos : []string {},
983
- },
984
- },
985
- {
986
- name : "Detects all private repos using a glob pattern" ,
987
- modFileContent : modTestFile ,
988
- globPattern : "*.example.com" ,
989
- expect : expectations {
990
- repos : []string {"https://private1.example.com/private/repo.git" , "https://private2.example.com/another/repo.git" },
991
- },
992
- },
993
- {
994
- name : "Detects all private repos" ,
995
- modFileContent : modTestFile ,
996
- globPattern : "private1.example.com,private2.example.com" ,
997
- expect : expectations {
998
- repos : []string {"https://private1.example.com/private/repo.git" , "https://private2.example.com/another/repo.git" },
999
- },
1000
- },
1001
- {
1002
- name : "Detects a dedicated repo" ,
1003
- modFileContent : modTestFile ,
1004
- globPattern : "private2.example.com" ,
1005
- expect : expectations {
1006
- repos : []string {"https://private2.example.com/another/repo.git" },
1007
- },
1008
- },
1009
- }
1010
-
1011
- for _ , tt := range tests {
1012
- t .Run (tt .name , func (t * testing.T ) {
1013
- utils := newGolangBuildTestsUtils ()
1014
-
1015
- goModFile , _ := modfile .Parse ("" , []byte (tt .modFileContent ), nil )
1016
-
1017
- repos , err := lookupGolangPrivateModulesRepositories (goModFile , tt .globPattern , utils )
1018
-
1019
- if tt .expect .errorMessage == "" {
1020
- assert .NoError (t , err )
1021
- assert .Equal (t , tt .expect .repos , repos )
1022
- } else {
1023
- assert .EqualError (t , err , tt .expect .errorMessage )
1024
- }
1025
- })
1026
- }
1027
- }
1028
-
1029
945
func TestRunGolangciLint (t * testing.T ) {
1030
946
t .Parallel ()
1031
947
@@ -1153,3 +1069,59 @@ func TestRetrieveGolangciLint(t *testing.T) {
1153
1069
})
1154
1070
}
1155
1071
}
1072
+
1073
+ func Test_gitConfigurationForPrivateModules (t * testing.T ) {
1074
+ type args struct {
1075
+ privateMod string
1076
+ token string
1077
+ }
1078
+ type expectations struct {
1079
+ commandsExecuted [][]string
1080
+ }
1081
+ tests := []struct {
1082
+ name string
1083
+ args args
1084
+
1085
+ expected expectations
1086
+ }{
1087
+ {
1088
+ name : "with one private module" ,
1089
+ args : args {
1090
+ privateMod : "example.com/*" ,
1091
+ token : "mytoken" ,
1092
+ },
1093
+ expected : expectations {
1094
+ commandsExecuted : [][]string {
1095
+ {
"git" ,
"config" ,
"--global" ,
"url.https://[email protected] " ,
"https://example.com" },
1096
+ },
1097
+ },
1098
+ },
1099
+ {
1100
+ name : "with multiple private modules" ,
1101
+ args : args {
1102
+ privateMod : "example.com/*,test.com/*" ,
1103
+ token : "mytoken" ,
1104
+ },
1105
+ expected : expectations {
1106
+ commandsExecuted : [][]string {
1107
+ {
"git" ,
"config" ,
"--global" ,
"url.https://[email protected] " ,
"https://example.com" },
1108
+ {
"git" ,
"config" ,
"--global" ,
"url.https://[email protected] " ,
"https://test.com" },
1109
+ },
1110
+ },
1111
+ },
1112
+ }
1113
+ for _ , tt := range tests {
1114
+ t .Run (tt .name , func (t * testing.T ) {
1115
+ utils := newGolangBuildTestsUtils ()
1116
+
1117
+ err := gitConfigurationForPrivateModules (tt .args .privateMod , tt .args .token , utils )
1118
+
1119
+ if assert .NoError (t , err ) {
1120
+ for i , expectedCommand := range tt .expected .commandsExecuted {
1121
+ assert .Equal (t , expectedCommand [0 ], utils .Calls [i ].Exec )
1122
+ assert .Equal (t , expectedCommand [1 :], utils .Calls [i ].Params )
1123
+ }
1124
+ }
1125
+ })
1126
+ }
1127
+ }
0 commit comments