diff --git a/internal/tools/orchestrator/endpoints/addon_test.go b/internal/tools/orchestrator/endpoints/addon_test.go index bd4eaff9122..0f43e6e73aa 100644 --- a/internal/tools/orchestrator/endpoints/addon_test.go +++ b/internal/tools/orchestrator/endpoints/addon_test.go @@ -15,8 +15,11 @@ package endpoints import ( + "context" "math/rand" + "net/http" "reflect" + "strings" "sync" "testing" @@ -212,3 +215,66 @@ func TestConcurrentReadWriteProjectInfos(t *testing.T) { assert.Equal(t, true, ok) } } + +func TestCreateAddonDirectly(t *testing.T) { + e := Endpoints{} + + for _, test := range []struct { + payload string + orgid string + userid string + }{ + { + payload: `{ + "addons": { + "registercenter": { + "plan": "registercenter:basic", + "options": { + "version": "2.0.0" + } + } + }, + "workspace": "TEST", + "shareScope": "PROJECT", + "projectId": 88888, + "clusterName": "test" +}`, + orgid: "666", + userid: "666", + }, + + { + payload: `{ + "addons": { + "config-center": { + "plan": "config-center:basic", + "options": { + "version": "2.0.0" + } + } + }, + "workspace": "TEST", + "shareScope": "PROJECT", + "projectId": 88888, + "clusterName": "test" +}`, + orgid: "666", + userid: "666", + }, + } { + payload := strings.NewReader(test.payload) + req, err := http.NewRequest("", "", payload) + if err != nil { + t.Fatal(err) + } + req.Header.Add("org-id", test.orgid) + req.Header.Add("USER-ID", test.userid) + + monkey.PatchInstanceMethod(reflect.TypeOf(e.addon), "AddonCreate", func(a *addon.Addon, req apistructs.AddonDirectCreateRequest) ([]string, error) { + return []string{"test success!"}, nil + }) + + _, _ = e.CreateAddonDirectly(context.Background(), req, nil) + } + +}