...

Source file src/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/autoneg_test.go

Documentation: github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg

     1  /*
     2  Copyright (c) 2011, Open Knowledge Foundation Ltd.
     3  All rights reserved.
     4  
     5  HTTP Content-Type Autonegotiation.
     6  
     7  The functions in this package implement the behaviour specified in
     8  http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
     9  
    10  Redistribution and use in source and binary forms, with or without
    11  modification, are permitted provided that the following conditions are
    12  met:
    13  
    14  	Redistributions of source code must retain the above copyright
    15  	notice, this list of conditions and the following disclaimer.
    16  
    17  	Redistributions in binary form must reproduce the above copyright
    18  	notice, this list of conditions and the following disclaimer in
    19  	the documentation and/or other materials provided with the
    20  	distribution.
    21  
    22  	Neither the name of the Open Knowledge Foundation Ltd. nor the
    23  	names of its contributors may be used to endorse or promote
    24  	products derived from this software without specific prior written
    25  	permission.
    26  
    27  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    28  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    29  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    30  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    31  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    32  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    33  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    34  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    35  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    36  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    37  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    38  */
    39  package goautoneg
    40  
    41  import (
    42  	"testing"
    43  )
    44  
    45  var chrome = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
    46  
    47  func TestParseAccept(t *testing.T) {
    48  	alternatives := []string{"text/html", "image/png"}
    49  	content_type := Negotiate(chrome, alternatives)
    50  	if content_type != "image/png" {
    51  		t.Errorf("got %s expected image/png", content_type)
    52  	}
    53  
    54  	alternatives = []string{"text/html", "text/plain", "text/n3"}
    55  	content_type = Negotiate(chrome, alternatives)
    56  	if content_type != "text/html" {
    57  		t.Errorf("got %s expected text/html", content_type)
    58  	}
    59  
    60  	alternatives = []string{"text/n3", "text/plain"}
    61  	content_type = Negotiate(chrome, alternatives)
    62  	if content_type != "text/plain" {
    63  		t.Errorf("got %s expected text/plain", content_type)
    64  	}
    65  
    66  	alternatives = []string{"text/n3", "application/rdf+xml"}
    67  	content_type = Negotiate(chrome, alternatives)
    68  	if content_type != "text/n3" {
    69  		t.Errorf("got %s expected text/n3", content_type)
    70  	}
    71  }
    72  

View as plain text