Commit 8bc5a7b9 authored by Jürgen Enge's avatar Jürgen Enge
Browse files

server_test added

parent 1967cd68
Pipeline #8599 failed with stages
in 22 seconds
......@@ -4,7 +4,7 @@ Memoriav Media Streaming Server
## Installation
go get gitlab.switch.ch/memoriav/memobase-2020/streaming-server
go build gitlab.switch.ch/memoriav/memobase-2020/streaming-server/cmd/main
go build gitlab.switch.ch/memoriav/memobase-2020/streaming-server/cmd/server
## Prerequsites
......
package main
package server
import (
"github.com/BurntSushi/toml"
......
package main
package server
import (
"context"
......@@ -20,6 +20,7 @@ func main() {
configFile := flag.String("cfg", "./memostream.toml", "config file location")
flag.Parse()
var exPath = ""
// if configfile not found try path of executable as prefix
if !memostream.FileExists(*configFile) {
......
package server
import (
"context"
"database/sql"
"fmt"
"github.com/DATA-DOG/go-sqlmock"
"gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/pkg/memostream"
"io"
"io/ioutil"
"net/http"
"os"
"testing"
)
var db *sql.DB
func TestServer(t *testing.T) {
workingDirectory, err := os.Getwd()
if err != nil {
t.Fatalf("error getting working directory: %v", err)
}
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%v' was not expected when opening a stub database connection", err)
}
defer db.Close()
prep := mock.ExpectPrepare("SELECT uri, access, proto AS protocol, `status` FROM test.entities WHERE sig = ?")
resolverDB, err := memostream.NewResolverDBMysql(db, "SELECT uri, access, proto AS protocol, `status` FROM test.entities WHERE sig = ?")
if err != nil {
t.Fatalf("cannot initialize resolverdb: %v", err)
}
defer resolverDB.Close()
log, lf := memostream.CreateLogger("memostream", "", "DEBUG")
defer lf.Close()
resolver := memostream.NewResolver(resolverDB, 10)
fm := memostream.NewFileMapper(map[string]string{"x": fmt.Sprintf("%s/../../web/static", workingDirectory)})
fmt.Sprintf("%v // %v // %v\n", log, resolver, fm)
srv, err := memostream.NewServer(
"/memo/",
"/command/",
"/iiif/",
"",
"",
"iiif:",
fmt.Sprintf("%s/../../web/template/openseadragon.gohtml", workingDirectory),
"localhost:9876",
resolver,
fm,
"swordfish",
[]string{"HS386"},
log,
os.Stdout,
fmt.Sprintf("%s/../../web/template/error.gohtml", workingDirectory),
fmt.Sprintf("%s/../../web/template/videojs.gohtml", workingDirectory),
fmt.Sprintf("%s/../../web/template/audiohowler.gohtml", workingDirectory),
"/static/",
fmt.Sprintf("%s/../../web/static", workingDirectory),
)
if err != nil {
t.Fatalf("error initializing server: %v", err)
}
var shutdown = false
go func() {
if err := srv.ListenAndServe("", ""); err != nil {
if !shutdown {
t.Errorf("server died: %+v", err)
}
}
}()
t.Logf("checking cache query for http://localhost:9876/memo/sig-001 - proxy")
prep.
ExpectQuery().
WithArgs("sig-001").
WillReturnRows(sqlmock.NewRows([]string{"uri", "access", "protocol", "status"}).
AddRow("http://localhost:9876/static/memoriav_logo_400x400.jpg", "public", "proxy", "ok"))
resp, err := http.Get("http://localhost:9876/memo/sig-001")
if err != nil {
t.Errorf("error checking proxy: %v", err)
}
if resp.StatusCode != 200 {
t.Errorf("error checking proxy - invalid status: %v %v", resp.StatusCode, resp.Status)
}
num, err := io.Copy(ioutil.Discard, resp.Body)
if err != nil {
t.Errorf("error checking proxy - cannot read data: %v", err)
}
if num != 19337 {
t.Errorf("error checking proxy - invalid size %v", num)
}
resp.Body.Close()
t.Logf("checking cache query for http://localhost:9876/memo/sig-002 - file")
prep.
ExpectQuery().
WithArgs("sig-002").
WillReturnRows(sqlmock.NewRows([]string{"uri", "access", "protocol", "status"}).
AddRow("file://x/memoriav_logo_400x400.jpg", "public", "file", "ok"))
resp, err = http.Get("http://localhost:9876/memo/sig-002")
if err != nil {
t.Errorf("error checking file: %v", err)
}
if resp.StatusCode != 200 {
t.Errorf("error checking file - invalid status: %v %v", resp.StatusCode, resp.Status)
}
num, err = io.Copy(ioutil.Discard, resp.Body)
if err != nil {
t.Errorf("error checking file - cannot read data: %v", err)
}
if num != 19337 {
t.Errorf("error checking file - invalid size %v", num)
}
resp.Body.Close()
t.Logf("checking cache query for http://localhost:9876/memo/sig-003 - redirect")
prep.
ExpectQuery().
WithArgs("sig-003").
WillReturnRows(sqlmock.NewRows([]string{"uri", "access", "protocol", "status"}).
AddRow("http://localhost:9876/static/memoriav_logo_400x400.jpg", "public", "redirect", "ok"))
resp, err = http.Get("http://localhost:9876/memo/sig-003")
if err != nil {
t.Errorf("error checking redirect: %v", err)
}
if resp.StatusCode != 200 {
t.Errorf("error checking redirect - invalid status: %v %v", resp.StatusCode, resp.Status)
}
num, err = io.Copy(ioutil.Discard, resp.Body)
if err != nil {
t.Errorf("error checking redirect - cannot read data: %v", err)
}
if num != 19337 {
t.Errorf("error checking redirect - invalid size %v", num)
}
resp.Body.Close()
shutdown = true
srv.Shutdown(context.Background())
}
......@@ -4,6 +4,7 @@ go 1.14
require (
github.com/BurntSushi/toml v0.3.1
github.com/DATA-DOG/go-sqlmock v1.4.1
github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-sql-driver/mysql v1.5.0
......
......@@ -20,7 +20,7 @@
preload="auto"
width="100vw"
height="100vw"
poster="/static/memoriav_logo_400x400.jpg"
poster="/web/static/memoriav_logo_400x400.jpg"
data-setup="{}"
style="width: 100vw; height: 100vh">
<source src="{{.VideoSource}}" type="{{.VideoType}}" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment