// Package consts ... // // Description : consts ... // // Author : go_developer@163.com<白茶清欢> // // Date : 2025-04-20 14:37 package consts import ( "encoding/json" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestRequestDataLocation_String(t *testing.T) { Convey("request data location字符串值", t, func() { byteData, err := json.Marshal(RequestDataLocationBody) So(err, ShouldBeNil) So(RequestDataLocationBody.String(), ShouldEqual, "BODY") So(string(byteData), ShouldEqual, `"BODY"`) }) Convey("request data location MarshalJSON", t, func() { str, err := RequestDataLocationBody.MarshalJSON() So(err, ShouldBeNil) So(string(str), ShouldEqual, `"BODY"`) dataList := []RequestDataLocation{RequestDataLocationBody} jsonData, err := json.Marshal(dataList) So(err, ShouldBeNil) So(string(jsonData), ShouldEqual, `["BODY"]`) }) } func TestRequestDataLocation_IsValid(t *testing.T) { Convey("request data location 非法验证", t, func() { So(RequestDataLocation("Invalid").IsValid(), ShouldBeFalse) }) Convey("request data location 合法验证", t, func() { So(RequestDataLocation("BODY").IsValid(), ShouldBeTrue) }) } func TestResponseDataLocation_String(t *testing.T) { Convey("response data location字符串值", t, func() { byteData, err := json.Marshal(ResponseDataLocationBody) So(err, ShouldBeNil) So(RequestDataLocationBody.String(), ShouldEqual, "BODY") So(string(byteData), ShouldEqual, `"BODY"`) }) Convey("response data location MarshalJSON", t, func() { str, err := ResponseDataLocationBody.MarshalJSON() So(err, ShouldBeNil) So(string(str), ShouldEqual, `"BODY"`) dataList := []ResponseDataLocation{ResponseDataLocationBody} jsonData, err := json.Marshal(dataList) So(err, ShouldBeNil) So(string(jsonData), ShouldEqual, `["BODY"]`) }) } func TestResponseDataLocation_IsValid(t *testing.T) { Convey("response data location 非法验证", t, func() { So(ResponseDataLocation("Invalid").IsValid(), ShouldBeFalse) }) Convey("response data location 合法验证", t, func() { So(ResponseDataLocation("BODY").IsValid(), ShouldBeTrue) }) }