0.2.65 - End Credits wiring / Gateway: 0.1.45 - Credits
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package emby
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Where the gateway reads media bytes from is the one address that is not interchangeable
|
||||
// with the others, so all three are pinned against each other here: a television must never
|
||||
// be handed the internal address, and a scan must never be sent out the public way when an
|
||||
// internal one has been named.
|
||||
|
||||
func TestInternalStreamURLPrefersTheMediaAddress(t *testing.T) {
|
||||
client := New(
|
||||
"https://molise.bounceme.net", "https://molise.bounceme.net",
|
||||
"MbyATV", "MbyGateway", time.Second,
|
||||
)
|
||||
client.SetMediaURL("http://10.0.0.2:8096")
|
||||
|
||||
stream := client.InternalStreamURL(Credentials{Token: "tok", DeviceID: "dev"}, "item-1")
|
||||
if !strings.HasPrefix(stream, "http://10.0.0.2:8096/Videos/item-1/stream?") {
|
||||
t.Fatalf("scan should read from the media address, got %q", stream)
|
||||
}
|
||||
}
|
||||
|
||||
// The fallback is what makes the setting optional. A deployment that never names a media
|
||||
// address must behave exactly as it did before there was one, or adding the option would be
|
||||
// a breaking change to every install that ignores it.
|
||||
func TestInternalStreamURLFallsBackToTheGatewayAddress(t *testing.T) {
|
||||
client := New("http://emby:8096", "https://public.example", "MbyATV", "MbyGateway", time.Second)
|
||||
|
||||
stream := client.InternalStreamURL(Credentials{Token: "tok", DeviceID: "dev"}, "item-1")
|
||||
if !strings.HasPrefix(stream, "http://emby:8096/Videos/item-1/stream?") {
|
||||
t.Fatalf("with no media address the scan should use the gateway address, got %q", stream)
|
||||
}
|
||||
}
|
||||
|
||||
// A blank or whitespace value is the same as unset. It arrives from an environment variable
|
||||
// somebody left empty, which is the ordinary way to turn the setting off again, and treating
|
||||
// it as an address would build "/Videos/…" and read from the gateway itself.
|
||||
func TestBlankMediaURLIsTreatedAsUnset(t *testing.T) {
|
||||
client := New("http://emby:8096", "https://public.example", "MbyATV", "MbyGateway", time.Second)
|
||||
client.SetMediaURL(" ")
|
||||
|
||||
stream := client.InternalStreamURL(Credentials{Token: "tok", DeviceID: "dev"}, "item-1")
|
||||
if !strings.HasPrefix(stream, "http://emby:8096/Videos/") {
|
||||
t.Fatalf("blank media address should fall back, got %q", stream)
|
||||
}
|
||||
}
|
||||
|
||||
// A trailing slash is what an operator actually types, and it must not reach the URL as a
|
||||
// double slash — some reverse proxies answer that with a redirect ffmpeg will not follow.
|
||||
func TestMediaURLTolerantOfATrailingSlash(t *testing.T) {
|
||||
client := New("http://emby:8096", "https://public.example", "MbyATV", "MbyGateway", time.Second)
|
||||
client.SetMediaURL("http://10.0.0.2:8096/")
|
||||
|
||||
stream := client.InternalStreamURL(Credentials{Token: "tok", DeviceID: "dev"}, "item-1")
|
||||
if !strings.HasPrefix(stream, "http://10.0.0.2:8096/Videos/") {
|
||||
t.Fatalf("media address should lose its trailing slash, got %q", stream)
|
||||
}
|
||||
}
|
||||
|
||||
// The television's URL is the public address and is not affected by any of this. Nothing
|
||||
// reachable only from the NAS may ever be handed to a set in the house.
|
||||
func TestStreamURLForTelevisionsIgnoresTheMediaAddress(t *testing.T) {
|
||||
client := New("http://emby:8096", "https://public.example", "MbyATV", "MbyGateway", time.Second)
|
||||
client.SetMediaURL("http://10.0.0.2:8096")
|
||||
|
||||
stream := client.StreamURL(Credentials{Token: "tok", DeviceID: "dev"}, "item-1")
|
||||
if !strings.HasPrefix(stream, "https://public.example/Videos/item-1/stream?") {
|
||||
t.Fatalf("televisions must keep the public address, got %q", stream)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user