* Add repo unit test.
This commit is contained in:
@@ -2516,9 +2516,9 @@ class repoModel extends model
|
||||
* @param bool $withCommit
|
||||
* @param string $condition
|
||||
* @access public
|
||||
* @return string|false
|
||||
* @return string|object|false
|
||||
*/
|
||||
public function getHistoryRevision(int $repoID, string $revision, bool $withCommit = false, string $condition = 'eq'): string|false
|
||||
public function getHistoryRevision(int $repoID, string $revision, bool $withCommit = false, string $condition = 'eq'): string|object|false
|
||||
{
|
||||
$field = $withCommit ? 'revision, commit' : 'revision';
|
||||
return $this->dao->select($field)->from(TABLE_REPOHISTORY)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->getGitlabFilesByPath();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab类型版本库1的master分支文件列表
|
||||
- 第0条的name属性 @public
|
||||
- 第0条的kind属性 @dir
|
||||
- 获取gitlab类型版本库1的master分支文件列表数量 @1
|
||||
- 获取gitlab类型版本库1的master分支public路径下文件列表
|
||||
- 第0条的name属性 @index.html
|
||||
- 第0条的kind属性 @file
|
||||
- 获取gitlab类型版本库1的master分支public路径下文件列表数量 @1
|
||||
- 获取gitlab类型版本库1的branch1分支文件列表
|
||||
- 第2条的name属性 @README.md
|
||||
- 第2条的kind属性 @file
|
||||
- 获取gitlab类型版本库1的brnach1分支文件列表数量 @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
zdTable('repo')->config('repo')->gen(5);
|
||||
|
||||
$repoIds = array(1);
|
||||
$paths = array('', 'public');
|
||||
$branches = array('master', 'branch1');
|
||||
|
||||
$repo = new repoTest();
|
||||
|
||||
$result = $repo->getGitlabFilesByPathTest($repoIds[0], $paths[0], $branches[0]);
|
||||
r($result) && p('0:name,kind') && e('public,dir'); // 获取gitlab类型版本库1的master分支文件列表
|
||||
r(count($result) > 3) && p() && e('1'); // 获取gitlab类型版本库1的master分支文件列表数量
|
||||
|
||||
$result = $repo->getGitlabFilesByPathTest($repoIds[0], $paths[1], $branches[0]);
|
||||
r($result) && p('0:name,kind') && e('index.html,file'); // 获取gitlab类型版本库1的master分支public路径下文件列表
|
||||
r(count($result) > 1) && p() && e('1'); // 获取gitlab类型版本库1的master分支public路径下文件列表数量
|
||||
|
||||
$result = $repo->getGitlabFilesByPathTest($repoIds[0], $paths[0], $branches[1]);
|
||||
r($result) && p('2:name,kind') && e('README.md,file'); // 获取gitlab类型版本库1的branch1分支文件列表
|
||||
r(count($result) > 2) && p() && e('1'); // 获取gitlab类型版本库1的brnach1分支文件列表数量
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel::getHistoryRevision();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 查询提交记录版本号 @d30919bdb9b4cf8e2698f4a6a30e41910427c01c
|
||||
- 查询提交记录版本号withCommmit参数为true
|
||||
- 属性revision @d30919bdb9b4cf8e2698f4a6a30e41910427c01c
|
||||
- 属性commit @2
|
||||
- 查询提交记录版本号withCommmit参数为true
|
||||
- 属性revision @0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb
|
||||
- 属性commit @1
|
||||
|
||||
*/
|
||||
|
||||
zdTable('repo')->config('repo')->gen(4);
|
||||
zdTable('repohistory')->config('repohistory')->gen(3);
|
||||
|
||||
$repoModel = $tester->loadModel('repo');
|
||||
|
||||
$repoID = 3;
|
||||
$revision = 'd30919bdb9b4cf8e2698f4a6a30e41910427c01c';
|
||||
$withCommit = true;
|
||||
$condition = 'lt';
|
||||
|
||||
r($repoModel->getHistoryRevision($repoID, $revision)) && p() && e('d30919bdb9b4cf8e2698f4a6a30e41910427c01c'); //查询提交记录版本号
|
||||
r($repoModel->getHistoryRevision($repoID, $revision, $withCommit)) && p('revision,commit') && e('d30919bdb9b4cf8e2698f4a6a30e41910427c01c,2'); //查询提交记录版本号withCommmit参数为true
|
||||
r($repoModel->getHistoryRevision($repoID, $revision, $withCommit, $condition)) && p('revision,commit') && e('0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb,1'); //查询提交记录版本号withCommmit参数为true
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/repo.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 repoModel->getTreeByGraphql();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取gitlab类型版本库1的master分支文件夹列表第0条的name属性 @public
|
||||
- 获取gitlab类型版本库1的master分支文件列表第2条的name属性 @sonar-project.properties
|
||||
- 获取gitlab类型版本库1的master分支public路径下文件夹列表数量 @0
|
||||
- 获取gitlab类型版本库1的master分支public路径下文件列表第0条的name属性 @index.html
|
||||
- 获取gitlab类型版本库1的branch1分支文件夹列表第0条的name属性 @public
|
||||
- 获取gitlab类型版本库1的branch1分支文件列表第1条的name属性 @README.md
|
||||
|
||||
*/
|
||||
|
||||
zdTable('pipeline')->gen(5);
|
||||
zdTable('repo')->config('repo')->gen(5);
|
||||
|
||||
$repoIds = array(1);
|
||||
$paths = array('', 'public');
|
||||
$branches = array('master', 'branch1');
|
||||
$types = array('trees', 'blobs');
|
||||
|
||||
$repo = new repoTest();
|
||||
|
||||
r($repo->getTreeByGraphqlTest($repoIds[0], $paths[0], $branches[0], $types[0])) && p('0:name') && e('public'); // 获取gitlab类型版本库1的master分支文件夹列表
|
||||
r($repo->getTreeByGraphqlTest($repoIds[0], $paths[0], $branches[0], $types[1])) && p('2:name') && e('sonar-project.properties'); // 获取gitlab类型版本库1的master分支文件列表
|
||||
|
||||
$result = $repo->getTreeByGraphqlTest($repoIds[0], $paths[1], $branches[0], $types[0]);
|
||||
r(count($result)) && p() && e('0'); // 获取gitlab类型版本库1的master分支public路径下文件夹列表数量
|
||||
r($repo->getTreeByGraphqlTest($repoIds[0], $paths[1], $branches[0], $types[1])) && p('0:name') && e('index.html'); // 获取gitlab类型版本库1的master分支public路径下文件列表
|
||||
|
||||
r($repo->getTreeByGraphqlTest($repoIds[0], $paths[0], $branches[1], $types[0])) && p('0:name') && e('public'); // 获取gitlab类型版本库1的branch1分支文件夹列表
|
||||
r($repo->getTreeByGraphqlTest($repoIds[0], $paths[0], $branches[1], $types[1])) && p('1:name') && e('README.md'); // 获取gitlab类型版本库1的branch1分支文件列表
|
||||
@@ -709,4 +709,25 @@ class repoTest
|
||||
$result = $this->objectModel->filterProject($products, $projects);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getGitlabFilesByPathTest(int $repoID, string $path = '', string $branch = '')
|
||||
{
|
||||
$repo = $this->objectModel->getByID($repoID);
|
||||
$result = $this->objectModel->getGitlabFilesByPath($repo, $path, $branch);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getTreeByGraphqlTest(int $repoID, string $path = '', string $branch = '', string $type = 'blobs')
|
||||
{
|
||||
$repo = $this->objectModel->getByID($repoID);
|
||||
$result = $this->objectModel->getTreeByGraphql($repo, $path, $branch, $type);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user