func TestPreviewController(t *testing.T) { p := datastore.NewProgram() p.FunctionId = "iterator" p.StartAt = time.Now() p.Parameters = map[string]string{ "start_at": "0", "end_at": "10", "target_duration": "5.0", "url_format": testUrlFormat, } if err := p.Save(); err != nil { t.Error("failed to save test program:", err) return } testRequestUrl := fmt.Sprintf("http://localhost:8080/vod/%s.m3u8", p.UUID) fmt.Println(testRequestUrl) req, err := http.NewRequest("GET", testRequestUrl, nil) if err != nil { t.Error("Failed to create test request:", err) return } w := httptest.NewRecorder() pc := http.StripPrefix("/vod/", PreviewController{}) pc.ServeHTTP(w, req) if w.Code > 299 || w.Code < 200 { t.Error("Error: Expected 200 response but got", w.Code) } }
// programPosted posts a program (or programs) and returns it's UUID // if multiple programs are saved, only the last uuid is returned. func programPosted(w http.ResponseWriter, r *http.Request) string { requestedProgram := strings.Split(r.URL.Path, ".")[0] decoder := json.NewDecoder(r.Body) if _, err := decoder.Token(); err != nil { http.Error(w, "Error parsing program", 400) return "" } var p datastore.Program for decoder.More() { if err := decoder.Decode(&p); err != nil { http.Error(w, "Error parsing program instsance", 400) return "" } if requestedProgram == "new" || requestedProgram == "temp" { p.UUID = datastore.NewProgram().UUID } p.Save() p.Expire(NewProgramExpirationTime) } return p.UUID }