Skip to content

Commit

Permalink
feat: create addon test
Browse files Browse the repository at this point in the history
Signed-off-by: CeerDecy <[email protected]>
  • Loading branch information
CeerDecy committed Sep 29, 2024
1 parent d7b6a49 commit 8b674b6
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions internal/tools/orchestrator/endpoints/addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
package endpoints

import (
"context"
"math/rand"
"net/http"
"reflect"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -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)
}

}

0 comments on commit 8b674b6

Please sign in to comment.