* [misc] Enhance unit tests for repoModel::createGitlabRepo() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,28 +1,36 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel::createGitlabRepo();
|
||||
timeout=0
|
||||
cid=1
|
||||
cid=0
|
||||
|
||||
- 创建gitlab远程版本库 @1
|
||||
- namesapce为空时第namespace条的0属性 @不能为空字符
|
||||
- 执行$result @1
|
||||
- 执行$result->message第namespace条的0属性 @不能为空字符
|
||||
- 执行$result @false
|
||||
- 执行$result @false
|
||||
- 执行$result @negative_namespace_error
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
|
||||
|
||||
zenData('pipeline')->gen(5);
|
||||
|
||||
su('admin');
|
||||
|
||||
$repoTest = new repoTest();
|
||||
|
||||
$_SERVER['REQUEST_URI'] = 'http://unittest/';
|
||||
|
||||
// 测试步骤1:正常输入情况,创建有效的GitLab项目
|
||||
$repo = new stdclass();
|
||||
$repo->product = '1,2';
|
||||
$repo->projects = '3,4';
|
||||
$repo->name = 'abc&&';
|
||||
$repo->name = 'unitTestProject17';
|
||||
$repo->serviceHost = 1;
|
||||
$repo->path = 'unit_test_project17';
|
||||
$repo->desc = 'unit_test_project desc';
|
||||
@@ -30,13 +38,37 @@ $repo->namespace = 1;
|
||||
$repo->SCM = 'Gitlab';
|
||||
$repo->acl = '{"acl":"open","groups":[""],"users":[""]}';
|
||||
|
||||
$_SERVER['REQUEST_URI'] = 'http://unittest/';
|
||||
|
||||
$repo->name = 'unitTestProject17';
|
||||
$result = $repoTest->createGitlabRepoTest($repo, $repo->namespace);
|
||||
if(isset($result->id)) $result = true;
|
||||
if(!empty($result->message->name[0]) and $result->message->name[0] == '已经被使用') $result = true;
|
||||
r($result) && p() && e('1'); //创建gitlab远程版本库
|
||||
r($result) && p() && e('1');
|
||||
|
||||
// 测试步骤2:边界值测试,命名空间为0的情况
|
||||
$result = $repoTest->createGitlabRepoTest($repo, 0);
|
||||
r($result->message) && p('namespace:0') && e('不能为空字符'); //namesapce为空时
|
||||
r($result->message) && p('namespace:0') && e('不能为空字符');
|
||||
|
||||
// 测试步骤3:无效输入测试,repo对象缺少name属性的情况
|
||||
$emptyRepo = new stdclass();
|
||||
$emptyRepo->name = '';
|
||||
$emptyRepo->serviceHost = 1;
|
||||
$emptyRepo->desc = '';
|
||||
$result = $repoTest->createGitlabRepoTest($emptyRepo, 1);
|
||||
if($result === false) $result = 'false';
|
||||
r($result) && p() && e('false');
|
||||
|
||||
// 测试步骤4:项目名称为空字符串测试
|
||||
$emptyNameRepo = clone $repo;
|
||||
$emptyNameRepo->name = '';
|
||||
$emptyNameRepo->path = '';
|
||||
$result = $repoTest->createGitlabRepoTest($emptyNameRepo, 1);
|
||||
if($result === false) $result = 'false';
|
||||
r($result) && p() && e('false');
|
||||
|
||||
// 测试步骤5:命名空间为负数测试,使用负数的命名空间ID
|
||||
$negativeNamespaceRepo = clone $repo;
|
||||
$negativeNamespaceRepo->name = 'testNegativeNamespace';
|
||||
$negativeNamespaceRepo->path = 'test-negative-namespace';
|
||||
$result = $repoTest->createGitlabRepoTest($negativeNamespaceRepo, -1);
|
||||
if(!empty($result->message)) $result = 'negative_namespace_error';
|
||||
if($result === false) $result = 'false';
|
||||
r($result) && p() && e('negative_namespace_error');
|
||||
Reference in New Issue
Block a user