@@ -962,6 +962,149 @@ func TestRegistryModulesCreateBranchBasedWithVCSConnection(t *testing.T) {
962
962
})
963
963
}
964
964
965
+ func TestRegistryModulesCreateMonorepoBranchBasedWithVCSConnection (t * testing.T ) {
966
+ skipUnlessBeta (t )
967
+
968
+ githubIdentifier := os .Getenv ("GITHUB_REGISTRY_MODULE_IDENTIFIER" )
969
+ if githubIdentifier == "" {
970
+ t .Skip ("Export a valid GITHUB_REGISTRY_MODULE_IDENTIFIER before running this test" )
971
+ }
972
+ repositoryName := strings .Split (githubIdentifier , "/" )[1 ]
973
+ registryModuleProvider := strings .SplitN (repositoryName , "-" , 3 )[1 ]
974
+ registryModuleName := strings .SplitN (repositoryName , "-" , 3 )[2 ]
975
+
976
+ githubBranch := os .Getenv ("GITHUB_REGISTRY_MODULE_BRANCH" )
977
+ if githubBranch == "" {
978
+ githubBranch = "main"
979
+ }
980
+
981
+ client := testClient (t )
982
+ ctx := context .Background ()
983
+
984
+ orgTest , orgTestCleanup := createOrganizationWithMonorepoSupport (t , client )
985
+ t .Cleanup (orgTestCleanup )
986
+
987
+ oauthTokenTest , oauthTokenTestCleanup := createOAuthToken (t , client , orgTest )
988
+ t .Cleanup (oauthTokenTestCleanup )
989
+
990
+ t .Run ("with valid options including source directory" , func (t * testing.T ) {
991
+ sourceDirectory := "src"
992
+
993
+ options := RegistryModuleCreateWithVCSConnectionOptions {
994
+ VCSRepo : & RegistryModuleVCSRepoOptions {
995
+ OrganizationName : String (orgTest .Name ),
996
+ Identifier : String (githubIdentifier ),
997
+ OAuthTokenID : String (oauthTokenTest .ID ),
998
+ DisplayIdentifier : String (githubIdentifier ),
999
+ Branch : String (githubBranch ),
1000
+ SourceDirectory : String (sourceDirectory ),
1001
+ },
1002
+ }
1003
+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , options )
1004
+ require .NoError (t , err )
1005
+ assert .NotEmpty (t , rm .ID )
1006
+ assert .Equal (t , registryModuleName , rm .Name )
1007
+ assert .Equal (t , registryModuleProvider , rm .Provider )
1008
+ assert .Equal (t , githubBranch , rm .VCSRepo .Branch )
1009
+ assert .Equal (t , false , rm .VCSRepo .Tags )
1010
+ assert .Equal (t , sourceDirectory , rm .VCSRepo .SourceDirectory )
1011
+ })
1012
+ }
1013
+
1014
+ func TestRegistryModulesCreateTagBasedWithVCSConnection (t * testing.T ) {
1015
+ skipUnlessBeta (t )
1016
+
1017
+ githubIdentifier := os .Getenv ("GITHUB_REGISTRY_MODULE_IDENTIFIER" )
1018
+ if githubIdentifier == "" {
1019
+ t .Skip ("Export a valid GITHUB_REGISTRY_MODULE_IDENTIFIER before running this test" )
1020
+ }
1021
+ repositoryName := strings .Split (githubIdentifier , "/" )[1 ]
1022
+ registryModuleProvider := strings .SplitN (repositoryName , "-" , 3 )[1 ]
1023
+ registryModuleName := strings .SplitN (repositoryName , "-" , 3 )[2 ]
1024
+
1025
+ githubBranch := os .Getenv ("GITHUB_REGISTRY_MODULE_BRANCH" )
1026
+ if githubBranch == "" {
1027
+ githubBranch = "main"
1028
+ }
1029
+
1030
+ client := testClient (t )
1031
+ ctx := context .Background ()
1032
+
1033
+ orgTest , orgTestCleanup := createOrganizationWithMonorepoSupport (t , client )
1034
+ t .Cleanup (orgTestCleanup )
1035
+
1036
+ oauthTokenTest , oauthTokenTestCleanup := createOAuthToken (t , client , orgTest )
1037
+ t .Cleanup (oauthTokenTestCleanup )
1038
+
1039
+ t .Run ("with monorepo publishing" , func (t * testing.T ) {
1040
+ sourceDirectory := "src"
1041
+ tagPrefix := "v"
1042
+
1043
+ options := RegistryModuleCreateWithVCSConnectionOptions {
1044
+ VCSRepo : & RegistryModuleVCSRepoOptions {
1045
+ Identifier : String (githubIdentifier ),
1046
+ OAuthTokenID : String (oauthTokenTest .ID ),
1047
+ DisplayIdentifier : String (githubIdentifier ),
1048
+ Branch : String (githubBranch ),
1049
+ SourceDirectory : String (sourceDirectory ),
1050
+ TagPrefix : String (tagPrefix ),
1051
+ },
1052
+ }
1053
+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , options )
1054
+ require .NoError (t , err )
1055
+ assert .NotEmpty (t , rm .ID )
1056
+ assert .Equal (t , registryModuleName , rm .Name )
1057
+ assert .Equal (t , registryModuleProvider , rm .Provider )
1058
+ assert .Equal (t , rm .VCSRepo .Branch , githubBranch )
1059
+ assert .Equal (t , rm .VCSRepo .Identifier , githubIdentifier )
1060
+ assert .Equal (t , rm .VCSRepo .IngressSubmodules , true )
1061
+ assert .Equal (t , rm .VCSRepo .OAuthTokenID , oauthTokenTest .ID )
1062
+ assert .Equal (t , rm .VCSRepo .RepositoryHTTPURL , fmt .Sprintf ("https://github.com/%s" , githubIdentifier ))
1063
+ assert .Equal (t , rm .VCSRepo .ServiceProvider , string (ServiceProviderGithub ))
1064
+ assert .Regexp (t , fmt .Sprintf ("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" , regexp .QuoteMeta (DefaultConfig ().Address )), rm .VCSRepo .WebhookURL )
1065
+
1066
+ if rm .VCSRepo .SourceDirectory != sourceDirectory {
1067
+ t .Errorf ("expected SourceDirectory %q, got %q" , sourceDirectory , rm .VCSRepo .SourceDirectory )
1068
+ }
1069
+ if rm .VCSRepo .TagPrefix != tagPrefix {
1070
+ t .Errorf ("expected TagPrefix %q, got %q" , tagPrefix , rm .VCSRepo .TagPrefix )
1071
+ }
1072
+ })
1073
+
1074
+ t .Run ("without monorepo publishing" , func (t * testing.T ) {
1075
+ tagPrefix := "v"
1076
+
1077
+ options := RegistryModuleCreateWithVCSConnectionOptions {
1078
+ VCSRepo : & RegistryModuleVCSRepoOptions {
1079
+ Identifier : String (githubIdentifier ),
1080
+ OAuthTokenID : String (oauthTokenTest .ID ),
1081
+ DisplayIdentifier : String (githubIdentifier ),
1082
+ Branch : String (githubBranch ),
1083
+ TagPrefix : String (tagPrefix ),
1084
+ },
1085
+ }
1086
+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , options )
1087
+ require .NoError (t , err )
1088
+ assert .NotEmpty (t , rm .ID )
1089
+ assert .Equal (t , registryModuleName , rm .Name )
1090
+ assert .Equal (t , registryModuleProvider , rm .Provider )
1091
+ assert .Equal (t , rm .VCSRepo .Branch , githubBranch )
1092
+ assert .Equal (t , rm .VCSRepo .Identifier , githubIdentifier )
1093
+ assert .Equal (t , rm .VCSRepo .IngressSubmodules , true )
1094
+ assert .Equal (t , rm .VCSRepo .OAuthTokenID , oauthTokenTest .ID )
1095
+ assert .Equal (t , rm .VCSRepo .RepositoryHTTPURL , fmt .Sprintf ("https://github.com/%s" , githubIdentifier ))
1096
+ assert .Equal (t , rm .VCSRepo .ServiceProvider , string (ServiceProviderGithub ))
1097
+ assert .Regexp (t , fmt .Sprintf ("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$" , regexp .QuoteMeta (DefaultConfig ().Address )), rm .VCSRepo .WebhookURL )
1098
+
1099
+ if rm .VCSRepo .SourceDirectory != "" {
1100
+ t .Errorf ("expected SourceDirectory %q, got %q" , "" , rm .VCSRepo .SourceDirectory )
1101
+ }
1102
+ if rm .VCSRepo .TagPrefix != tagPrefix {
1103
+ t .Errorf ("expected TagPrefix %q, got %q" , tagPrefix , rm .VCSRepo .TagPrefix )
1104
+ }
1105
+ })
1106
+ }
1107
+
965
1108
func TestRegistryModulesCreateBranchBasedWithVCSConnectionWithTesting (t * testing.T ) {
966
1109
skipUnlessBeta (t )
967
1110
0 commit comments