rambleraptor commented on code in PR #1174: URL: https://github.com/apache/iceberg-go/pull/1174#discussion_r3391772508
########## catalog/rest/endpoints_test.go: ########## @@ -0,0 +1,115 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package rest + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestEndpointFromString(t *testing.T) { + t.Parallel() + + cases := []struct { + in string + want endpoint + wantErr bool + }{ + {in: "GET /v1/{prefix}/namespaces", want: endpoint{http.MethodGet, "/v1/{prefix}/namespaces"}}, + {in: "POST /v1/{prefix}/transactions/commit", want: endpoint{http.MethodPost, "/v1/{prefix}/transactions/commit"}}, + {in: "HEAD /v1/{prefix}/namespaces/{namespace}", want: endpoint{http.MethodHead, "/v1/{prefix}/namespaces/{namespace}"}}, + // Extra surrounding/internal whitespace is tolerated. + {in: " DELETE /v1/{prefix}/namespaces/{namespace} ", want: endpoint{http.MethodDelete, "/v1/{prefix}/namespaces/{namespace}"}}, + {in: "", wantErr: true}, + {in: "GET", wantErr: true}, + {in: "GET /a /b", wantErr: true}, + } + + for _, tc := range cases { + got, err := endpointFromString(tc.in) + if tc.wantErr { + require.Error(t, err) + assert.ErrorIs(t, err, ErrRESTError) + + continue + } + require.NoError(t, err) + assert.Equal(t, tc.want, got) + } +} + +func TestEndpointRoundTripString(t *testing.T) { + t.Parallel() + Review Comment: Yeah, we should absolutely have that. I really don't love mock tests against the REST spec (how do you know your mocks truly match the spec?), but they're definitely needed in this case. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
