-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoinformer_test.go
67 lines (55 loc) · 1.91 KB
/
videoinformer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
//"fmt"
"testing"
"net/http"
"net/http/httptest"
"io/ioutil"
"encoding/json"
"mime/multipart"
"os"
"bytes"
"io"
)
type metadata struct {
Streams []struct {
Index int
Codec_name string
Codec_type string
Width int
Height int
Bit_rate string
}
}
func TestUploadVideoHandler(t *testing.T) {
path := "out-7.ogv"
file, err := os.Open(path); defer file.Close()
if err != nil { t.Fatal(err) }
b := bytes.Buffer{}
writer := multipart.NewWriter(&b)
part, err := writer.CreateFormFile("file", path)
if err != nil { t.Fatal(err) }
_, err = io.Copy(part, file)
if err != nil { t.Fatal(err) }
writer.Close()
req, err := http.NewRequest("POST", "http://localhost:4000/api/uploadVideo", &b)
//resp, err := http.Post("http://localhost:4000/api/uploadVideo", writer.FormDataContentType(), &b)
if err != nil { t.Fatal(err) }
req.Header.Set("Content-Type", writer.FormDataContentType())
//resp, _ := http.DefaultClient.Do(req); defer resp.Body.Close()
rr := httptest.NewRecorder()
http.HandlerFunc(uploadVideoHandler).ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("Status code differs. Expected %d .\n Got %d instead", http.StatusOK, status)
}
resp := rr.Result()
body, err := ioutil.ReadAll(resp.Body); defer resp.Body.Close()
if err != nil { t.Fatal(err) }
data := metadata{}
json.Unmarshal(body, &data)
expected := "video"
for _, v := range data.Streams { //Перебираем потоки видеозаписи (данные, видео, аудио)
if v.Codec_type == expected { return } //В загруженной видеозаписи есть видеопоток
}
t.Error("В загруженной видеозаписи нет видеопотока")
}