Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.82 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "testing"
  5.     "net/http/httptest"
  6.     "net/http"
  7.     "log"
  8.     "sync"
  9.     "generic"
  10. )
  11.  
  12.  
  13. type FakeTlinksMap struct{
  14.     Links map[string]map[string]struct{}
  15.     generic.TlinksMap
  16.     sync.Mutex
  17. }
  18.  
  19. func (*FakeTlinksMap) GetRandomLink(host string) string {
  20.     log.Print("My link is running")
  21.     return "http://example.com/path1"
  22. }
  23.  
  24.  
  25. func TestBasic(t *testing.T) {
  26.     linksMap = &FakeTlinksMap{Links: make(map[string]map[string]struct{})}
  27.     ts := httptest.NewServer(http.HandlerFunc(redirectHandler))
  28.     defer ts.Close()
  29.  
  30.     // Set up the HTTP request
  31.     req, err := http.NewRequest("GET", ts.URL, nil)
  32.     //req.Header.Add("Host", "sd.ua")
  33.     req.Host = "sd.ua"
  34.  
  35.     transport := http.Transport{}
  36.     resp, err := transport.RoundTrip(req)
  37.     if err != nil {
  38.         t.Fatal(err)
  39.     }
  40.  
  41.     log.Printf("Status code: %d", resp.StatusCode)
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement