@@ -71,6 +71,48 @@ func TestEndpoint_UnmarshalJSON(t *testing.T) {
7171 assert .Equal (t , "admin" , endpoint .EndpointConfig .Authentication .AuthenticationPolicy .Basic .Password , "Authentication Password should match" )
7272 })
7373
74+ t .Run ("Valid EndpointConfiguration with reference" , func (t * testing.T ) {
75+ input := `{
76+ "uri": "http://example.com/{id}",
77+ "authentication": {
78+ "oauth2": { "use": "secret" }
79+ }
80+ }`
81+
82+ var endpoint Endpoint
83+ err := json .Unmarshal ([]byte (input ), & endpoint )
84+
85+ assert .NoError (t , err , "Unmarshal should not return an error" )
86+ assert .NotNil (t , endpoint .EndpointConfig , "EndpointConfig should be set" )
87+ assert .NotNil (t , endpoint .EndpointConfig .URI , "EndpointConfig URI should be set" )
88+ assert .Nil (t , endpoint .EndpointConfig .RuntimeExpression , "EndpointConfig Expression should not be set" )
89+ assert .Equal (t , "secret" , endpoint .EndpointConfig .Authentication .AuthenticationPolicy .OAuth2 .Use , "Authentication secret should match" )
90+ b , err := json .Marshal (& endpoint )
91+ assert .NoError (t , err , "Marshal should not return an error" )
92+ assert .JSONEq (t , input , string (b ), "Output JSON should match" )
93+ })
94+
95+ t .Run ("Valid EndpointConfiguration with reference and expression" , func (t * testing.T ) {
96+ input := `{
97+ "uri": "${example}",
98+ "authentication": {
99+ "oauth2": { "use": "secret" }
100+ }
101+ }`
102+
103+ var endpoint Endpoint
104+ err := json .Unmarshal ([]byte (input ), & endpoint )
105+
106+ assert .NoError (t , err , "Unmarshal should not return an error" )
107+ assert .NotNil (t , endpoint .EndpointConfig , "EndpointConfig should be set" )
108+ assert .Nil (t , endpoint .EndpointConfig .URI , "EndpointConfig URI should not be set" )
109+ assert .NotNil (t , endpoint .EndpointConfig .RuntimeExpression , "EndpointConfig Expression should be set" )
110+ assert .Equal (t , "secret" , endpoint .EndpointConfig .Authentication .AuthenticationPolicy .OAuth2 .Use , "Authentication secret should match" )
111+ b , err := json .Marshal (& endpoint )
112+ assert .NoError (t , err , "Marshal should not return an error" )
113+ assert .JSONEq (t , input , string (b ), "Output JSON should match" )
114+ })
115+
74116 t .Run ("Invalid JSON Structure" , func (t * testing.T ) {
75117 input := `{"invalid": "data"}`
76118 var endpoint Endpoint
0 commit comments