(t *testing.T)
| 1094 | } |
| 1095 | |
| 1096 | func TestMuxSubroutesBasic(t *testing.T) { |
| 1097 | hIndex := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1098 | w.Write([]byte("index")) |
| 1099 | }) |
| 1100 | hArticlesList := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1101 | w.Write([]byte("articles-list")) |
| 1102 | }) |
| 1103 | hSearchArticles := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1104 | w.Write([]byte("search-articles")) |
| 1105 | }) |
| 1106 | hGetArticle := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1107 | w.Write([]byte(fmt.Sprintf("get-article:%s", URLParam(r, "id")))) |
| 1108 | }) |
| 1109 | hSyncArticle := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1110 | w.Write([]byte(fmt.Sprintf("sync-article:%s", URLParam(r, "id")))) |
| 1111 | }) |
| 1112 | |
| 1113 | r := NewRouter() |
| 1114 | // var rr1, rr2 *Mux |
| 1115 | r.Get("/", hIndex) |
| 1116 | r.Route("/articles", func(r Router) { |
| 1117 | // rr1 = r.(*Mux) |
| 1118 | r.Get("/", hArticlesList) |
| 1119 | r.Get("/search", hSearchArticles) |
| 1120 | r.Route("/{id}", func(r Router) { |
| 1121 | // rr2 = r.(*Mux) |
| 1122 | r.Get("/", hGetArticle) |
| 1123 | r.Get("/sync", hSyncArticle) |
| 1124 | }) |
| 1125 | }) |
| 1126 | |
| 1127 | // log.Println("~~~~~~~~~") |
| 1128 | // log.Println("~~~~~~~~~") |
| 1129 | // debugPrintTree(0, 0, r.tree, 0) |
| 1130 | // log.Println("~~~~~~~~~") |
| 1131 | // log.Println("~~~~~~~~~") |
| 1132 | |
| 1133 | // log.Println("~~~~~~~~~") |
| 1134 | // log.Println("~~~~~~~~~") |
| 1135 | // debugPrintTree(0, 0, rr1.tree, 0) |
| 1136 | // log.Println("~~~~~~~~~") |
| 1137 | // log.Println("~~~~~~~~~") |
| 1138 | |
| 1139 | // log.Println("~~~~~~~~~") |
| 1140 | // log.Println("~~~~~~~~~") |
| 1141 | // debugPrintTree(0, 0, rr2.tree, 0) |
| 1142 | // log.Println("~~~~~~~~~") |
| 1143 | // log.Println("~~~~~~~~~") |
| 1144 | |
| 1145 | ts := httptest.NewServer(r) |
| 1146 | defer ts.Close() |
| 1147 | |
| 1148 | var body, expected string |
| 1149 | |
| 1150 | _, body = testRequest(t, ts, "GET", "/", nil) |
| 1151 | expected = "index" |
| 1152 | if body != expected { |
| 1153 | t.Fatalf("expected:%s got:%s", expected, body) |
nothing calls this directly
no test coverage detected