summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-galaxy-collection-scm/tasks/requirements.yml
blob: 10070f1a052fd5671e1697d1ad337ebc59bc7316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
- name: make a requirements directory
  file:
    state: directory
    path: '{{ galaxy_dir }}/requirements'

- name: populate requirement templates
  template:
    src: "{{ item }}"
    dest: "{{ galaxy_dir }}/requirements/{{ item }}"
  loop:
    - source_only.yml
    - source_and_name.yml
    - source_and_name_and_type.yml
    - name_without_type.yml
    - git_prefix_name.yml
    - name_and_type.yml

- name: test source is not a git repo
  command: 'ansible-galaxy collection install -r source_only.yml'
  register: result
  ignore_errors: true
  args:
    chdir: '{{ galaxy_dir }}/requirements'

- assert:
    that:
      - result.failed
      - >-
        "ERROR! Neither the collection requirement entry key 'name',
        nor 'source' point to a concrete resolvable collection artifact.
        Also 'name' is not an FQCN. A valid collection name must be in
        the format <namespace>.<collection>. Please make sure that the
        namespace and the collection name contain characters from
        [a-zA-Z0-9_] only." in result.stderr

- name: test source is not a git repo even if name is provided
  command: 'ansible-galaxy collection install -r source_and_name.yml'
  register: result
  ignore_errors: true
  args:
    chdir: '{{ galaxy_dir }}/requirements'

- assert:
    that:
      - result.failed
      - >-
        result.stderr is search("ERROR! Collections requirement 'source'
        entry should contain a valid Galaxy API URL but it does not:
        git\+file:///.*/amazon.aws/.git is not an HTTP URL.")

- name: test source is not a git repo even if name and type is provided
  command: 'ansible-galaxy collection install -r source_and_name_and_type.yml'
  register: result
  ignore_errors: true
  args:
    chdir: '{{ galaxy_dir }}/requirements'

- assert:
    that:
      - result.failed
      - >-
        result.stderr is search("ERROR! Failed to clone a Git repository
        from `file:///.*/.git`.")
      - >-
        result.stderr is search("fatal: '/.*/amazon.aws/.git' does not
        appear to be a git repository")

- name: test using name as a git repo without git+ prefix
  command: 'ansible-galaxy collection install -r name_without_type.yml --no-deps'
  register: result
  ignore_errors: true
  args:
    chdir: '{{ galaxy_dir }}/requirements'

- assert:
    that:
      - result.failed
      - '"name must be in the format <namespace>.<collection>" in result.stderr'

- name: Clone a git repository
  git:
    repo: https://github.com/ansible-collections/amazon.aws.git
    dest: '{{ scm_path }}/amazon.aws/'

- name: test using name as a git repo
  command: 'ansible-galaxy collection install -r git_prefix_name.yml --no-deps'
  register: result
  args:
    chdir: '{{ galaxy_dir }}/requirements'

- name: test using name plus type as a git repo
  command: 'ansible-galaxy collection install -r name_and_type.yml --force --no-deps'
  register: result
  args:
    chdir: '{{ galaxy_dir }}/requirements'

- name: remove the test repo and requirements dir
  file:
    path: '{{ item }}'
    state: absent
  loop:
    - '{{ scm_path }}/amazon.aws/'
    - '{{ galaxy_dir }}/requirements'