From 73d6f2201c1c302856c201cccf696c2e915076cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A5=9A=E5=B2=B3?= Date: Wed, 26 Oct 2022 20:05:21 +0800 Subject: [PATCH] more error info for apiservice and add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 楚岳 change the mock addon version Signed-off-by: 楚岳 --- .../testdata/not-match-addon/metadata.yaml | 19 +++++++++++++++ pkg/apiserver/domain/service/addon.go | 4 +++- test/e2e-apiserver-test/addon_test.go | 24 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 e2e/addon/mock/testdata/not-match-addon/metadata.yaml diff --git a/e2e/addon/mock/testdata/not-match-addon/metadata.yaml b/e2e/addon/mock/testdata/not-match-addon/metadata.yaml new file mode 100644 index 000000000..e382c0949 --- /dev/null +++ b/e2e/addon/mock/testdata/not-match-addon/metadata.yaml @@ -0,0 +1,19 @@ +name: not-match-addon +version: 1.0.0 +description: Extended workload to do continuous and progressive delivery +icon: https://raw.githubusercontent.com/fluxcd/flux/master/docs/_files/weave-flux.png +url: https://fluxcd.io + +tags: + - mock +dependencies: [] +#- name: addon_name + +# set invisible means this won't be list and will be enabled when depended on +# for example, terraform-alibaba depends on terraform which is invisible, +# when terraform-alibaba is enabled, terraform will be enabled automatically +# default: false +invisible: false + +system: + kubernetes: "<=v1.3.0" \ No newline at end of file diff --git a/pkg/apiserver/domain/service/addon.go b/pkg/apiserver/domain/service/addon.go index 01fa89c5e..e0cf4c9fb 100644 --- a/pkg/apiserver/domain/service/addon.go +++ b/pkg/apiserver/domain/service/addon.go @@ -419,7 +419,9 @@ func (u *addonServiceImpl) EnableAddon(ctx context.Context, name string, args ap // wrap this error with special bcode if errors.As(err, &pkgaddon.VersionUnMatchError{}) { - return bcode.ErrAddonSystemVersionMismatch + berr := bcode.ErrAddonSystemVersionMismatch + berr.Message = err.Error() + return berr } // except `addon not found`, other errors should return directly return err diff --git a/test/e2e-apiserver-test/addon_test.go b/test/e2e-apiserver-test/addon_test.go index 48c9707c7..fc8dc4fd9 100644 --- a/test/e2e-apiserver-test/addon_test.go +++ b/test/e2e-apiserver-test/addon_test.go @@ -17,7 +17,10 @@ limitations under the License. package e2e_apiserver_test import ( + "encoding/json" "fmt" + "io/ioutil" + "strings" "time" . "github.com/onsi/ginkgo" @@ -188,5 +191,26 @@ var _ = Describe("Test addon rest api", func() { Expect(decodeResponseBody(res, &addonStatus)).Should(Succeed()) Expect(addonStatus.Name).Should(BeEquivalentTo("mock-addon")) }) + + It("enable addon with not match system version requirement", func() { + req := apisv1.EnableAddonRequest{ + Args: map[string]interface{}{ + "testkey": "testvalue", + }, + } + res := post("/addons/not-match-addon/enable", req) + defer res.Body.Close() + type errResp struct { + BusinessCode int `json:"BusinessCode"` + Message string `json:"Message"` + } + var errResponse errResp + body, err := ioutil.ReadAll(res.Body) + Expect(err).Should(BeNil()) + err = json.Unmarshal(body, &errResponse) + Expect(err).Should(BeNil()) + Expect(errResponse.BusinessCode).Should(BeEquivalentTo(50018)) + Expect(strings.Contains(errResponse.Message, "fail to install")) + }) }) })