github.com/iDigitalFlame/xmt@v0.5.1/com/wc2/target_test.go (about)

     1  // Copyright (C) 2020 - 2023 iDigitalFlame
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU General Public License as published by
     5  // the Free Software Foundation, either version 3 of the License, or
     6  // any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU General Public License
    14  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    15  //
    16  
    17  package wc2
    18  
    19  import (
    20  	"net/http"
    21  	"testing"
    22  
    23  	"github.com/iDigitalFlame/xmt/util/text"
    24  )
    25  
    26  func TestTargets(t *testing.T) {
    27  	var i Target
    28  	i.Host = text.Matcher("%10fs-Test123")
    29  	i.Agent = text.Matcher("Test123-%10fs")
    30  	i.Header("Content-Type", text.String("text/html"))
    31  	i.Header("Content-Host", text.Matcher("host-%10fs-%h"))
    32  	var (
    33  		r = i.Rule()
    34  		h http.Request
    35  	)
    36  	h.Host = i.Host.String()
    37  	h.Header = http.Header{
    38  		"User-Agent":   []string{i.Agent.String()},
    39  		"Content-Type": []string{"text/html"},
    40  		"Content-Host": []string{text.Matcher("host-%10fs-%h").String()},
    41  	}
    42  	if !r.match(&h) {
    43  		t.Fatalf("TestTargets(): Rule does not match generated http.Request!")
    44  	}
    45  }