|
| 1 | +package integration |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/http/httptest" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + |
| 10 | + api "github.com/ogen-go/ogen/internal/integration/test_deep_object_additional_properties" |
| 11 | +) |
| 12 | + |
| 13 | +type testDeepObjectAdditionalProperties struct { |
| 14 | + api.UnimplementedHandler |
| 15 | + params api.QueryWithAdditionalPropertiesParams |
| 16 | +} |
| 17 | + |
| 18 | +func (s *testDeepObjectAdditionalProperties) QueryWithAdditionalProperties(ctx context.Context, params api.QueryWithAdditionalPropertiesParams) (api.QueryWithAdditionalPropertiesOK, error) { |
| 19 | + s.params = params |
| 20 | + obj, ok := params.Object.Get() |
| 21 | + if !ok { |
| 22 | + return api.QueryWithAdditionalPropertiesOK{}, nil |
| 23 | + } |
| 24 | + return api.QueryWithAdditionalPropertiesOK(obj), nil |
| 25 | +} |
| 26 | + |
| 27 | +func TestDeepObjectAdditionalProperties(t *testing.T) { |
| 28 | + handler := &testDeepObjectAdditionalProperties{} |
| 29 | + srv, err := api.NewServer(handler) |
| 30 | + require.NoError(t, err) |
| 31 | + |
| 32 | + s := httptest.NewServer(srv) |
| 33 | + defer s.Close() |
| 34 | + |
| 35 | + client, err := api.NewClient(s.URL) |
| 36 | + require.NoError(t, err) |
| 37 | + |
| 38 | + ctx := context.Background() |
| 39 | + |
| 40 | + t.Run("WithValues", func(t *testing.T) { |
| 41 | + input := api.QueryWithAdditionalPropertiesObject{ |
| 42 | + "foo": "bar", |
| 43 | + "baz": "qux", |
| 44 | + } |
| 45 | + resp, err := client.QueryWithAdditionalProperties(ctx, api.QueryWithAdditionalPropertiesParams{ |
| 46 | + Object: api.NewOptQueryWithAdditionalPropertiesObject(input), |
| 47 | + }) |
| 48 | + require.NoError(t, err) |
| 49 | + require.Equal(t, "bar", map[string]string(resp)["foo"]) |
| 50 | + require.Equal(t, "qux", map[string]string(resp)["baz"]) |
| 51 | + }) |
| 52 | + |
| 53 | + t.Run("WithoutValues", func(t *testing.T) { |
| 54 | + resp, err := client.QueryWithAdditionalProperties(ctx, api.QueryWithAdditionalPropertiesParams{}) |
| 55 | + require.NoError(t, err) |
| 56 | + require.Empty(t, resp) |
| 57 | + }) |
| 58 | +} |
0 commit comments