2020-02-23 03:09:29 +08:00
|
|
|
#***************************************************************************
|
|
|
|
# _ _ ____ _
|
|
|
|
# Project ___| | | | _ \| |
|
|
|
|
# / __| | | | |_) | |
|
|
|
|
# | (__| |_| | _ <| |___
|
|
|
|
# \___|\___/|_| \_\_____|
|
|
|
|
#
|
2023-01-02 20:51:48 +08:00
|
|
|
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
|
|
# Copyright (C) Marc Hoersken, <info@marc-hoersken.de>
|
2020-02-23 03:09:29 +08:00
|
|
|
#
|
|
|
|
# This software is licensed as described in the file COPYING, which
|
|
|
|
# you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
# are also available at https://curl.se/docs/copyright.html.
|
2020-02-23 03:09:29 +08:00
|
|
|
#
|
|
|
|
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
# copies of the Software, and permit persons to whom the Software is
|
|
|
|
# furnished to do so, under the terms of the COPYING file.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
#
|
2020-02-23 03:09:29 +08:00
|
|
|
###########################################################################
|
|
|
|
|
2023-04-06 03:28:26 +08:00
|
|
|
package azure;
|
|
|
|
|
2020-02-23 03:09:29 +08:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2023-04-06 03:28:26 +08:00
|
|
|
BEGIN {
|
|
|
|
use base qw(Exporter);
|
|
|
|
|
|
|
|
our @EXPORT = qw(
|
|
|
|
azure_check_environment
|
|
|
|
azure_create_test_run
|
|
|
|
azure_create_test_result
|
|
|
|
azure_update_test_result
|
|
|
|
azure_update_test_run
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-23 03:09:29 +08:00
|
|
|
use POSIX qw(strftime);
|
|
|
|
|
|
|
|
sub azure_check_environment {
|
2020-03-01 21:49:35 +08:00
|
|
|
if(defined $ENV{'AZURE_ACCESS_TOKEN'} && $ENV{'AZURE_ACCESS_TOKEN'} &&
|
2020-02-23 03:09:29 +08:00
|
|
|
defined $ENV{'AGENT_JOBNAME'} && $ENV{'BUILD_BUILDID'} &&
|
|
|
|
defined $ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'} &&
|
|
|
|
defined $ENV{'SYSTEM_TEAMPROJECTID'}) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub azure_create_test_run {
|
2020-10-12 12:52:40 +08:00
|
|
|
my ($curl)=@_;
|
2020-02-23 03:09:29 +08:00
|
|
|
my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
|
2020-10-12 12:52:40 +08:00
|
|
|
my $azure_run=`$curl --silent --noproxy "*" \\
|
2020-02-23 03:09:29 +08:00
|
|
|
--header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
|
|
|
|
--header "Content-Type: application/json" \\
|
|
|
|
--data "
|
|
|
|
{
|
|
|
|
'name': '$ENV{'AGENT_JOBNAME'}',
|
|
|
|
'automated': true,
|
|
|
|
'build': {'id': '$ENV{'BUILD_BUILDID'}'}
|
|
|
|
}
|
|
|
|
" \\
|
2020-08-09 21:56:59 +08:00
|
|
|
"$azure_baseurl/_apis/test/runs?api-version=5.1"`;
|
2020-02-23 03:09:29 +08:00
|
|
|
if($azure_run =~ /"id":(\d+)/) {
|
|
|
|
return $1;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub azure_create_test_result {
|
2020-10-12 12:52:40 +08:00
|
|
|
my ($curl, $azure_run_id, $testnum, $testname)=@_;
|
2020-03-04 03:05:58 +08:00
|
|
|
$testname =~ s/\\/\\\\/g;
|
|
|
|
$testname =~ s/\"/\\\"/g;
|
2023-04-23 02:25:10 +08:00
|
|
|
$testname =~ s/\'/'"'"'/g;
|
2020-09-07 03:27:41 +08:00
|
|
|
my $title_testnum=sprintf("%04d", $testnum);
|
2020-02-23 03:09:29 +08:00
|
|
|
my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
|
2023-04-23 02:25:10 +08:00
|
|
|
my $azure_result=`$curl --silent --noproxy '*' \\
|
2020-02-23 03:09:29 +08:00
|
|
|
--header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
|
2023-04-23 02:25:10 +08:00
|
|
|
--header 'Content-Type: application/json' \\
|
|
|
|
--data '
|
2020-02-23 03:09:29 +08:00
|
|
|
[
|
|
|
|
{
|
2023-04-23 02:25:10 +08:00
|
|
|
"build": {"id": "$ENV{'BUILD_BUILDID'}"},
|
|
|
|
"testCase": {"id": $testnum},
|
|
|
|
"testCaseTitle": "$title_testnum: $testname",
|
|
|
|
"testCaseRevision": 2,
|
|
|
|
"automatedTestName": "curl.tests.$testnum",
|
|
|
|
"outcome": "InProgress"
|
2020-02-23 03:09:29 +08:00
|
|
|
}
|
|
|
|
]
|
2023-04-23 02:25:10 +08:00
|
|
|
' \\
|
|
|
|
'$azure_baseurl/_apis/test/runs/$azure_run_id/results?api-version=5.1'`;
|
2020-02-23 03:09:29 +08:00
|
|
|
if($azure_result =~ /\[\{"id":(\d+)/) {
|
|
|
|
return $1;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub azure_update_test_result {
|
2020-10-12 12:52:40 +08:00
|
|
|
my ($curl, $azure_run_id, $azure_result_id, $testnum, $error, $start, $stop)=@_;
|
2020-02-23 03:09:29 +08:00
|
|
|
if(!defined $stop) {
|
|
|
|
$stop = $start;
|
|
|
|
}
|
|
|
|
my $azure_start = strftime "%Y-%m-%dT%H:%M:%SZ", gmtime $start;
|
|
|
|
my $azure_complete = strftime "%Y-%m-%dT%H:%M:%SZ", gmtime $stop;
|
|
|
|
my $azure_duration = sprintf("%.0f", ($stop-$start)*1000);
|
|
|
|
my $azure_outcome;
|
2020-03-02 21:05:59 +08:00
|
|
|
if($error == 2) {
|
2020-08-09 21:56:59 +08:00
|
|
|
$azure_outcome = 'NotApplicable';
|
2020-03-02 21:05:59 +08:00
|
|
|
}
|
|
|
|
elsif($error < 0) {
|
2020-08-09 21:56:59 +08:00
|
|
|
$azure_outcome = 'NotExecuted';
|
2020-02-23 03:09:29 +08:00
|
|
|
}
|
|
|
|
elsif(!$error) {
|
|
|
|
$azure_outcome = 'Passed';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$azure_outcome = 'Failed';
|
|
|
|
}
|
|
|
|
my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
|
2023-04-23 02:25:10 +08:00
|
|
|
my $azure_result=`$curl --silent --noproxy '*' --request PATCH \\
|
2020-02-23 03:09:29 +08:00
|
|
|
--header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
|
|
|
|
--header "Content-Type: application/json" \\
|
2023-04-23 02:25:10 +08:00
|
|
|
--data '
|
2020-02-23 03:09:29 +08:00
|
|
|
[
|
|
|
|
{
|
2023-04-23 02:25:10 +08:00
|
|
|
"id": $azure_result_id,
|
|
|
|
"outcome": "$azure_outcome",
|
|
|
|
"startedDate": "$azure_start",
|
|
|
|
"completedDate": "$azure_complete",
|
|
|
|
"durationInMs": $azure_duration
|
2020-02-23 03:09:29 +08:00
|
|
|
}
|
|
|
|
]
|
2023-04-23 02:25:10 +08:00
|
|
|
' \\
|
|
|
|
'$azure_baseurl/_apis/test/runs/$azure_run_id/results?api-version=5.1'`;
|
2020-02-23 03:09:29 +08:00
|
|
|
if($azure_result =~ /\[\{"id":(\d+)/) {
|
|
|
|
return $1;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub azure_update_test_run {
|
2020-10-12 12:52:40 +08:00
|
|
|
my ($curl, $azure_run_id)=@_;
|
2020-02-23 03:09:29 +08:00
|
|
|
my $azure_baseurl="$ENV{'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'}$ENV{'SYSTEM_TEAMPROJECTID'}";
|
2023-04-23 02:25:10 +08:00
|
|
|
my $azure_run=`$curl --silent --noproxy '*' --request PATCH \\
|
2020-02-23 03:09:29 +08:00
|
|
|
--header "Authorization: Bearer $ENV{'AZURE_ACCESS_TOKEN'}" \\
|
2023-04-23 02:25:10 +08:00
|
|
|
--header 'Content-Type: application/json' \\
|
|
|
|
--data '
|
2020-02-23 03:09:29 +08:00
|
|
|
{
|
2023-04-23 02:25:10 +08:00
|
|
|
"state": "Completed"
|
2020-02-23 03:09:29 +08:00
|
|
|
}
|
2023-04-23 02:25:10 +08:00
|
|
|
' \\
|
|
|
|
'$azure_baseurl/_apis/test/runs/$azure_run_id?api-version=5.1'`;
|
2020-02-23 03:09:29 +08:00
|
|
|
if($azure_run =~ /"id":(\d+)/) {
|
|
|
|
return $1;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|