From a2c8481395e7bd142b415729651ec2b691c1f951 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 31 Aug 2017 00:20:45 +0530 Subject: [PATCH] Add testcases for github_issue (#26309) Signed-off-by: Abhijeet Kasurde --- .../modules/source_control/github_issue.py | 2 +- test/integration/targets/github_issue/aliases | 1 + .../targets/github_issue/tasks/main.yml | 69 +++++++++++++++++++ .../targets/github_issue/vars/main.yml | 6 ++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/github_issue/aliases create mode 100644 test/integration/targets/github_issue/tasks/main.yml create mode 100644 test/integration/targets/github_issue/vars/main.yml diff --git a/lib/ansible/modules/source_control/github_issue.py b/lib/ansible/modules/source_control/github_issue.py index 0121d4b4e1..5f64c27b02 100644 --- a/lib/ansible/modules/source_control/github_issue.py +++ b/lib/ansible/modules/source_control/github_issue.py @@ -103,7 +103,7 @@ def main(): result = dict() gh_obj = github3.issue(organization, repo, issue) - if isinstance(gh_obj, github3.null.NullObject): + if gh_obj is None: module.fail_json(msg="Failed to get details about issue specified. " "Please check organization, repo and issue " "details and try again.") diff --git a/test/integration/targets/github_issue/aliases b/test/integration/targets/github_issue/aliases new file mode 100644 index 0000000000..4485d76162 --- /dev/null +++ b/test/integration/targets/github_issue/aliases @@ -0,0 +1 @@ +posix/ci/group1 diff --git a/test/integration/targets/github_issue/tasks/main.yml b/test/integration/targets/github_issue/tasks/main.yml new file mode 100644 index 0000000000..fb29058b1e --- /dev/null +++ b/test/integration/targets/github_issue/tasks/main.yml @@ -0,0 +1,69 @@ +# Test code for the github_issue module. +# (c) 2017, Abhijeet Kasurde + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +# + +# Testcase 0001: Check if dependency is installed +- name: Check if github3.py is installed or not + github_issue: + organization: "{{ organization }}" + repo: "{{ repo }}" + issue: "{{ non_existent_issue }}" + action: get_status + register: lib_missing + ignore_errors: True + +- assert: + that: + - "{{ lib_missing.failed == True }}" + - "{{ lib_missing.changed == False }}" + - "{{ 'Missing required github3 module.' in lib_missing.msg }}" + +- name: make sure github3.py is installed + pip: + name: github3.py + state: latest + +# Testcase 0002: Check if issue exists +- name: Check if GitHub issue is closed or not + github_issue: + organization: "{{ organization }}" + repo: "{{ repo }}" + issue: "{{ issue }}" + action: get_status + register: get_status_0002 + +- assert: + that: + - "{{ get_status_0002.changed == True }}" + - "{{ get_status_0002.issue_status == 'closed' }}" + +# Testcase 0003: Check non-existent issue status +- name: Check if GitHub issue is closed or not + github_issue: + organization: "{{ organization }}" + repo: "{{ repo }}" + issue: "{{ non_existent_issue }}" + action: get_status + register: get_status_0003 + ignore_errors: True + +- assert: + that: + - "{{ get_status_0003.changed == False }}" + - "{{ get_status_0003.failed == True }}" + - "{{ 'Failed' in get_status_0003.msg }}" diff --git a/test/integration/targets/github_issue/vars/main.yml b/test/integration/targets/github_issue/vars/main.yml new file mode 100644 index 0000000000..52546d3f7c --- /dev/null +++ b/test/integration/targets/github_issue/vars/main.yml @@ -0,0 +1,6 @@ +--- + +issue: 23642 +non_existent_issue: 1111111 +organization: ansible +repo: ansible