122 lines
4.3 KiB
Go
Executable File
122 lines
4.3 KiB
Go
Executable File
package main
|
||
|
||
import (
|
||
"testing"
|
||
image2 "wdd.io/agent-common/image"
|
||
"wdd.io/agent-common/utils"
|
||
)
|
||
|
||
/* 拉取
|
||
*/
|
||
|
||
func TestFetchDependencyRepos_Middle(t *testing.T) {
|
||
|
||
errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList := C_DownloadCompressUploadDependency(true, true, false, false)
|
||
|
||
utils.BeautifulPrintListWithTitle(errorPullImageList, "errorPullImageList")
|
||
utils.BeautifulPrintListWithTitle(errorGzipImageList, "errorGzipImageList")
|
||
utils.BeautifulPrintListWithTitle(realCmiiImageName, "realCmiiImageName")
|
||
utils.BeautifulPrintListWithTitle(allGzipFileNameList, "allGzipFileNameList")
|
||
|
||
}
|
||
|
||
func TestFetchDependencyRepos_RKE(t *testing.T) {
|
||
|
||
errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList := C_DownloadCompressUploadDependency(true, true, false, true)
|
||
|
||
utils.BeautifulPrintListWithTitle(errorPullImageList, "errorPullImageList")
|
||
utils.BeautifulPrintListWithTitle(errorGzipImageList, "errorGzipImageList")
|
||
utils.BeautifulPrintListWithTitle(realCmiiImageName, "realCmiiImageName")
|
||
utils.BeautifulPrintListWithTitle(allGzipFileNameList, "allGzipFileNameList")
|
||
|
||
}
|
||
|
||
func TestLoadSplitGzipImageToTargetHarbor(t *testing.T) {
|
||
errorLoadImageNameList, errorPushImageNameList := LoadSplitCmiiGzipImageToTargetHarbor("xmyd", DirectPushDeployHarborHost)
|
||
|
||
utils.BeautifulPrintListWithTitle(errorLoadImageNameList, "errorLoadImageNameList")
|
||
utils.BeautifulPrintListWithTitle(errorPushImageNameList, "errorPushImageNameList")
|
||
}
|
||
|
||
func TestLoadSplitDepGzipImageToTargetHarbor(t *testing.T) {
|
||
errorLoadImageNameList, errorPushImageNameList := LoadSplitDepGzipImageToTargetHarbor(DirectPushDeployHarborHost)
|
||
|
||
utils.BeautifulPrintListWithTitle(errorLoadImageNameList, "errorLoadImageNameList")
|
||
utils.BeautifulPrintListWithTitle(errorPushImageNameList, "errorPushImageNameList")
|
||
}
|
||
|
||
func TestPullFromEntityAndSyncConditionally(t *testing.T) {
|
||
// 创建一个模拟的sync对象,用于测试函数的行为。这里需要根据你的实际需求来设置mock数据和预期结果。
|
||
sync := ImageSyncEntity{
|
||
CmiiNameTagList: []string{
|
||
//"cmii-uav-mqtthandler:5.4.0-bjdyt-052102",
|
||
},
|
||
FullNameImageList: nil,
|
||
ProjectVersion: "",
|
||
ProjectName: "cqsh",
|
||
DirectHarborHost: "chongqingcis-9b4a3da9.ecis.chongqing-1.cmecloud.cn",
|
||
ShouldDownloadImage: true,
|
||
ShouldCompressImageToGzip: false,
|
||
ShouldUploadToDemoMinio: false,
|
||
ShouldDirectPushToHarbor: true,
|
||
}
|
||
|
||
// 调用函数并获取结果。这里需要根据你的实际需求来验证返回的结果是否符合预期。
|
||
result := sync.PullFromEntityAndSyncConditionally()
|
||
|
||
utils.BeautifulPrint(result)
|
||
|
||
// 添加断言以检查函数的输出,例如:
|
||
if len(result.ErrorPullImageList) != 0 {
|
||
t.Errorf("Expected no error pulling images, got %v", result.ErrorPullImageList)
|
||
}
|
||
// ...其他验证逻辑...
|
||
}
|
||
|
||
func TestDownloadLoadTagUpload(t *testing.T) {
|
||
|
||
localGzipFileList := []string{
|
||
"/root/octopus_image/middle",
|
||
"/root/octopus_image/rke",
|
||
"/root/octopus_image/xjyd",
|
||
}
|
||
|
||
for _, s := range localGzipFileList {
|
||
log.InfoF("start to sync => %s", s)
|
||
|
||
targetImageFullNameList := A_DownloadLoadTagUpload(false, "", "", s, "172.28.0.251:8033")
|
||
|
||
utils.BeautifulPrintListWithTitle(targetImageFullNameList, "targetImageFullNameList")
|
||
|
||
}
|
||
|
||
}
|
||
|
||
func TestConcatAndUniformCmiiImage(t *testing.T) {
|
||
// 创建一个模拟的fullImageList和cmiiImageList,用于测试函数的行为。这里需要根据你的实际需求来设置mock数据和预期结果。
|
||
fullImageList := []string{"image3", "image4"}
|
||
cmiiImageList := []string{"image1", "image2"}
|
||
|
||
// 调用函数并获取结果。这里需要根据你的实际需求来验证返回的结果是否符合预期。
|
||
result := concatAndUniformCmiiImage(fullImageList, cmiiImageList)
|
||
|
||
// 添加断言以检查函数的输出,例如:
|
||
expectedResult := []string{"image3", "image4", image2.CmiiHarborPrefix + "image1", image2.CmiiHarborPrefix + "image2"}
|
||
if len(result) != len(expectedResult) {
|
||
t.Errorf("Expected %v, got %v", expectedResult, result)
|
||
}
|
||
// ...其他验证逻辑...
|
||
}
|
||
|
||
func TestImageSyncEntity_PullFromEntityAndSyncConditionally(t *testing.T) {
|
||
imageSyncEntity := ImageSyncEntity{
|
||
ProjectVersion: "5.4.0",
|
||
DirectHarborHost: "36.134.71.138",
|
||
}
|
||
|
||
imageSyncResult := imageSyncEntity.PullFromEntityAndSyncConditionally()
|
||
|
||
utils.BeautifulPrint(imageSyncResult)
|
||
|
||
}
|