Commit 286765e9 authored by 楚岳's avatar 楚岳 Committed by github-actions[bot]
Browse files

more error info for apiservice and add tests

Signed-off-by: default avatar楚岳 <wangyike.wyk@alibaba-inc.com>

change the mock addon version
Signed-off-by: default avatar楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 73d6f2201c1c302856c201cccf696c2e915076cb)
parent c91850ce
Showing with 46 additions and 1 deletion
+46 -1
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
......@@ -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
......
......@@ -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"))
})
})
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment