模块命名变更
This commit is contained in:
@@ -9,17 +9,17 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/gitcodestatic/gitcodestatic/docs"
|
_ "github.com/hanxuanyu/gitcodestatic/docs"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/api"
|
"github.com/hanxuanyu/gitcodestatic/internal/api"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/cache"
|
"github.com/hanxuanyu/gitcodestatic/internal/cache"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/config"
|
"github.com/hanxuanyu/gitcodestatic/internal/config"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/stats"
|
"github.com/hanxuanyu/gitcodestatic/internal/stats"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage/sqlite"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage/sqlite"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/worker"
|
"github.com/hanxuanyu/gitcodestatic/internal/worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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
|
go 1.21
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
|
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RepoHandler 仓库API处理器
|
// RepoHandler 仓库API处理器
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/service"
|
"github.com/hanxuanyu/gitcodestatic/internal/service"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatsHandler 统计API处理器
|
// StatsHandler 统计API处理器
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TaskHandler 任务API处理器
|
// TaskHandler 任务API处理器
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package api
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"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"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"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"
|
httpSwagger "github.com/swaggo/http-swagger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
6
internal/cache/file_cache.go
vendored
6
internal/cache/file_cache.go
vendored
@@ -8,9 +8,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileCache 基于文件+DB的缓存实现
|
// FileCache 基于文件+DB的缓存实现
|
||||||
|
|||||||
2
internal/cache/key.go
vendored
2
internal/cache/key.go
vendored
@@ -5,7 +5,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenerateCacheKey 生成缓存键
|
// GenerateCacheKey 生成缓存键
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdGitManager 基于git命令的实现
|
// CmdGitManager 基于git命令的实现
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package git
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Manager Git管理器接口
|
// Manager Git管理器接口
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/worker"
|
"github.com/hanxuanyu/gitcodestatic/internal/worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RepoService 仓库服务
|
// RepoService 仓库服务
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/cache"
|
"github.com/hanxuanyu/gitcodestatic/internal/cache"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/worker"
|
"github.com/hanxuanyu/gitcodestatic/internal/worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatsService 统计服务
|
// StatsService 统计服务
|
||||||
@@ -34,9 +34,9 @@ func NewStatsService(store storage.Store, queue *worker.Queue, fileCache *cache.
|
|||||||
|
|
||||||
// CalculateRequest 统计请求
|
// CalculateRequest 统计请求
|
||||||
type CalculateRequest struct {
|
type CalculateRequest struct {
|
||||||
RepoID int64 `json:"repo_id"`
|
RepoID int64 `json:"repo_id"`
|
||||||
Branch string `json:"branch"`
|
Branch string `json:"branch"`
|
||||||
Constraint *models.StatsConstraint `json:"constraint"`
|
Constraint *models.StatsConstraint `json:"constraint"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate 触发统计计算
|
// Calculate 触发统计计算
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TaskService 任务服务
|
// TaskService 任务服务
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Calculator 统计计算器
|
// Calculator 统计计算器
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/cache"
|
"github.com/hanxuanyu/gitcodestatic/internal/cache"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/git"
|
"github.com/hanxuanyu/gitcodestatic/internal/git"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/stats"
|
"github.com/hanxuanyu/gitcodestatic/internal/stats"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CloneHandler 克隆任务处理器
|
// CloneHandler 克隆任务处理器
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pool Worker池
|
// Pool Worker池
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Queue 任务队列
|
// Queue 任务队列
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/logger"
|
"github.com/hanxuanyu/gitcodestatic/internal/logger"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/models"
|
"github.com/hanxuanyu/gitcodestatic/internal/models"
|
||||||
"github.com/gitcodestatic/gitcodestatic/internal/storage"
|
"github.com/hanxuanyu/gitcodestatic/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TaskHandler 任务处理器接口
|
// TaskHandler 任务处理器接口
|
||||||
|
|||||||
@@ -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