github.com/argoproj/argo-cd/v2@v2.10.9/applicationset/services/scm_provider/gitlab_test.go (about)

     1  package scm_provider
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"io"
     7  	"net/http"
     8  	"net/http/httptest"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  
    13  	"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
    14  )
    15  
    16  func gitlabMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
    17  	return func(w http.ResponseWriter, r *http.Request) {
    18  		w.Header().Set("Content-Type", "application/json")
    19  		switch r.RequestURI {
    20  		case "/api/v4":
    21  			fmt.Println("here1")
    22  		case "/api/v4/groups/test-argocd-proton/projects?include_subgroups=false&per_page=100", "/api/v4/groups/test-argocd-proton/projects?include_subgroups=false&per_page=100&topic=&with_shared=false":
    23  			fmt.Println("here")
    24  			_, err := io.WriteString(w, `[{
    25  				"id": 27084533,
    26  				"description": "",
    27  				"name": "argocd",
    28  				"name_with_namespace": "test argocd proton / argocd",
    29  				"path": "argocd",
    30  				"path_with_namespace": "test-argocd-proton/argocd",
    31  				"created_at": "2021-06-01T17:30:44.724Z",
    32  				"default_branch": "master",
    33  				"tag_list": [
    34  					"test-topic"
    35  				],
    36  				"topics": [
    37  					"test-topic"
    38  				],
    39  				"ssh_url_to_repo": "git@gitlab.com:test-argocd-proton/argocd.git",
    40  				"http_url_to_repo": "https://gitlab.com/test-argocd-proton/argocd.git",
    41  				"web_url": "https://gitlab.com/test-argocd-proton/argocd",
    42  				"readme_url": null,
    43  				"avatar_url": null,
    44  				"forks_count": 0,
    45  				"star_count": 0,
    46  				"last_activity_at": "2021-06-04T08:19:51.656Z",
    47  				"namespace": {
    48  					"id": 12258515,
    49  					"name": "test argocd proton",
    50  					"path": "test-argocd-proton",
    51  					"kind": "gro* Connection #0 to host gitlab.com left intact up ",
    52  					"full_path ": "test - argocd - proton ",
    53  					"parent_id ": null,
    54  					"avatar_url ": null,
    55  					"web_url ": "https: //gitlab.com/groups/test-argocd-proton"
    56  				},
    57  				"container_registry_image_prefix": "registry.gitlab.com/test-argocd-proton/argocd",
    58  				"_links": {
    59  					"self": "https://gitlab.com/api/v4/projects/27084533",
    60  					"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
    61  					"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
    62  					"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
    63  					"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
    64  					"events": "https://gitlab.com/api/v4/projects/27084533/events",
    65  					"members": "https://gitlab.com/api/v4/projects/27084533/members",
    66  					"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
    67  				},
    68  				"packages_enabled": true,
    69  				"empty_repo": false,
    70  				"archived": false,
    71  				"visibility": "public",
    72  				"resolve_outdated_diff_discussions": false,
    73  				"container_expiration_policy": {
    74  					"cadence": "1d",
    75  					"enabled": false,
    76  					"keep_n": 10,
    77  					"older_than": "90d",
    78  					"name_regex": ".*",
    79  					"name_regex_keep": null,
    80  					"next_run_at": "2021-06-02T17:30:44.740Z"
    81  				},
    82  				"issues_enabled": true,
    83  				"merge_requests_enabled": true,
    84  				"wiki_enabled": true,
    85  				"jobs_enabled": true,
    86  				"snippets_enabled": true,
    87  				"container_registry_enabled": true,
    88  				"service_desk_enabled": true,
    89  				"can_create_merge_request_in": false,
    90  				"issues_access_level": "enabled",
    91  				"repository_access_level": "enabled",
    92  				"merge_requests_access_level": "enabled",
    93  				"forking_access_level": "enabled",
    94  				"wiki_access_level": "enabled",
    95  				"builds_access_level": "enabled",
    96  				"snippets_access_level": "enabled",
    97  				"pages_access_level": "enabled",
    98  				"operations_access_level": "enabled",
    99  				"analytics_access_level": "enabled",
   100  				"container_registry_access_level": "enabled",
   101  				"security_and_compliance_access_level": "private",
   102  				"emails_disabled": null,
   103  				"shared_runners_enabled": true,
   104  				"lfs_enabled": true,
   105  				"creator_id": 2378866,
   106  				"import_status": "none",
   107  				"open_issues_count": 0,
   108  				"ci_default_git_depth": 50,
   109  				"ci_forward_deployment_enabled": true,
   110  				"ci_job_token_scope_enabled": false,
   111  				"public_jobs": true,
   112  				"build_timeout": 3600,
   113  				"auto_cancel_pending_pipelines": "enabled",
   114  				"ci_config_path": "",
   115  				"shared_with_groups": [],
   116  				"only_allow_merge_if_pipeline_succeeds": false,
   117  				"allow_merge_on_skipped_pipeline": null,
   118  				"restrict_user_defined_variables": false,
   119  				"request_access_enabled": true,
   120  				"only_allow_merge_if_all_discussions_are_resolved": false,
   121  				"remove_source_branch_after_merge": true,
   122  				"printing_merge_request_link_enabled": true,
   123  				"merge_method": "merge",
   124  				"squash_option": "default_off",
   125  				"suggestion_commit_message": null,
   126  				"merge_commit_template": null,
   127  				"squash_commit_template": null,
   128  				"auto_devops_enabled": false,
   129  				"auto_devops_deploy_strategy": "continuous",
   130  				"autoclose_referenced_issues": true,
   131  				"keep_latest_artifact": true,
   132  				"runner_token_expiration_interval": null,
   133  				"approvals_before_merge": 0,
   134  				"mirror": false,
   135  				"external_authorization_classification_label": "",
   136  				"marked_for_deletion_at": null,
   137  				"marked_for_deletion_on": null,
   138  				"requirements_enabled": true,
   139  				"requirements_access_level": "enabled",
   140  				"security_and_compliance_enabled": false,
   141  				"compliance_frameworks": [],
   142  				"issues_template": null,
   143  				"merge_requests_template": null,
   144  				"merge_pipelines_enabled": false,
   145  				"merge_trains_enabled": false
   146  			}]`)
   147  			if err != nil {
   148  				t.Fail()
   149  			}
   150  		case "/api/v4/groups/test-argocd-proton/projects?include_subgroups=true&per_page=100&topic=&with_shared=false":
   151  			fmt.Println("here")
   152  			_, err := io.WriteString(w, `[{
   153  				"id": 27084533,
   154  				"description": "",
   155  				"name": "argocd",
   156  				"name_with_namespace": "test argocd proton / argocd",
   157  				"path": "argocd",
   158  				"path_with_namespace": "test-argocd-proton/argocd",
   159  				"created_at": "2021-06-01T17:30:44.724Z",
   160  				"default_branch": "master",
   161  				"tag_list": [
   162  					"test-topic",
   163  					"specific-topic"
   164  				],
   165  				"topics": [
   166  					"test-topic",
   167  					"specific-topic"
   168  				],
   169  				"ssh_url_to_repo": "git@gitlab.com:test-argocd-proton/argocd.git",
   170  				"http_url_to_repo": "https://gitlab.com/test-argocd-proton/argocd.git",
   171  				"web_url": "https://gitlab.com/test-argocd-proton/argocd",
   172  				"readme_url": null,
   173  				"avatar_url": null,
   174  				"forks_count": 0,
   175  				"star_count": 0,
   176  				"last_activity_at": "2021-06-04T08:19:51.656Z",
   177  				"namespace": {
   178  					"id": 12258515,
   179  					"name": "test argocd proton",
   180  					"path": "test-argocd-proton",
   181  					"kind": "gro* Connection #0 to host gitlab.com left intact up ",
   182  					"full_path ": "test - argocd - proton ",
   183  					"parent_id ": null,
   184  					"avatar_url ": null,
   185  					"web_url ": "https: //gitlab.com/groups/test-argocd-proton"
   186  				},
   187  				"container_registry_image_prefix": "registry.gitlab.com/test-argocd-proton/argocd",
   188  				"_links": {
   189  					"self": "https://gitlab.com/api/v4/projects/27084533",
   190  					"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
   191  					"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
   192  					"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
   193  					"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
   194  					"events": "https://gitlab.com/api/v4/projects/27084533/events",
   195  					"members": "https://gitlab.com/api/v4/projects/27084533/members",
   196  					"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
   197  				},
   198  				"packages_enabled": true,
   199  				"empty_repo": false,
   200  				"archived": false,
   201  				"visibility": "public",
   202  				"resolve_outdated_diff_discussions": false,
   203  				"container_expiration_policy": {
   204  					"cadence": "1d",
   205  					"enabled": false,
   206  					"keep_n": 10,
   207  					"older_than": "90d",
   208  					"name_regex": ".*",
   209  					"name_regex_keep": null,
   210  					"next_run_at": "2021-06-02T17:30:44.740Z"
   211  				},
   212  				"issues_enabled": true,
   213  				"merge_requests_enabled": true,
   214  				"wiki_enabled": true,
   215  				"jobs_enabled": true,
   216  				"snippets_enabled": true,
   217  				"container_registry_enabled": true,
   218  				"service_desk_enabled": true,
   219  				"can_create_merge_request_in": false,
   220  				"issues_access_level": "enabled",
   221  				"repository_access_level": "enabled",
   222  				"merge_requests_access_level": "enabled",
   223  				"forking_access_level": "enabled",
   224  				"wiki_access_level": "enabled",
   225  				"builds_access_level": "enabled",
   226  				"snippets_access_level": "enabled",
   227  				"pages_access_level": "enabled",
   228  				"operations_access_level": "enabled",
   229  				"analytics_access_level": "enabled",
   230  				"container_registry_access_level": "enabled",
   231  				"security_and_compliance_access_level": "private",
   232  				"emails_disabled": null,
   233  				"shared_runners_enabled": true,
   234  				"lfs_enabled": true,
   235  				"creator_id": 2378866,
   236  				"import_status": "none",
   237  				"open_issues_count": 0,
   238  				"ci_default_git_depth": 50,
   239  				"ci_forward_deployment_enabled": true,
   240  				"ci_job_token_scope_enabled": false,
   241  				"public_jobs": true,
   242  				"build_timeout": 3600,
   243  				"auto_cancel_pending_pipelines": "enabled",
   244  				"ci_config_path": "",
   245  				"shared_with_groups": [],
   246  				"only_allow_merge_if_pipeline_succeeds": false,
   247  				"allow_merge_on_skipped_pipeline": null,
   248  				"restrict_user_defined_variables": false,
   249  				"request_access_enabled": true,
   250  				"only_allow_merge_if_all_discussions_are_resolved": false,
   251  				"remove_source_branch_after_merge": true,
   252  				"printing_merge_request_link_enabled": true,
   253  				"merge_method": "merge",
   254  				"squash_option": "default_off",
   255  				"suggestion_commit_message": null,
   256  				"merge_commit_template": null,
   257  				"squash_commit_template": null,
   258  				"auto_devops_enabled": false,
   259  				"auto_devops_deploy_strategy": "continuous",
   260  				"autoclose_referenced_issues": true,
   261  				"keep_latest_artifact": true,
   262  				"runner_token_expiration_interval": null,
   263  				"approvals_before_merge": 0,
   264  				"mirror": false,
   265  				"external_authorization_classification_label": "",
   266  				"marked_for_deletion_at": null,
   267  				"marked_for_deletion_on": null,
   268  				"requirements_enabled": true,
   269  				"requirements_access_level": "enabled",
   270  				"security_and_compliance_enabled": false,
   271  				"compliance_frameworks": [],
   272  				"issues_template": null,
   273  				"merge_requests_template": null,
   274  				"merge_pipelines_enabled": false,
   275  				"merge_trains_enabled": false
   276  			},
   277  			{
   278  				"id": 27084538,
   279  				"description": "This is a Project from a Subgroup",
   280  				"name": "argocd-subgroup",
   281  				"name_with_namespace": "test argocd proton / subgroup / argocd-subgroup",
   282  				"path": "argocd-subgroup",
   283  				"path_with_namespace": "test-argocd-proton/subgroup/argocd-subgroup",
   284  				"created_at": "2021-06-01T17:30:44.724Z",
   285  				"default_branch": "master",
   286  				"tag_list": [
   287  					"test-topic"
   288  				],
   289  				"topics": [
   290  					"test-topic"
   291  				],
   292  				"ssh_url_to_repo": "git@gitlab.com:test-argocd-proton/subgroup/argocd-subgroup.git",
   293  				"http_url_to_repo": "https://gitlab.com/test-argocd-proton/subgroup/argocd-subgroup.git",
   294  				"web_url": "https://gitlab.com/test-argocd-proton/subgroup/argocd-subgroup",
   295  				"readme_url": null,
   296  				"avatar_url": null,
   297  				"forks_count": 0,
   298  				"star_count": 0,
   299  				"last_activity_at": "2021-06-04T08:19:51.656Z",
   300  				"namespace": {
   301  					"id": 12258542,
   302  					"name": "subgroup",
   303  					"path": "subgroup",
   304  					"kind": "group ",
   305  					"full_path ": "test-argocd-proton/subgroup",
   306  					"parent_id ": 12258515,
   307  					"avatar_url ": null,
   308  					"web_url ": "https: //gitlab.com/groups/test-argocd-proton/subgroup"
   309  				},
   310  				"container_registry_image_prefix": "registry.gitlab.com/test-argocd-proton/subgroup/argocd",
   311  				"_links": {
   312  					"self": "https://gitlab.com/api/v4/projects/27084538",
   313  					"issues": "https://gitlab.com/api/v4/projects/27084538/issues",
   314  					"merge_requests": "https://gitlab.com/api/v4/projects/27084538/merge_requests",
   315  					"repo_branches": "https://gitlab.com/api/v4/projects/27084538/repository/branches",
   316  					"labels": "https://gitlab.com/api/v4/projects/27084538/labels",
   317  					"events": "https://gitlab.com/api/v4/projects/27084538/events",
   318  					"members": "https://gitlab.com/api/v4/projects/27084538/members",
   319  					"cluster_agents": "https://gitlab.com/api/v4/projects/27084538/cluster_agents"
   320  				},
   321  				"packages_enabled": true,
   322  				"empty_repo": false,
   323  				"archived": false,
   324  				"visibility": "public",
   325  				"resolve_outdated_diff_discussions": false,
   326  				"container_expiration_policy": {
   327  					"cadence": "1d",
   328  					"enabled": false,
   329  					"keep_n": 10,
   330  					"older_than": "90d",
   331  					"name_regex": ".*",
   332  					"name_regex_keep": null,
   333  					"next_run_at": "2021-06-02T17:30:44.740Z"
   334  				},
   335  				"issues_enabled": true,
   336  				"merge_requests_enabled": true,
   337  				"wiki_enabled": true,
   338  				"jobs_enabled": true,
   339  				"snippets_enabled": true,
   340  				"container_registry_enabled": true,
   341  				"service_desk_enabled": true,
   342  				"can_create_merge_request_in": false,
   343  				"issues_access_level": "enabled",
   344  				"repository_access_level": "enabled",
   345  				"merge_requests_access_level": "enabled",
   346  				"forking_access_level": "enabled",
   347  				"wiki_access_level": "enabled",
   348  				"builds_access_level": "enabled",
   349  				"snippets_access_level": "enabled",
   350  				"pages_access_level": "enabled",
   351  				"operations_access_level": "enabled",
   352  				"analytics_access_level": "enabled",
   353  				"container_registry_access_level": "enabled",
   354  				"security_and_compliance_access_level": "private",
   355  				"emails_disabled": null,
   356  				"shared_runners_enabled": true,
   357  				"lfs_enabled": true,
   358  				"creator_id": 2378866,
   359  				"import_status": "none",
   360  				"open_issues_count": 0,
   361  				"ci_default_git_depth": 50,
   362  				"ci_forward_deployment_enabled": true,
   363  				"ci_job_token_scope_enabled": false,
   364  				"public_jobs": true,
   365  				"build_timeout": 3600,
   366  				"auto_cancel_pending_pipelines": "enabled",
   367  				"ci_config_path": "",
   368  				"shared_with_groups": [],
   369  				"only_allow_merge_if_pipeline_succeeds": false,
   370  				"allow_merge_on_skipped_pipeline": null,
   371  				"restrict_user_defined_variables": false,
   372  				"request_access_enabled": true,
   373  				"only_allow_merge_if_all_discussions_are_resolved": false,
   374  				"remove_source_branch_after_merge": true,
   375  				"printing_merge_request_link_enabled": true,
   376  				"merge_method": "merge",
   377  				"squash_option": "default_off",
   378  				"suggestion_commit_message": null,
   379  				"merge_commit_template": null,
   380  				"squash_commit_template": null,
   381  				"auto_devops_enabled": false,
   382  				"auto_devops_deploy_strategy": "continuous",
   383  				"autoclose_referenced_issues": true,
   384  				"keep_latest_artifact": true,
   385  				"runner_token_expiration_interval": null,
   386  				"approvals_before_merge": 0,
   387  				"mirror": false,
   388  				"external_authorization_classification_label": "",
   389  				"marked_for_deletion_at": null,
   390  				"marked_for_deletion_on": null,
   391  				"requirements_enabled": true,
   392  				"requirements_access_level": "enabled",
   393  				"security_and_compliance_enabled": false,
   394  				"compliance_frameworks": [],
   395  				"issues_template": null,
   396  				"merge_requests_template": null,
   397  				"merge_pipelines_enabled": false,
   398  				"merge_trains_enabled": false
   399  			}
   400  			]`)
   401  			if err != nil {
   402  				t.Fail()
   403  			}
   404  		case "/api/v4/groups/test-argocd-proton/projects?include_subgroups=false&per_page=100&topic=specific-topic&with_shared=false":
   405  			fmt.Println("here")
   406  			_, err := io.WriteString(w, `[{
   407  				"id": 27084533,
   408  				"description": "",
   409  				"name": "argocd",
   410  				"name_with_namespace": "test argocd proton / argocd",
   411  				"path": "argocd",
   412  				"path_with_namespace": "test-argocd-proton/argocd",
   413  				"created_at": "2021-06-01T17:30:44.724Z",
   414  				"default_branch": "master",
   415  				"tag_list": [
   416  					"test-topic",
   417  					"specific-topic"
   418  				],
   419  				"topics": [
   420  					"test-topic",
   421  					"specific-topic"
   422  				],
   423  				"ssh_url_to_repo": "git@gitlab.com:test-argocd-proton/argocd.git",
   424  				"http_url_to_repo": "https://gitlab.com/test-argocd-proton/argocd.git",
   425  				"web_url": "https://gitlab.com/test-argocd-proton/argocd",
   426  				"readme_url": null,
   427  				"avatar_url": null,
   428  				"forks_count": 0,
   429  				"star_count": 0,
   430  				"last_activity_at": "2021-06-04T08:19:51.656Z",
   431  				"namespace": {
   432  					"id": 12258515,
   433  					"name": "test argocd proton",
   434  					"path": "test-argocd-proton",
   435  					"kind": "gro* Connection #0 to host gitlab.com left intact up ",
   436  					"full_path ": "test - argocd - proton ",
   437  					"parent_id ": null,
   438  					"avatar_url ": null,
   439  					"web_url ": "https: //gitlab.com/groups/test-argocd-proton"
   440  				},
   441  				"container_registry_image_prefix": "registry.gitlab.com/test-argocd-proton/argocd",
   442  				"_links": {
   443  					"self": "https://gitlab.com/api/v4/projects/27084533",
   444  					"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
   445  					"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
   446  					"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
   447  					"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
   448  					"events": "https://gitlab.com/api/v4/projects/27084533/events",
   449  					"members": "https://gitlab.com/api/v4/projects/27084533/members",
   450  					"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
   451  				},
   452  				"packages_enabled": true,
   453  				"empty_repo": false,
   454  				"archived": false,
   455  				"visibility": "public",
   456  				"resolve_outdated_diff_discussions": false,
   457  				"container_expiration_policy": {
   458  					"cadence": "1d",
   459  					"enabled": false,
   460  					"keep_n": 10,
   461  					"older_than": "90d",
   462  					"name_regex": ".*",
   463  					"name_regex_keep": null,
   464  					"next_run_at": "2021-06-02T17:30:44.740Z"
   465  				},
   466  				"issues_enabled": true,
   467  				"merge_requests_enabled": true,
   468  				"wiki_enabled": true,
   469  				"jobs_enabled": true,
   470  				"snippets_enabled": true,
   471  				"container_registry_enabled": true,
   472  				"service_desk_enabled": true,
   473  				"can_create_merge_request_in": false,
   474  				"issues_access_level": "enabled",
   475  				"repository_access_level": "enabled",
   476  				"merge_requests_access_level": "enabled",
   477  				"forking_access_level": "enabled",
   478  				"wiki_access_level": "enabled",
   479  				"builds_access_level": "enabled",
   480  				"snippets_access_level": "enabled",
   481  				"pages_access_level": "enabled",
   482  				"operations_access_level": "enabled",
   483  				"analytics_access_level": "enabled",
   484  				"container_registry_access_level": "enabled",
   485  				"security_and_compliance_access_level": "private",
   486  				"emails_disabled": null,
   487  				"shared_runners_enabled": true,
   488  				"lfs_enabled": true,
   489  				"creator_id": 2378866,
   490  				"import_status": "none",
   491  				"open_issues_count": 0,
   492  				"ci_default_git_depth": 50,
   493  				"ci_forward_deployment_enabled": true,
   494  				"ci_job_token_scope_enabled": false,
   495  				"public_jobs": true,
   496  				"build_timeout": 3600,
   497  				"auto_cancel_pending_pipelines": "enabled",
   498  				"ci_config_path": "",
   499  				"shared_with_groups": [],
   500  				"only_allow_merge_if_pipeline_succeeds": false,
   501  				"allow_merge_on_skipped_pipeline": null,
   502  				"restrict_user_defined_variables": false,
   503  				"request_access_enabled": true,
   504  				"only_allow_merge_if_all_discussions_are_resolved": false,
   505  				"remove_source_branch_after_merge": true,
   506  				"printing_merge_request_link_enabled": true,
   507  				"merge_method": "merge",
   508  				"squash_option": "default_off",
   509  				"suggestion_commit_message": null,
   510  				"merge_commit_template": null,
   511  				"squash_commit_template": null,
   512  				"auto_devops_enabled": false,
   513  				"auto_devops_deploy_strategy": "continuous",
   514  				"autoclose_referenced_issues": true,
   515  				"keep_latest_artifact": true,
   516  				"runner_token_expiration_interval": null,
   517  				"approvals_before_merge": 0,
   518  				"mirror": false,
   519  				"external_authorization_classification_label": "",
   520  				"marked_for_deletion_at": null,
   521  				"marked_for_deletion_on": null,
   522  				"requirements_enabled": true,
   523  				"requirements_access_level": "enabled",
   524  				"security_and_compliance_enabled": false,
   525  				"compliance_frameworks": [],
   526  				"issues_template": null,
   527  				"merge_requests_template": null,
   528  				"merge_pipelines_enabled": false,
   529  				"merge_trains_enabled": false
   530  			}
   531  			]`)
   532  			if err != nil {
   533  				t.Fail()
   534  			}
   535  		case "/api/v4/groups/test-argocd-proton/projects?include_subgroups=true&per_page=100&topic=&with_shared=true":
   536  			fmt.Println("here")
   537  			_, err := io.WriteString(w, `[{
   538  				"id": 27084533,
   539  				"description": "",
   540  				"name": "argocd",
   541  				"name_with_namespace": "test argocd proton / argocd",
   542  				"path": "argocd",
   543  				"path_with_namespace": "test-argocd-proton/argocd",
   544  				"created_at": "2021-06-01T17:30:44.724Z",
   545  				"default_branch": "master",
   546  				"tag_list": [
   547  					"test-topic"
   548  				],
   549  				"topics": [
   550  					"test-topic"
   551  				],
   552  				"ssh_url_to_repo": "git@gitlab.com:test-argocd-proton/argocd.git",
   553  				"http_url_to_repo": "https://gitlab.com/test-argocd-proton/argocd.git",
   554  				"web_url": "https://gitlab.com/test-argocd-proton/argocd",
   555  				"readme_url": null,
   556  				"avatar_url": null,
   557  				"forks_count": 0,
   558  				"star_count": 0,
   559  				"last_activity_at": "2021-06-04T08:19:51.656Z",
   560  				"namespace": {
   561  					"id": 12258515,
   562  					"name": "test argocd proton",
   563  					"path": "test-argocd-proton",
   564  					"kind": "gro* Connection #0 to host gitlab.com left intact up ",
   565  					"full_path ": "test - argocd - proton ",
   566  					"parent_id ": null,
   567  					"avatar_url ": null,
   568  					"web_url ": "https: //gitlab.com/groups/test-argocd-proton"
   569  				},
   570  				"container_registry_image_prefix": "registry.gitlab.com/test-argocd-proton/argocd",
   571  				"_links": {
   572  					"self": "https://gitlab.com/api/v4/projects/27084533",
   573  					"issues": "https://gitlab.com/api/v4/projects/27084533/issues",
   574  					"merge_requests": "https://gitlab.com/api/v4/projects/27084533/merge_requests",
   575  					"repo_branches": "https://gitlab.com/api/v4/projects/27084533/repository/branches",
   576  					"labels": "https://gitlab.com/api/v4/projects/27084533/labels",
   577  					"events": "https://gitlab.com/api/v4/projects/27084533/events",
   578  					"members": "https://gitlab.com/api/v4/projects/27084533/members",
   579  					"cluster_agents": "https://gitlab.com/api/v4/projects/27084533/cluster_agents"
   580  				},
   581  				"packages_enabled": true,
   582  				"empty_repo": false,
   583  				"archived": false,
   584  				"visibility": "public",
   585  				"resolve_outdated_diff_discussions": false,
   586  				"container_expiration_policy": {
   587  					"cadence": "1d",
   588  					"enabled": false,
   589  					"keep_n": 10,
   590  					"older_than": "90d",
   591  					"name_regex": ".*",
   592  					"name_regex_keep": null,
   593  					"next_run_at": "2021-06-02T17:30:44.740Z"
   594  				},
   595  				"issues_enabled": true,
   596  				"merge_requests_enabled": true,
   597  				"wiki_enabled": true,
   598  				"jobs_enabled": true,
   599  				"snippets_enabled": true,
   600  				"container_registry_enabled": true,
   601  				"service_desk_enabled": true,
   602  				"can_create_merge_request_in": false,
   603  				"issues_access_level": "enabled",
   604  				"repository_access_level": "enabled",
   605  				"merge_requests_access_level": "enabled",
   606  				"forking_access_level": "enabled",
   607  				"wiki_access_level": "enabled",
   608  				"builds_access_level": "enabled",
   609  				"snippets_access_level": "enabled",
   610  				"pages_access_level": "enabled",
   611  				"operations_access_level": "enabled",
   612  				"analytics_access_level": "enabled",
   613  				"container_registry_access_level": "enabled",
   614  				"security_and_compliance_access_level": "private",
   615  				"emails_disabled": null,
   616  				"shared_runners_enabled": true,
   617  				"lfs_enabled": true,
   618  				"creator_id": 2378866,
   619  				"import_status": "none",
   620  				"open_issues_count": 0,
   621  				"ci_default_git_depth": 50,
   622  				"ci_forward_deployment_enabled": true,
   623  				"ci_job_token_scope_enabled": false,
   624  				"public_jobs": true,
   625  				"build_timeout": 3600,
   626  				"auto_cancel_pending_pipelines": "enabled",
   627  				"ci_config_path": "",
   628  				"shared_with_groups": [],
   629  				"only_allow_merge_if_pipeline_succeeds": false,
   630  				"allow_merge_on_skipped_pipeline": null,
   631  				"restrict_user_defined_variables": false,
   632  				"request_access_enabled": true,
   633  				"only_allow_merge_if_all_discussions_are_resolved": false,
   634  				"remove_source_branch_after_merge": true,
   635  				"printing_merge_request_link_enabled": true,
   636  				"merge_method": "merge",
   637  				"squash_option": "default_off",
   638  				"suggestion_commit_message": null,
   639  				"merge_commit_template": null,
   640  				"squash_commit_template": null,
   641  				"auto_devops_enabled": false,
   642  				"auto_devops_deploy_strategy": "continuous",
   643  				"autoclose_referenced_issues": true,
   644  				"keep_latest_artifact": true,
   645  				"runner_token_expiration_interval": null,
   646  				"approvals_before_merge": 0,
   647  				"mirror": false,
   648  				"external_authorization_classification_label": "",
   649  				"marked_for_deletion_at": null,
   650  				"marked_for_deletion_on": null,
   651  				"requirements_enabled": true,
   652  				"requirements_access_level": "enabled",
   653  				"security_and_compliance_enabled": false,
   654  				"compliance_frameworks": [],
   655  				"issues_template": null,
   656  				"merge_requests_template": null,
   657  				"merge_pipelines_enabled": false,
   658  				"merge_trains_enabled": false
   659  			},
   660  			{
   661  				"id": 27084534,
   662  				"description": "This is a Shared Project",
   663  				"name": "shared-argocd",
   664  				"name_with_namespace": "shared project to test argocd proton / argocd",
   665  				"path": "shared-argocd",
   666  				"path_with_namespace": "test-shared-argocd-proton/shared-argocd",
   667  				"created_at": "2021-06-11T17:30:44.724Z",
   668  				"default_branch": "master",
   669  				"tag_list": [
   670  					"test-topic"
   671  				],
   672  				"topics": [
   673  					"test-topic"
   674  				],
   675  				"ssh_url_to_repo": "git@gitlab.com:test-shared-argocd-proton/shared-argocd.git",
   676  				"http_url_to_repo": "https://gitlab.com/test-shared-argocd-proton/shared-argocd.git",
   677  				"web_url": "https://gitlab.com/test-shared-argocd-proton/shared-argocd",
   678  				"readme_url": null,
   679  				"avatar_url": null,
   680  				"forks_count": 0,
   681  				"star_count": 0,
   682  				"last_activity_at": "2021-06-04T08:19:51.656Z",
   683  				"namespace": {
   684  					"id": 12258518,
   685  					"name": "test shared argocd proton",
   686  					"path": "test-shared-argocd-proton",
   687  					"kind": "group",
   688  					"full_path ": "test-shared-argocd-proton",
   689  					"parent_id ": null,
   690  					"avatar_url ": null,
   691  					"web_url ": "https: //gitlab.com/groups/test-shared-argocd-proton"
   692  				},
   693  				"container_registry_image_prefix": "registry.gitlab.com/test-shared-argocd-proton/shared-argocd",
   694  				"_links": {
   695  					"self": "https://gitlab.com/api/v4/projects/27084534",
   696  					"issues": "https://gitlab.com/api/v4/projects/27084534/issues",
   697  					"merge_requests": "https://gitlab.com/api/v4/projects/27084534/merge_requests",
   698  					"repo_branches": "https://gitlab.com/api/v4/projects/27084534/repository/branches",
   699  					"labels": "https://gitlab.com/api/v4/projects/27084534/labels",
   700  					"events": "https://gitlab.com/api/v4/projects/27084534/events",
   701  					"members": "https://gitlab.com/api/v4/projects/27084534/members",
   702  					"cluster_agents": "https://gitlab.com/api/v4/projects/27084534/cluster_agents"
   703  				},
   704  				"packages_enabled": true,
   705  				"empty_repo": false,
   706  				"archived": false,
   707  				"visibility": "public",
   708  				"resolve_outdated_diff_discussions": false,
   709  				"container_expiration_policy": {
   710  					"cadence": "1d",
   711  					"enabled": false,
   712  					"keep_n": 10,
   713  					"older_than": "90d",
   714  					"name_regex": ".*",
   715  					"name_regex_keep": null,
   716  					"next_run_at": "2021-06-12T17:30:44.740Z"
   717  				},
   718  				"issues_enabled": true,
   719  				"merge_requests_enabled": true,
   720  				"wiki_enabled": true,
   721  				"jobs_enabled": true,
   722  				"snippets_enabled": true,
   723  				"container_registry_enabled": true,
   724  				"service_desk_enabled": true,
   725  				"can_create_merge_request_in": false,
   726  				"issues_access_level": "enabled",
   727  				"repository_access_level": "enabled",
   728  				"merge_requests_access_level": "enabled",
   729  				"forking_access_level": "enabled",
   730  				"wiki_access_level": "enabled",
   731  				"builds_access_level": "enabled",
   732  				"snippets_access_level": "enabled",
   733  				"pages_access_level": "enabled",
   734  				"operations_access_level": "enabled",
   735  				"analytics_access_level": "enabled",
   736  				"container_registry_access_level": "enabled",
   737  				"security_and_compliance_access_level": "private",
   738  				"emails_disabled": null,
   739  				"shared_runners_enabled": true,
   740  				"lfs_enabled": true,
   741  				"creator_id": 2378866,
   742  				"import_status": "none",
   743  				"open_issues_count": 0,
   744  				"ci_default_git_depth": 50,
   745  				"ci_forward_deployment_enabled": true,
   746  				"ci_job_token_scope_enabled": false,
   747  				"public_jobs": true,
   748  				"build_timeout": 3600,
   749  				"auto_cancel_pending_pipelines": "enabled",
   750  				"ci_config_path": "",
   751  				"shared_with_groups": [
   752  					{
   753  						"group_id": 12258515,
   754  						"group_name": "test-argocd-proton",
   755  						"group_full_path": "test-shared-argocd-proton",
   756  						"group_access_level": 30,
   757  						"expires_at": null
   758  					}
   759  				],
   760  				"only_allow_merge_if_pipeline_succeeds": false,
   761  				"allow_merge_on_skipped_pipeline": null,
   762  				"restrict_user_defined_variables": false,
   763  				"request_access_enabled": true,
   764  				"only_allow_merge_if_all_discussions_are_resolved": false,
   765  				"remove_source_branch_after_merge": true,
   766  				"printing_merge_request_link_enabled": true,
   767  				"merge_method": "merge",
   768  				"squash_option": "default_off",
   769  				"suggestion_commit_message": null,
   770  				"merge_commit_template": null,
   771  				"squash_commit_template": null,
   772  				"auto_devops_enabled": false,
   773  				"auto_devops_deploy_strategy": "continuous",
   774  				"autoclose_referenced_issues": true,
   775  				"keep_latest_artifact": true,
   776  				"runner_token_expiration_interval": null,
   777  				"approvals_before_merge": 0,
   778  				"mirror": false,
   779  				"external_authorization_classification_label": "",
   780  				"marked_for_deletion_at": null,
   781  				"marked_for_deletion_on": null,
   782  				"requirements_enabled": true,
   783  				"requirements_access_level": "enabled",
   784  				"security_and_compliance_enabled": false,
   785  				"compliance_frameworks": [],
   786  				"issues_template": null,
   787  				"merge_requests_template": null,
   788  				"merge_pipelines_enabled": false,
   789  				"merge_trains_enabled": false
   790  			}]`)
   791  			if err != nil {
   792  				t.Fail()
   793  			}
   794  		case "/api/v4/projects/27084533/repository/branches/master":
   795  			fmt.Println("returning")
   796  			_, err := io.WriteString(w, `{
   797  				"name": "master",
   798  				"commit": {
   799  					"id": "8898d7999fc99dd0fd578650b58b244fc63f6b53",
   800  					"short_id": "8898d799",
   801  					"created_at": "2021-06-04T08:24:44.000+00:00",
   802  					"parent_ids": ["3c9d50be1ef949ad28674e238c7e12a17b1e9706", "56482e001731640b4123cf177e51c696f08a3005"],
   803  					"title": "Merge branch 'pipeline-1317911429' into 'master'",
   804  					"message": "Merge branch 'pipeline-1317911429' into 'master'\n\n[testapp-ci] manifests/demo/test-app.yaml: release v1.1.0\n\nSee merge request test-argocd-proton/argocd!3",
   805  					"author_name": "Martin Vozník",
   806  					"author_email": "martin@voznik.cz",
   807  					"authored_date": "2021-06-04T08:24:44.000+00:00",
   808  					"committer_name": "Martin Vozník",
   809  					"committer_email": "martin@voznik.cz",
   810  					"committed_date": "2021-06-04T08:24:44.000+00:00",
   811  					"trailers": {},
   812  					"web_url": "https://gitlab.com/test-argocd-proton/argocd/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
   813  				},
   814  				"merged": false,
   815  				"protected": true,
   816  				"developers_can_push": false,
   817  				"developers_can_merge": false,
   818  				"can_push": false,
   819  				"default": true,
   820  				"web_url": "https://gitlab.com/test-argocd-proton/argocd/-/tree/master"
   821  			}`)
   822  			if err != nil {
   823  				t.Fail()
   824  			}
   825  		case "/api/v4/projects/27084533/repository/branches?per_page=100":
   826  			_, err := io.WriteString(w, `[{
   827  				"name": "master",
   828  				"commit": {
   829  					"id": "8898d7999fc99dd0fd578650b58b244fc63f6b53",
   830  					"short_id": "8898d799",
   831  					"created_at": "2021-06-04T08:24:44.000+00:00",
   832  					"parent_ids": null,
   833  					"title": "Merge branch 'pipeline-1317911429' into 'master'",
   834  					"message": "Merge branch 'pipeline-1317911429' into 'master'",
   835  					"author_name": "Martin Vozník",
   836  					"author_email": "martin@voznik.cz",
   837  					"authored_date": "2021-06-04T08:24:44.000+00:00",
   838  					"committer_name": "Martin Vozník",
   839  					"committer_email": "martin@voznik.cz",
   840  					"committed_date": "2021-06-04T08:24:44.000+00:00",
   841  					"trailers": null,
   842  					"web_url": "https://gitlab.com/test-argocd-proton/argocd/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
   843  				},
   844  				"merged": false,
   845  				"protected": true,
   846  				"developers_can_push": false,
   847  				"developers_can_merge": false,
   848  				"can_push": false,
   849  				"default": true,
   850  				"web_url": "https://gitlab.com/test-argocd-proton/argocd/-/tree/master"
   851  			}, {
   852  				"name": "pipeline-1310077506",
   853  				"commit": {
   854  					"id": "0f92540e5f396ba960adea4ed0aa905baf3f73d1",
   855  					"short_id": "0f92540e",
   856  					"created_at": "2021-06-01T18:39:59.000+00:00",
   857  					"parent_ids": null,
   858  					"title": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
   859  					"message": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
   860  					"author_name": "ci-test-app",
   861  					"author_email": "mvoznik+cicd@protonmail.com",
   862  					"authored_date": "2021-06-01T18:39:59.000+00:00",
   863  					"committer_name": "ci-test-app",
   864  					"committer_email": "mvoznik+cicd@protonmail.com",
   865  					"committed_date": "2021-06-01T18:39:59.000+00:00",
   866  					"trailers": null,
   867  					"web_url": "https://gitlab.com/test-argocd-proton/argocd/-/commit/0f92540e5f396ba960adea4ed0aa905baf3f73d1"
   868  				},
   869  				"merged": false,
   870  				"protected": false,
   871  				"developers_can_push": false,
   872  				"developers_can_merge": false,
   873  				"can_push": false,
   874  				"default": false,
   875  				"web_url": "https://gitlab.com/test-argocd-proton/argocd/-/tree/pipeline-1310077506"
   876  			}]`)
   877  			if err != nil {
   878  				t.Fail()
   879  			}
   880  		case "/api/v4/projects/27084534/repository/branches?per_page=100":
   881  			_, err := io.WriteString(w, `[{
   882  				"name": "master",
   883  				"commit": {
   884  					"id": "8898d7999fc99dd0fd578650b58b244fc63f6b53",
   885  					"short_id": "8898d799",
   886  					"created_at": "2021-06-04T08:24:44.000+00:00",
   887  					"parent_ids": null,
   888  					"title": "Merge branch 'pipeline-1317911429' into 'master'",
   889  					"message": "Merge branch 'pipeline-1317911429' into 'master'",
   890  					"author_name": "Martin Vozník",
   891  					"author_email": "martin@voznik.cz",
   892  					"authored_date": "2021-06-04T08:24:44.000+00:00",
   893  					"committer_name": "Martin Vozník",
   894  					"committer_email": "martin@voznik.cz",
   895  					"committed_date": "2021-06-04T08:24:44.000+00:00",
   896  					"trailers": null,
   897  					"web_url": "https://gitlab.com/test-shared-argocd-proton/shared-argocd/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
   898  				},
   899  				"merged": false,
   900  				"protected": true,
   901  				"developers_can_push": false,
   902  				"developers_can_merge": false,
   903  				"can_push": false,
   904  				"default": true,
   905  				"web_url": "https://gitlab.com/test-shared-argocd-proton/shared-argocd/-/tree/master"
   906  			}, {
   907  				"name": "pipeline-2310077506",
   908  				"commit": {
   909  					"id": "0f92540e5f396ba960adea4ed0aa905baf3f73d1",
   910  					"short_id": "0f92540e",
   911  					"created_at": "2021-06-01T18:39:59.000+00:00",
   912  					"parent_ids": null,
   913  					"title": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
   914  					"message": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
   915  					"author_name": "ci-test-app",
   916  					"author_email": "mvoznik+cicd@protonmail.com",
   917  					"authored_date": "2021-06-01T18:39:59.000+00:00",
   918  					"committer_name": "ci-test-app",
   919  					"committer_email": "mvoznik+cicd@protonmail.com",
   920  					"committed_date": "2021-06-01T18:39:59.000+00:00",
   921  					"trailers": null,
   922  					"web_url": "https://gitlab.com/test-shared-argocd-proton/shared-argocd/-/commit/0f92540e5f396ba960adea4ed0aa905baf3f73d1"
   923  				},
   924  				"merged": false,
   925  				"protected": false,
   926  				"developers_can_push": false,
   927  				"developers_can_merge": false,
   928  				"can_push": false,
   929  				"default": false,
   930  				"web_url": "https://gitlab.com/test-shared-argocd-proton/shared-argocd/-/tree/pipeline-1310077506"
   931  			}]`)
   932  			if err != nil {
   933  				t.Fail()
   934  			}
   935  		case "/api/v4/projects/27084538/repository/branches?per_page=100":
   936  			_, err := io.WriteString(w, `[{
   937  				"name": "master",
   938  				"commit": {
   939  					"id": "8898d7999fc99dd0fd578650b58b244fc63f6b58",
   940  					"short_id": "8898d801",
   941  					"created_at": "2021-06-04T08:24:44.000+00:00",
   942  					"parent_ids": null,
   943  					"title": "Merge branch 'pipeline-1317911429' into 'master'",
   944  					"message": "Merge branch 'pipeline-1317911429' into 'master'",
   945  					"author_name": "Martin Vozník",
   946  					"author_email": "martin@voznik.cz",
   947  					"authored_date": "2021-06-04T08:24:44.000+00:00",
   948  					"committer_name": "Martin Vozník",
   949  					"committer_email": "martin@voznik.cz",
   950  					"committed_date": "2021-06-04T08:24:44.000+00:00",
   951  					"trailers": null,
   952  					"web_url": "https://gitlab.com/test-argocd-proton/subgroup/argocd-subgroup/-/commit/8898d7999fc99dd0fd578650b58b244fc63f6b53"
   953  				},
   954  				"merged": false,
   955  				"protected": true,
   956  				"developers_can_push": false,
   957  				"developers_can_merge": false,
   958  				"can_push": false,
   959  				"default": true,
   960  				"web_url": "https://gitlab.com/test-argocd-proton/subgroup/argocd-subgroup/-/tree/master"
   961  			}, {
   962  				"name": "pipeline-2310077506",
   963  				"commit": {
   964  					"id": "0f92540e5f396ba960adea4ed0aa905baf3f73d1",
   965  					"short_id": "0f92540e",
   966  					"created_at": "2021-06-01T18:39:59.000+00:00",
   967  					"parent_ids": null,
   968  					"title": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
   969  					"message": "[testapp-ci] manifests/demo/test-app.yaml: release v1.0.1",
   970  					"author_name": "ci-test-app",
   971  					"author_email": "mvoznik+cicd@protonmail.com",
   972  					"authored_date": "2021-06-01T18:39:59.000+00:00",
   973  					"committer_name": "ci-test-app",
   974  					"committer_email": "mvoznik+cicd@protonmail.com",
   975  					"committed_date": "2021-06-01T18:39:59.000+00:00",
   976  					"trailers": null,
   977  					"web_url": "https://gitlab.com/test-argocd-proton/subgroup/argocd-subgroup/-/commit/0f92540e5f396ba960adea4ed0aa905baf3f73d1"
   978  				},
   979  				"merged": false,
   980  				"protected": false,
   981  				"developers_can_push": false,
   982  				"developers_can_merge": false,
   983  				"can_push": false,
   984  				"default": false,
   985  				"web_url": "https://gitlab.com/test-argocd-proton/subgroup/argocd-subgroup/-/tree/pipeline-1310077506"
   986  			}]`)
   987  			if err != nil {
   988  				t.Fail()
   989  			}
   990  		case "/api/v4/projects/test-argocd-proton%2Fargocd":
   991  			fmt.Println("auct")
   992  			_, err := io.WriteString(w, `{
   993  				"id": 27084533,
   994  				"description": "",
   995  				"name": "argocd",
   996  				"name_with_namespace": "test argocd proton / argocd",
   997  				"path": "argocd",
   998  				"path_with_namespace": "test-argocd-proton/argocd",
   999  				"created_at": "2021-06-01T17:30:44.724Z",
  1000  				"default_branch": "master",
  1001  				"tag_list": [
  1002  					"test-topic"
  1003  				],
  1004  				"topics": [
  1005  					"test-topic"
  1006  				],
  1007  				"ssh_url_to_repo": "git@gitlab.com:test-argocd-proton/argocd.git",
  1008  				"http_url_to_repo": "https://gitlab.com/test-argocd-proton/argocd.git",
  1009  				"web_url": "https://gitlab.com/test-argocd-proton/argocd",
  1010  				"readme_url": null,
  1011  				"avatar_url": null,
  1012  				"forks_count": 0,
  1013  				"star_count": 0,
  1014  				"last_activity_at": "2021-06-04T08:19:51.656Z",
  1015  				"namespace": {
  1016  					"id": 12258515,
  1017  					"name": "test argocd proton",
  1018  					"path": "test-argocd-proton",
  1019  					"kind": "group",
  1020  					"full_path": "test-argocd-proton",
  1021  					"parent_id": null,
  1022  					"avatar_url": null,
  1023  					"web_url": "https://gitlab.com/groups/test-argocd-proton"
  1024  				}
  1025  			}`)
  1026  			if err != nil {
  1027  				t.Fail()
  1028  			}
  1029  		case "/api/v4/projects/27084533/repository/tree?path=argocd&ref=master":
  1030  			_, err := io.WriteString(w, `[{"id":"ca14f2a3718159c74572a5325fb4bfb0662a2d3e","name":"ingress.yaml","type":"blob","path":"argocd/ingress.yaml","mode":"100644"},{"id":"de2a53a73b1550b3e0f4d37ea0a6d878bf9c5096","name":"install.yaml","type":"blob","path":"argocd/install.yaml","mode":"100644"}]`)
  1031  			if err != nil {
  1032  				t.Fail()
  1033  			}
  1034  		case "/api/v4/projects/27084533/repository/tree?path=.&ref=master":
  1035  			_, err := io.WriteString(w, `[{"id":"f2bf99fa8f7a27df9c43d2dffc8c8cd747f3181a","name":"argocd","type":"tree","path":"argocd","mode":"040000"},{"id":"68a3125232e01c1583a6a6299534ce10c5e7dd83","name":"manifests","type":"tree","path":"manifests","mode":"040000"}]`)
  1036  			if err != nil {
  1037  				t.Fail()
  1038  			}
  1039  		case "/api/v4/projects/27084533/repository/branches/foo":
  1040  			w.WriteHeader(http.StatusNotFound)
  1041  		default:
  1042  			_, err := io.WriteString(w, `[]`)
  1043  			if err != nil {
  1044  				t.Fail()
  1045  			}
  1046  		}
  1047  	}
  1048  }
  1049  func TestGitlabListRepos(t *testing.T) {
  1050  	cases := []struct {
  1051  		name, proto, url, topic                                                  string
  1052  		hasError, allBranches, includeSubgroups, includeSharedProjects, insecure bool
  1053  		branches                                                                 []string
  1054  		filters                                                                  []v1alpha1.SCMProviderGeneratorFilter
  1055  	}{
  1056  		{
  1057  			name:     "blank protocol",
  1058  			url:      "git@gitlab.com:test-argocd-proton/argocd.git",
  1059  			branches: []string{"master"},
  1060  		},
  1061  		{
  1062  			name:  "ssh protocol",
  1063  			proto: "ssh",
  1064  			url:   "git@gitlab.com:test-argocd-proton/argocd.git",
  1065  		},
  1066  		{
  1067  			name:  "labelmatch",
  1068  			proto: "ssh",
  1069  			url:   "git@gitlab.com:test-argocd-proton/argocd.git",
  1070  			filters: []v1alpha1.SCMProviderGeneratorFilter{
  1071  				{
  1072  					LabelMatch: strp("test-topic"),
  1073  				},
  1074  			},
  1075  		},
  1076  		{
  1077  			name:  "https protocol",
  1078  			proto: "https",
  1079  			url:   "https://gitlab.com/test-argocd-proton/argocd.git",
  1080  		},
  1081  		{
  1082  			name:     "other protocol",
  1083  			proto:    "other",
  1084  			hasError: true,
  1085  		},
  1086  		{
  1087  			name:        "all branches",
  1088  			allBranches: true,
  1089  			url:         "git@gitlab.com:test-argocd-proton/argocd.git",
  1090  			branches:    []string{"master"},
  1091  		},
  1092  		{
  1093  			name:                  "all subgroups",
  1094  			allBranches:           true,
  1095  			url:                   "git@gitlab.com:test-argocd-proton/argocd.git",
  1096  			branches:              []string{"master"},
  1097  			includeSharedProjects: false,
  1098  			includeSubgroups:      true,
  1099  		},
  1100  		{
  1101  			name:                  "all subgroups and shared projects",
  1102  			allBranches:           true,
  1103  			url:                   "git@gitlab.com:test-argocd-proton/argocd.git",
  1104  			branches:              []string{"master"},
  1105  			includeSharedProjects: true,
  1106  			includeSubgroups:      true,
  1107  		},
  1108  		{
  1109  			name:             "specific topic",
  1110  			allBranches:      true,
  1111  			url:              "git@gitlab.com:test-argocd-proton/argocd.git",
  1112  			branches:         []string{"master"},
  1113  			includeSubgroups: false,
  1114  			topic:            "specific-topic",
  1115  		},
  1116  	}
  1117  	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  1118  		gitlabMockHandler(t)(w, r)
  1119  	}))
  1120  	for _, c := range cases {
  1121  		t.Run(c.name, func(t *testing.T) {
  1122  			provider, _ := NewGitlabProvider(context.Background(), "test-argocd-proton", "", ts.URL, c.allBranches, c.includeSubgroups, c.includeSharedProjects, c.insecure, "", c.topic)
  1123  			rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto)
  1124  			if c.hasError {
  1125  				assert.NotNil(t, err)
  1126  			} else {
  1127  				assert.Nil(t, err)
  1128  				// Just check that this one project shows up. Not a great test but better than nothing?
  1129  				repos := []*Repository{}
  1130  				uniqueRepos := map[string]int{}
  1131  				branches := []string{}
  1132  				for _, r := range rawRepos {
  1133  					if r.Repository == "argocd" {
  1134  						repos = append(repos, r)
  1135  						branches = append(branches, r.Branch)
  1136  					}
  1137  					uniqueRepos[r.Repository]++
  1138  				}
  1139  				assert.NotEmpty(t, repos)
  1140  				assert.Equal(t, c.url, repos[0].URL)
  1141  				for _, b := range c.branches {
  1142  					assert.Contains(t, branches, b)
  1143  				}
  1144  				// In case of listing subgroups, validate the number of returned projects
  1145  				if c.includeSubgroups || c.includeSharedProjects {
  1146  					assert.Equal(t, 2, len(uniqueRepos))
  1147  				}
  1148  				// In case we filter on the topic, ensure we got only one repo returned
  1149  				if c.topic != "" {
  1150  					assert.Equal(t, 1, len(uniqueRepos))
  1151  				}
  1152  			}
  1153  		})
  1154  	}
  1155  }
  1156  
  1157  func TestGitlabHasPath(t *testing.T) {
  1158  	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  1159  		gitlabMockHandler(t)(w, r)
  1160  	}))
  1161  	host, _ := NewGitlabProvider(context.Background(), "test-argocd-proton", "", ts.URL, false, true, true, false, "", "")
  1162  	repo := &Repository{
  1163  		Organization: "test-argocd-proton",
  1164  		Repository:   "argocd",
  1165  		Branch:       "master",
  1166  	}
  1167  
  1168  	cases := []struct {
  1169  		name, path string
  1170  		exists     bool
  1171  	}{
  1172  		{
  1173  			name:   "directory exists",
  1174  			path:   "argocd",
  1175  			exists: true,
  1176  		},
  1177  		{
  1178  			name:   "file exists",
  1179  			path:   "argocd/install.yaml",
  1180  			exists: true,
  1181  		},
  1182  		{
  1183  			name:   "directory does not exist",
  1184  			path:   "notathing",
  1185  			exists: false,
  1186  		},
  1187  		{
  1188  			name:   "file does not exist",
  1189  			path:   "argocd/notathing.yaml",
  1190  			exists: false,
  1191  		},
  1192  	}
  1193  
  1194  	for _, c := range cases {
  1195  		t.Run(c.name, func(t *testing.T) {
  1196  			ok, err := host.RepoHasPath(context.Background(), repo, c.path)
  1197  			assert.Nil(t, err)
  1198  			assert.Equal(t, c.exists, ok)
  1199  		})
  1200  	}
  1201  }
  1202  
  1203  func TestGitlabGetBranches(t *testing.T) {
  1204  	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  1205  		gitlabMockHandler(t)(w, r)
  1206  	}))
  1207  	host, _ := NewGitlabProvider(context.Background(), "test-argocd-proton", "", ts.URL, false, true, true, false, "", "")
  1208  
  1209  	repo := &Repository{
  1210  		RepositoryId: 27084533,
  1211  		Branch:       "master",
  1212  	}
  1213  	t.Run("branch exists", func(t *testing.T) {
  1214  		repos, err := host.GetBranches(context.Background(), repo)
  1215  		assert.Nil(t, err)
  1216  		assert.Equal(t, repos[0].Branch, "master")
  1217  	})
  1218  
  1219  	repo2 := &Repository{
  1220  		RepositoryId: 27084533,
  1221  		Branch:       "foo",
  1222  	}
  1223  	t.Run("unknown branch", func(t *testing.T) {
  1224  		_, err := host.GetBranches(context.Background(), repo2)
  1225  		assert.NoError(t, err)
  1226  	})
  1227  }