模块命名变更
This commit is contained in:
@@ -9,17 +9,17 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
_ "github.com/gitcodestatic/gitcodestatic/docs"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/api"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/cache"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/config"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/stats"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage/sqlite"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/worker"
|
||||
_ "github.com/hanxuanyu/gitcodestatic/docs"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/api"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/cache"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/config"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/stats"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage/sqlite"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/worker"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
||||
module github.com/gitcodestatic/gitcodestatic
|
||||
module github.com/hanxuanyu/gitcodestatic
|
||||
|
||||
go 1.21
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||
)
|
||||
|
||||
// RepoHandler 仓库API处理器
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// StatsHandler 统计API处理器
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// TaskHandler 任务API处理器
|
||||
|
||||
@@ -3,12 +3,12 @@ package api
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
_ "github.com/gitcodestatic/gitcodestatic/docs"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/api/handlers"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
_ "github.com/hanxuanyu/gitcodestatic/docs"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/api/handlers"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
)
|
||||
|
||||
|
||||
12
internal/cache/file_cache.go
vendored
12
internal/cache/file_cache.go
vendored
@@ -8,9 +8,9 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// FileCache 基于文件+DB的缓存实现
|
||||
@@ -66,12 +66,12 @@ func (c *FileCache) Get(ctx context.Context, cacheKey string) (*models.StatsResu
|
||||
}
|
||||
|
||||
// Set 设置缓存
|
||||
func (c *FileCache) Set(ctx context.Context, repoID int64, branch string, constraint *models.StatsConstraint,
|
||||
func (c *FileCache) Set(ctx context.Context, repoID int64, branch string, constraint *models.StatsConstraint,
|
||||
commitHash string, stats *models.Statistics) error {
|
||||
|
||||
|
||||
// 生成缓存键
|
||||
cacheKey := GenerateCacheKey(repoID, branch, constraint, commitHash)
|
||||
|
||||
|
||||
// 保存统计结果到文件
|
||||
resultPath := filepath.Join(c.statsDir, cacheKey+".json.gz")
|
||||
if err := c.saveStatsToFile(stats, resultPath); err != nil {
|
||||
|
||||
4
internal/cache/key.go
vendored
4
internal/cache/key.go
vendored
@@ -5,13 +5,13 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
)
|
||||
|
||||
// GenerateCacheKey 生成缓存键
|
||||
func GenerateCacheKey(repoID int64, branch string, constraint *models.StatsConstraint, commitHash string) string {
|
||||
var constraintStr string
|
||||
|
||||
|
||||
if constraint != nil {
|
||||
if constraint.Type == models.ConstraintTypeDateRange {
|
||||
constraintStr = fmt.Sprintf("dr_%s_%s", constraint.From, constraint.To)
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
)
|
||||
|
||||
// CmdGitManager 基于git命令的实现
|
||||
|
||||
@@ -3,7 +3,7 @@ package git
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
)
|
||||
|
||||
// Manager Git管理器接口
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/worker"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/worker"
|
||||
)
|
||||
|
||||
// RepoService 仓库服务
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/cache"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/worker"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/cache"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/worker"
|
||||
)
|
||||
|
||||
// StatsService 统计服务
|
||||
@@ -34,9 +34,9 @@ func NewStatsService(store storage.Store, queue *worker.Queue, fileCache *cache.
|
||||
|
||||
// CalculateRequest 统计请求
|
||||
type CalculateRequest struct {
|
||||
RepoID int64 `json:"repo_id"`
|
||||
Branch string `json:"branch"`
|
||||
Constraint *models.StatsConstraint `json:"constraint"`
|
||||
RepoID int64 `json:"repo_id"`
|
||||
Branch string `json:"branch"`
|
||||
Constraint *models.StatsConstraint `json:"constraint"`
|
||||
}
|
||||
|
||||
// Calculate 触发统计计算
|
||||
|
||||
@@ -3,8 +3,8 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// TaskService 任务服务
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
)
|
||||
|
||||
// Calculator 统计计算器
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/cache"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/stats"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/cache"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/stats"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// CloneHandler 克隆任务处理器
|
||||
@@ -301,7 +301,7 @@ func (h *StatsHandler) Handle(ctx context.Context, task *models.Task) error {
|
||||
if cached != nil {
|
||||
// 缓存命中,直接返回
|
||||
logger.Logger.Info().Str("cache_key", cacheKey).Msg("cache hit during stats calculation")
|
||||
|
||||
|
||||
result := models.TaskResult{
|
||||
CacheKey: cacheKey,
|
||||
Message: "cache hit",
|
||||
@@ -310,7 +310,7 @@ func (h *StatsHandler) Handle(ctx context.Context, task *models.Task) error {
|
||||
resultStr := string(resultJSON)
|
||||
task.Result = &resultStr
|
||||
h.store.Tasks().Update(ctx, task)
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// Pool Worker池
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// Queue 任务队列
|
||||
@@ -40,7 +40,7 @@ func (q *Queue) Enqueue(ctx context.Context, task *models.Task) error {
|
||||
Int64("repo_id", task.RepoID).
|
||||
Str("task_type", task.TaskType).
|
||||
Msg("task already exists, returning existing task")
|
||||
|
||||
|
||||
task.ID = existing.ID
|
||||
task.Status = existing.Status
|
||||
task.CreatedAt = existing.CreatedAt
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||
)
|
||||
|
||||
// TaskHandler 任务处理器接口
|
||||
@@ -121,7 +121,7 @@ func (w *Worker) handleTask(ctx context.Context, task *models.Task) {
|
||||
|
||||
// 执行任务
|
||||
err := handler.Handle(taskCtx, task)
|
||||
|
||||
|
||||
duration := time.Since(startTime)
|
||||
|
||||
if err != nil {
|
||||
@@ -133,7 +133,7 @@ func (w *Worker) handleTask(ctx context.Context, task *models.Task) {
|
||||
Str("task_type", task.TaskType).
|
||||
Int64("duration_ms", duration.Milliseconds()).
|
||||
Msg("task failed")
|
||||
|
||||
|
||||
w.store.Tasks().UpdateStatus(ctx, task.ID, models.TaskStatusFailed, &errMsg)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TestGenerateCacheKey 测试缓存键生成
|
||||
func TestGenerateCacheKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repoID int64
|
||||
branch string
|
||||
constraint *models.StatsConstraint
|
||||
commitHash string
|
||||
}{
|
||||
{
|
||||
name: "date_range constraint",
|
||||
repoID: 1,
|
||||
branch: "main",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeDateRange,
|
||||
From: "2024-01-01",
|
||||
To: "2024-12-31",
|
||||
},
|
||||
commitHash: "abc123",
|
||||
},
|
||||
{
|
||||
name: "commit_limit constraint",
|
||||
repoID: 1,
|
||||
branch: "main",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeCommitLimit,
|
||||
Limit: 100,
|
||||
},
|
||||
commitHash: "abc123",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
key1 := GenerateCacheKey(tt.repoID, tt.branch, tt.constraint, tt.commitHash)
|
||||
key2 := GenerateCacheKey(tt.repoID, tt.branch, tt.constraint, tt.commitHash)
|
||||
|
||||
// 相同参数应该生成相同的key
|
||||
assert.Equal(t, key1, key2)
|
||||
assert.NotEmpty(t, key1)
|
||||
assert.Len(t, key1, 64) // SHA256 hex = 64 chars
|
||||
})
|
||||
}
|
||||
|
||||
// 测试不同参数生成不同的key
|
||||
t.Run("different parameters generate different keys", func(t *testing.T) {
|
||||
constraint := &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeCommitLimit,
|
||||
Limit: 100,
|
||||
}
|
||||
|
||||
key1 := GenerateCacheKey(1, "main", constraint, "abc123")
|
||||
key2 := GenerateCacheKey(1, "main", constraint, "def456") // 不同的commit hash
|
||||
key3 := GenerateCacheKey(1, "develop", constraint, "abc123") // 不同的分支
|
||||
|
||||
assert.NotEqual(t, key1, key2)
|
||||
assert.NotEqual(t, key1, key3)
|
||||
assert.NotEqual(t, key2, key3)
|
||||
})
|
||||
}
|
||||
|
||||
// TestSerializeConstraint 测试约束序列化
|
||||
func TestSerializeConstraint(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
constraint *models.StatsConstraint
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "nil constraint",
|
||||
constraint: nil,
|
||||
expected: "{}",
|
||||
},
|
||||
{
|
||||
name: "date_range constraint",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeDateRange,
|
||||
From: "2024-01-01",
|
||||
To: "2024-12-31",
|
||||
},
|
||||
expected: `{"type":"date_range","from":"2024-01-01","to":"2024-12-31"}`,
|
||||
},
|
||||
{
|
||||
name: "commit_limit constraint",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeCommitLimit,
|
||||
Limit: 100,
|
||||
},
|
||||
expected: `{"type":"commit_limit","limit":100}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := SerializeConstraint(tt.constraint)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TestValidateStatsConstraint 测试统计约束校验
|
||||
func TestValidateStatsConstraint(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
constraint *models.StatsConstraint
|
||||
expectError bool
|
||||
errorMsg string
|
||||
}{
|
||||
{
|
||||
name: "nil constraint",
|
||||
constraint: nil,
|
||||
expectError: true,
|
||||
errorMsg: "constraint is required",
|
||||
},
|
||||
{
|
||||
name: "valid date_range constraint",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeDateRange,
|
||||
From: "2024-01-01",
|
||||
To: "2024-12-31",
|
||||
},
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "date_range missing from",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeDateRange,
|
||||
To: "2024-12-31",
|
||||
},
|
||||
expectError: true,
|
||||
errorMsg: "date_range requires both from and to",
|
||||
},
|
||||
{
|
||||
name: "date_range with limit (invalid)",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeDateRange,
|
||||
From: "2024-01-01",
|
||||
To: "2024-12-31",
|
||||
Limit: 100,
|
||||
},
|
||||
expectError: true,
|
||||
errorMsg: "date_range cannot be used with limit",
|
||||
},
|
||||
{
|
||||
name: "valid commit_limit constraint",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeCommitLimit,
|
||||
Limit: 100,
|
||||
},
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "commit_limit with zero limit",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeCommitLimit,
|
||||
Limit: 0,
|
||||
},
|
||||
expectError: true,
|
||||
errorMsg: "commit_limit requires positive limit value",
|
||||
},
|
||||
{
|
||||
name: "commit_limit with date range (invalid)",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: models.ConstraintTypeCommitLimit,
|
||||
Limit: 100,
|
||||
From: "2024-01-01",
|
||||
},
|
||||
expectError: true,
|
||||
errorMsg: "commit_limit cannot be used with date range",
|
||||
},
|
||||
{
|
||||
name: "invalid constraint type",
|
||||
constraint: &models.StatsConstraint{
|
||||
Type: "invalid_type",
|
||||
},
|
||||
expectError: true,
|
||||
errorMsg: "constraint type must be",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := ValidateStatsConstraint(tt.constraint)
|
||||
|
||||
if tt.expectError {
|
||||
assert.Error(t, err)
|
||||
if tt.errorMsg != "" {
|
||||
assert.Contains(t, err.Error(), tt.errorMsg)
|
||||
}
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestExtractRepoName 测试仓库名称提取
|
||||
func TestExtractRepoName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
url string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "https url with .git",
|
||||
url: "https://github.com/user/repo.git",
|
||||
expected: "repo",
|
||||
},
|
||||
{
|
||||
name: "https url without .git",
|
||||
url: "https://github.com/user/repo",
|
||||
expected: "repo",
|
||||
},
|
||||
{
|
||||
name: "ssh url",
|
||||
url: "git@github.com:user/repo.git",
|
||||
expected: "repo_git",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := extractRepoName(tt.url)
|
||||
assert.NotEmpty(t, result)
|
||||
// 注意:实际实现可能会有差异,这里主要测试不会panic
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user