github.ccut.club/rafael-santiago/cherry@v0.0.0-20161214151746-8ea42c6e9670/src/pkg/tests/rawhttp_test.go (about)

     1  /*
     2   *                                Copyright (C) 2016 by Rafael Santiago
     3   *
     4   * This is a free software. You can redistribute it and/or modify under
     5   * the terms of the GNU General Public License version 2.
     6   *
     7   */
     8  package cherry_test
     9  
    10  import (
    11  	"pkg/rawhttp"
    12  	"testing"
    13  )
    14  
    15  func TestGetFieldsFromPost(t *testing.T) {
    16  	fields := rawhttp.GetFieldsFromPost("POST /path/script.cgi HTTP/1.0\r\n\r\nfoo=bar&bar=foo")
    17  	if len(fields) != 2 {
    18  		t.Fail()
    19  	}
    20  	if fields["foo"] != "bar" {
    21  		t.Fail()
    22  	}
    23  	if fields["bar"] != "foo" {
    24  		t.Fail()
    25  	}
    26  }
    27  
    28  func TestGetHttpFieldFromBuffer(t *testing.T) {
    29  	if rawhttp.GetHTTPFieldFromBuffer("Content-Length", "GET /abc/xy/z.log HTTP/1.0\r\nContent-Length: 255\r\n") != "255" {
    30  		t.Fail()
    31  	}
    32  }
    33  
    34  func TestGetFieldsFromGet(t *testing.T) {
    35  	fields := rawhttp.GetFieldsFromGet("GET /abc/&foo=foo&bar=bar&\r\n\r\n")
    36  	if len(fields) != 2 {
    37  		t.Fail()
    38  	}
    39  	if fields["foo"] != "foo" {
    40  		t.Fail()
    41  	}
    42  	if fields["bar"] != "bar" {
    43  		t.Fail()
    44  	}
    45  }