...

Source file src/github.com/ory/fosite/access_write_test.go

Documentation: github.com/ory/fosite

     1  /*
     2   * Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   * @author		Aeneas Rekkas <aeneas+oss@aeneas.io>
    17   * @copyright 	2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
    18   * @license 	Apache-2.0
    19   *
    20   */
    21  
    22  package fosite_test
    23  
    24  import (
    25  	"net/http"
    26  	"testing"
    27  
    28  	"github.com/golang/mock/gomock"
    29  	"github.com/stretchr/testify/assert"
    30  
    31  	. "github.com/ory/fosite"
    32  	. "github.com/ory/fosite/internal"
    33  )
    34  
    35  func TestWriteAccessResponse(t *testing.T) {
    36  	f := &Fosite{}
    37  	header := http.Header{}
    38  	ctrl := gomock.NewController(t)
    39  	rw := NewMockResponseWriter(ctrl)
    40  	ar := NewMockAccessRequester(ctrl)
    41  	resp := NewMockAccessResponder(ctrl)
    42  	defer ctrl.Finish()
    43  
    44  	rw.EXPECT().Header().AnyTimes().Return(header)
    45  	rw.EXPECT().WriteHeader(http.StatusOK)
    46  	rw.EXPECT().Write(gomock.Any())
    47  	resp.EXPECT().ToMap().Return(map[string]interface{}{})
    48  
    49  	f.WriteAccessResponse(rw, ar, resp)
    50  	assert.Equal(t, "application/json;charset=UTF-8", header.Get("Content-Type"))
    51  	assert.Equal(t, "no-store", header.Get("Cache-Control"))
    52  	assert.Equal(t, "no-cache", header.Get("Pragma"))
    53  }
    54  

View as plain text