-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'github-bk-bcs/master'
* github-bk-bcs/master: feat: vault mysql storage add etcd ha backend (#2917) refactor: 增加中英文icon (#2919) fix: 切换服务后版本对比下拉列表没有刷新--bug=119754095 (#2918) fix(bk-bscp): access blueking notification center (#2916) feat(bk-bscp): access blueking notification center (#2915) feat:Helm Release 详情扩展 (#2891) feat:新增模板集相关metrics (#2890) fix: 调整info-box样式问题 (#2914)
- Loading branch information
Showing
38 changed files
with
1,637 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
bcs-services/bcs-bscp/cmd/api-server/service/bknotice_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package service | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"path" | ||
"testing" | ||
"text/template" | ||
|
||
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/cmd/api-server/options" | ||
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/cc" | ||
) | ||
|
||
// SysOpt is the system option | ||
var SysOpt *options.Option | ||
|
||
var configFileTmpl = ` | ||
esb: | ||
appCode: {{ .AppCode }} | ||
appSecret: {{ .AppSecret }} | ||
bkNotice: | ||
enable: true | ||
host: {{ .BKNoticeHost }} | ||
repository: | ||
# storageType: S3 | ||
storageType: BKREPO | ||
bkRepo: | ||
endpoints: | ||
- http://example.bktencent.com | ||
project: bscp | ||
username: example | ||
password: example | ||
s3: | ||
endpoint: "" | ||
accessKeyID: "" | ||
secretAccessKey: "" | ||
useSSL: true | ||
bucketName: bscp-example | ||
` | ||
|
||
type MockHttpClient struct { | ||
DoFunc func(req *http.Request) (*http.Response, error) | ||
} | ||
|
||
func (m *MockHttpClient) Do(req *http.Request) (*http.Response, error) { | ||
return m.DoFunc(req) | ||
} | ||
|
||
func TestGetCurrentAnnouncements(t *testing.T) { | ||
|
||
tempDir := os.TempDir() | ||
SysOpt.Sys.ConfigFiles = []string{path.Join(tempDir, "cc.yaml")} | ||
file, err := os.OpenFile(path.Join(tempDir, "cc.yaml"), os.O_RDWR|os.O_CREATE, 0755) | ||
if err != nil { | ||
t.Errorf("open file failed, err: %s", err.Error()) | ||
} | ||
defer file.Close() | ||
tpl, err := template.New("cc.yaml").Parse(configFileTmpl) | ||
if err != nil { | ||
t.Errorf("parse template failed, err: %s", err.Error()) | ||
} | ||
if e := tpl.Execute(file, map[string]string{ | ||
"AppCode": os.Getenv("APP_CODE"), | ||
"AppSecret": os.Getenv("APP_SECRET"), | ||
"BKNoticeHost": os.Getenv("BK_NOTICE_HOST"), | ||
}); e != nil { | ||
t.Errorf("execute template failed, err: %s", e.Error()) | ||
} | ||
|
||
if e := cc.LoadSettings(SysOpt.Sys); e != nil { | ||
t.Errorf("load settings from config files failed, err: %s", e.Error()) | ||
} | ||
|
||
service, err := newBKNoticeService() | ||
if err != nil { | ||
t.Errorf("newBKNoticeService failed: %v", err) | ||
} | ||
|
||
recorder := httptest.NewRecorder() | ||
// Mock 一个http请求 | ||
request, _ := http.NewRequest("GET", "/", nil) | ||
|
||
// 调用API | ||
service.GetCurrentAnnouncements(recorder, request) | ||
|
||
// 检查状态码 | ||
if status := recorder.Code; status != http.StatusOK { | ||
t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK) | ||
} | ||
|
||
// 检查响应体 | ||
type expectedResp struct { | ||
Result bool `json:"result"` | ||
Code int `json:"code"` | ||
Data interface{} `json:"data"` | ||
} | ||
expected := &expectedResp{} | ||
if err := json.Unmarshal(recorder.Body.Bytes(), expected); err != nil { | ||
t.Errorf("handler returned response failed: %v", err) | ||
} | ||
|
||
if expected.Code != 0 { | ||
t.Errorf("handler returned response failed, code: %v", expected.Code) | ||
} | ||
|
||
if !expected.Result { | ||
t.Errorf("handler returned response failed, result: %v", expected.Result) | ||
} | ||
} | ||
|
||
func init() { | ||
|
||
SysOpt = options.InitOptions() | ||
|
||
cc.InitService(cc.APIServerName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package vault | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/cc" | ||
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/kit" | ||
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/types" | ||
) | ||
|
||
func initClient(t testing.TB) Set { | ||
vaultToken := os.Getenv("VAULT_TOKEN") | ||
vaultAddr := os.Getenv("VAULT_ADDR") | ||
if vaultAddr == "" || vaultToken == "" { | ||
t.Skipf("VAULT_ADDR or VAULT_TOKEN env is missing") | ||
} | ||
|
||
s, err := NewSet(cc.Vault{ | ||
Address: vaultAddr, | ||
Token: vaultToken, | ||
}) | ||
if err != nil { | ||
t.Fatalf("new set err: %s", err) | ||
} | ||
|
||
return s | ||
} | ||
|
||
func TestGetKv(t *testing.T) { | ||
s := initClient(t) | ||
kt := kit.New() | ||
|
||
opt := &types.GetLastKvOpt{ | ||
BizID: 2, | ||
AppID: 1, | ||
Key: "conf", | ||
} | ||
|
||
_, _, err := s.GetLastKv(kt, opt) | ||
if err != nil { | ||
t.Fatalf("GetLastKv err: %s", err) | ||
} | ||
} | ||
|
||
func BenchmarkGetKv(b *testing.B) { | ||
s := initClient(b) | ||
kt := kit.New() | ||
|
||
opt := &types.GetLastKvOpt{ | ||
BizID: 2, | ||
AppID: 1, | ||
Key: "conf", | ||
} | ||
|
||
for i := 0; i < b.N; i++ { | ||
_, _, err := s.GetLastKv(kt, opt) | ||
if err != nil { | ||
b.Fatalf("GetLastKv err: %s", err) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkParallelGetKv(b *testing.B) { | ||
s := initClient(b) | ||
kt := kit.New() | ||
|
||
opt := &types.GetLastKvOpt{ | ||
BizID: 2, | ||
AppID: 1, | ||
Key: "conf", | ||
} | ||
|
||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
_, _, err := s.GetLastKv(kt, opt) | ||
if err != nil { | ||
b.Fatalf("GetLastKv err: %s", err) | ||
} | ||
} | ||
}) | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.