mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-13 22:05:21 +01:00
Rename the import path of new package 'label'
Signed-off-by: Steven Zou <szou@vmware.com>
This commit is contained in:
parent
06ce715a6b
commit
e6de7f080d
55
src/chartserver/reverse_proxy_test.go
Normal file
55
src/chartserver/reverse_proxy_test.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package chartserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Test the URL rewrite function
|
||||||
|
func TestURLRewrite(t *testing.T) {
|
||||||
|
req, err := createRequest(http.MethodGet, "/api/chartrepo/health")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rewriteURLPath(req)
|
||||||
|
if req.URL.Path != "/health" {
|
||||||
|
t.Fatalf("Expect url format %s but got %s", "/health", req.URL.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err = createRequest(http.MethodGet, "/api/chartrepo/library/charts")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rewriteURLPath(req)
|
||||||
|
if req.URL.Path != "/api/library/charts" {
|
||||||
|
t.Fatalf("Expect url format %s but got %s", "/api/library/charts", req.URL.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err = createRequest(http.MethodPost, "/api/chartrepo/charts")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rewriteURLPath(req)
|
||||||
|
if req.URL.Path != "/api/library/charts" {
|
||||||
|
t.Fatalf("Expect url format %s but got %s", "/api/library/charts", req.URL.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err = createRequest(http.MethodGet, "/chartrepo/library/index.yaml")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rewriteURLPath(req)
|
||||||
|
if req.URL.Path != "/library/index.yaml" {
|
||||||
|
t.Fatalf("Expect url format %s but got %s", "/library/index.yaml", req.URL.Path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func createRequest(method string, url string) (*http.Request, error) {
|
||||||
|
req, err := http.NewRequest(method, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.RequestURI = url
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package chartserver
|
package chartserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -40,3 +42,61 @@ func TestParseRedisConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetCacheConfig(t *testing.T) {
|
||||||
|
// case 1: no cache set
|
||||||
|
cacheConf, err := getCacheConfig()
|
||||||
|
if err != nil || cacheConf != nil {
|
||||||
|
t.Fatal("expect nil cache config and nil error but got non-nil one when parsing empty cache settings")
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 2: unknown cache type
|
||||||
|
os.Setenv(cacheDriverENVKey, "unknown")
|
||||||
|
_, err = getCacheConfig()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expect non-nil error but got nil one when parsing unknown cache type")
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 3: in memory cache type
|
||||||
|
os.Setenv(cacheDriverENVKey, cacheDriverMem)
|
||||||
|
memCacheConf, err := getCacheConfig()
|
||||||
|
if err != nil || memCacheConf == nil || memCacheConf.DriverType != cacheDriverMem {
|
||||||
|
t.Fatal("expect in memory cache driver but got invalid one")
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 4: wrong redis cache conf
|
||||||
|
os.Setenv(cacheDriverENVKey, cacheDriverRedis)
|
||||||
|
os.Setenv(redisENVKey, "")
|
||||||
|
_, err = getCacheConfig()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expect non-nil error but got nil one when parsing a invalid redis cache conf")
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 5: redis cache conf
|
||||||
|
os.Setenv(redisENVKey, "redis:6379,100,Passw0rd,1")
|
||||||
|
redisConf, err := getCacheConfig()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expect nil error but got non-nil one when parsing valid redis conf")
|
||||||
|
}
|
||||||
|
|
||||||
|
if redisConf == nil || redisConf.DriverType != cacheDriverRedis {
|
||||||
|
t.Fatal("expect redis cache driver but got invalid one")
|
||||||
|
}
|
||||||
|
|
||||||
|
conf := make(map[string]string)
|
||||||
|
if err = json.Unmarshal([]byte(redisConf.Config), &conf); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := conf["conn"]; !ok {
|
||||||
|
t.Fatal("expect 'conn' filed in the parsed conf but got nothing")
|
||||||
|
} else {
|
||||||
|
if v != "redis:6379" {
|
||||||
|
t.Fatalf("expect %s but got %s", "redis:6379", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear
|
||||||
|
os.Unsetenv(cacheDriverENVKey)
|
||||||
|
os.Unsetenv(redisENVKey)
|
||||||
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/ui/label"
|
"github.com/goharbor/harbor/src/core/label"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/chartserver"
|
"github.com/goharbor/harbor/src/chartserver"
|
||||||
hlog "github.com/goharbor/harbor/src/common/utils/log"
|
hlog "github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
Loading…
Reference in New Issue
Block a user