Merge pull request #6 from Azure/users/atbagga/addtests

Adding sample unit tests and setting up test run in CI
This commit is contained in:
Atul Bagga 2020-01-30 15:48:16 +05:30 коммит произвёл GitHub
Родитель e44a41cf5a 0893af84b4
Коммит e074fa92d2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 87 добавлений и 1 удалений

Просмотреть файл

@ -71,3 +71,22 @@ jobs:
targetType: 'filePath'
filePath: 'scripts/runStyleCheck.ps1'
- job: 'Run_Test_Ubuntu'
dependsOn : Build_Publish_Azure_CLI_Test_SDK
pool:
vmImage: 'Ubuntu-16.04'
strategy:
matrix:
Python37:
python.version: '3.7.x'
PythonLatest:
python.version: '3.x'
maxParallel: 3
steps:
- bash: sudo rm -R -f /usr/local/lib/azureExtensionDir
- template: templates/run-tests.yml
parameters:
pythonVersion: '$(python.version)'

Просмотреть файл

@ -4,7 +4,7 @@ steps:
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'ak-deploy-cli-extension'
artifactName: 'deploy-to-azure-cli-extension'
downloadPath: '$(System.ArtifactsDirectory)/extension'
- task: PowerShell@2

Просмотреть файл

@ -0,0 +1,38 @@
parameters:
pythonVersion: ''
runOnlyRecordedTests: 'false'
runWithAzureCliReleased: 'false'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: ${{ parameters.pythonVersion }}
architecture: 'x64'
- ${{ if eq(parameters.runWithAzureCliReleased, 'false') }}:
- template: install-azure-cli-edge.yml
- ${{ if eq(parameters.runWithAzureCliReleased, 'true') }}:
- template: install-azure-cli-released.yml
- template: download-install-local-azure-test-sdk.yml
- template: setup-ci-machine.yml
- template: download-install-local-deploy-to-azure-cli-extension.yml
- ${{ if eq(parameters.runOnlyRecordedTests, 'false') }}:
- script: pytest --junitxml "TEST-results.xml"
displayName: 'Run Tests'
- ${{ if eq(parameters.runOnlyRecordedTests, 'true') }}:
- script: pytest tests --junitxml "TEST-results.xml"
displayName: 'Run Tests'
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**TEST-*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)'
condition: succeededOrFailed()

Просмотреть файл

@ -0,0 +1,29 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import unittest
try:
# Attempt to load mock (works on Python 3.3 and above)
from unittest.mock import patch
except ImportError:
# Attempt to load mock (works on Python version below 3.3)
from mock import patch
from azext_deploy_to_azure.dev.common.git import is_github_url_candidate
class TestGitMethods(unittest.TestCase):
def test_github_url_candidate(self):
self.assertEqual(is_github_url_candidate(url='https://github.com/org/repo'), True)
self.assertEqual(is_github_url_candidate(url='https://github.com/org/repo/'), True)
self.assertEqual(is_github_url_candidate(url='https://github.com/org'), True)
self.assertEqual(is_github_url_candidate(url='https://github.com'), True)
self.assertEqual(is_github_url_candidate(url='https://dev.azure.com/org'), False)
self.assertEqual(is_github_url_candidate(url='https://github.in/org/repo'), False)
self.assertEqual(is_github_url_candidate(url=None), False)
self.assertEqual(is_github_url_candidate(url='not a url'), False)
if __name__ == '__main__':
unittest.main()