github.com/splucs/witchcraft-go-server@v1.7.0/wrouter/whttprouter/routerimpl_test.go (about)

     1  // Copyright (c) 2018 Palantir Technologies. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package whttprouter_test
    16  
    17  import (
    18  	"net/http"
    19  	"net/http/httptest"
    20  	"testing"
    21  
    22  	"github.com/palantir/witchcraft-go-server/wrouter"
    23  	"github.com/palantir/witchcraft-go-server/wrouter/whttprouter"
    24  	"github.com/stretchr/testify/assert"
    25  	"github.com/stretchr/testify/require"
    26  )
    27  
    28  func TestNew(t *testing.T) {
    29  	handlerCalled := false
    30  	router := whttprouter.New(whttprouter.RedirectTrailingSlash(false))
    31  	router.Register(http.MethodGet, []wrouter.PathSegment{
    32  		{
    33  			Type:  wrouter.LiteralSegment,
    34  			Value: "hello",
    35  		},
    36  	}, http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
    37  		handlerCalled = true
    38  	}))
    39  
    40  	server := httptest.NewServer(router)
    41  	defer server.Close()
    42  
    43  	_, err := http.Get(server.URL + "/hello/")
    44  	require.NoError(t, err)
    45  
    46  	assert.False(t, handlerCalled)
    47  }