github.com/orteth01/up@v0.2.0/internal/header/header_test.go (about)

     1  package header
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/tj/assert"
     7  )
     8  
     9  func TestMatcher_Lookup(t *testing.T) {
    10  	rules := Rules{
    11  		"*": {
    12  			"X-Type": "html",
    13  		},
    14  		"*.css": {
    15  			"X-Type": "css",
    16  		},
    17  		"/docs/alerts": {
    18  			"X-Type": "docs alerts",
    19  		},
    20  		"/docs/*": {
    21  			"X-Type": "docs",
    22  		},
    23  	}
    24  
    25  	m, err := Compile(rules)
    26  	assert.NoError(t, err, "compile")
    27  
    28  	assert.Equal(t, Fields{"X-Type": "html"}, m.Lookup("/something"))
    29  	assert.Equal(t, Fields{"X-Type": "html"}, m.Lookup("/docs"))
    30  	assert.Equal(t, Fields{"X-Type": "docs"}, m.Lookup("/docs/"))
    31  	assert.Equal(t, Fields{"X-Type": "css"}, m.Lookup("/style.css"))
    32  	assert.Equal(t, Fields{"X-Type": "css"}, m.Lookup("/public/css/style.css"))
    33  	assert.Equal(t, Fields{"X-Type": "docs"}, m.Lookup("/docs/checks"))
    34  	assert.Equal(t, Fields{"X-Type": "docs alerts"}, m.Lookup("/docs/alerts"))
    35  }