mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-27 19:17:47 +01:00
test: add GetRedisURL to tests redis pkg and fix hardcoded redis url (#17581)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
7bbefca8c2
commit
25a42af277
@ -25,6 +25,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/controller/artifact"
|
||||
"github.com/goharbor/harbor/src/controller/project"
|
||||
"github.com/goharbor/harbor/src/jobservice/job"
|
||||
"github.com/goharbor/harbor/src/jobservice/tests"
|
||||
pkgart "github.com/goharbor/harbor/src/pkg/artifact"
|
||||
"github.com/goharbor/harbor/src/pkg/artifactrash/model"
|
||||
pkg_blob "github.com/goharbor/harbor/src/pkg/blob/models"
|
||||
@ -276,9 +277,8 @@ func (suite *gcTestSuite) TestRun() {
|
||||
}
|
||||
params := map[string]interface{}{
|
||||
"delete_untagged": false,
|
||||
// ToDo add a redis testing pkg, we do have a 'localhost' redis server in UT
|
||||
"redis_url_reg": "redis://localhost:6379",
|
||||
"time_window": 1,
|
||||
"redis_url_reg": tests.GetRedisURL(),
|
||||
"time_window": 1,
|
||||
}
|
||||
|
||||
suite.Nil(gc.Run(ctx, params))
|
||||
|
@ -27,20 +27,22 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
poolMaxIdle = 6
|
||||
PoolMaxActive = 6
|
||||
dialConnectionTimeout = 30 * time.Second
|
||||
healthCheckPeriod = time.Minute
|
||||
dialReadTimeout = healthCheckPeriod + 10*time.Second
|
||||
dialWriteTimeout = 10 * time.Second
|
||||
testingRedisHost = "REDIS_HOST"
|
||||
testingRedisHostEnv = "REDIS_HOST"
|
||||
testingRedisPort = 6379
|
||||
testingNamespace = "testing_job_service_v2"
|
||||
)
|
||||
|
||||
// GiveMeRedisPool ...
|
||||
func GiveMeRedisPool() *redis.Pool {
|
||||
redisHost := getRedisHost()
|
||||
pool, _ := redislib.GetRedisPool("test", fmt.Sprintf("redis://%s:%d", redisHost, 6379), &redislib.PoolParam{
|
||||
PoolMaxIdle: 6,
|
||||
PoolMaxActive: 6,
|
||||
pool, _ := redislib.GetRedisPool("test", GetRedisURL(), &redislib.PoolParam{
|
||||
PoolMaxIdle: poolMaxIdle,
|
||||
PoolMaxActive: PoolMaxActive,
|
||||
DialConnectionTimeout: dialConnectionTimeout,
|
||||
DialReadTimeout: dialReadTimeout,
|
||||
DialWriteTimeout: dialWriteTimeout,
|
||||
@ -53,6 +55,16 @@ func GiveMeTestNamespace() string {
|
||||
return testingNamespace
|
||||
}
|
||||
|
||||
// GetRedisURL ...
|
||||
func GetRedisURL() string {
|
||||
redisHost := os.Getenv(testingRedisHostEnv)
|
||||
if redisHost == "" {
|
||||
redisHost = "127.0.0.1" // for local test
|
||||
}
|
||||
|
||||
return fmt.Sprintf("redis://%s:%d", redisHost, testingRedisPort)
|
||||
}
|
||||
|
||||
// Clear ...
|
||||
func Clear(key string, conn redis.Conn) error {
|
||||
if conn != nil {
|
||||
@ -82,12 +94,3 @@ func ClearAll(namespace string, conn redis.Conn) error {
|
||||
|
||||
return conn.Flush()
|
||||
}
|
||||
|
||||
func getRedisHost() string {
|
||||
redisHost := os.Getenv(testingRedisHost)
|
||||
if redisHost == "" {
|
||||
redisHost = "127.0.0.1" // for local test
|
||||
}
|
||||
|
||||
return redisHost
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user