Prepara l'architettura multi-nodo (MediaMTX+ffmpeg) con assignment URL per sessione, admin di provision/drain e provider Cloud/DNS astratti verso mltv-stream.net. Co-authored-by: Cursor <cursoragent@cursor.com>
83 lines
2.4 KiB
Ruby
83 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
RSpec.describe Streams::CloudProviders::Hetzner do
|
|
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
|
let(:conn) do
|
|
Faraday.new(url: "https://api.hetzner.cloud/v1") do |f|
|
|
f.request :json
|
|
f.response :json
|
|
f.adapter :test, stubs
|
|
end
|
|
end
|
|
let(:provider) { described_class.new(token: "test-token", conn: conn) }
|
|
|
|
def with_env(vars)
|
|
previous = vars.keys.index_with { |k| ENV[k] }
|
|
vars.each { |k, v| ENV[k] = v }
|
|
yield
|
|
ensure
|
|
previous.each { |k, v| v.nil? ? ENV.delete(k) : ENV[k] = v }
|
|
end
|
|
|
|
after { stubs.verify_stubbed_calls }
|
|
|
|
it "creates a server and waits until running" do
|
|
with_env(
|
|
"HCLOUD_LOCATION" => "fsn1",
|
|
"HCLOUD_SERVER_TYPE" => "cpx21",
|
|
"HCLOUD_IMAGE" => "debian-12",
|
|
"HCLOUD_SSH_KEY" => "matchlivetv-stream"
|
|
) do
|
|
stubs.post("/servers") do |env|
|
|
body = JSON.parse(env.body)
|
|
expect(body["name"]).to eq("mltv-stream-ingest-01")
|
|
expect(body["location"]).to eq("fsn1")
|
|
[
|
|
201,
|
|
{ "Content-Type" => "application/json" },
|
|
{
|
|
"server" => {
|
|
"id" => 42,
|
|
"name" => "mltv-stream-ingest-01",
|
|
"status" => "initializing",
|
|
"public_net" => { "ipv4" => { "ip" => "49.13.1.2" } },
|
|
"private_net" => []
|
|
},
|
|
"action" => { "id" => 7, "status" => "running" }
|
|
}
|
|
]
|
|
end
|
|
stubs.get("/actions/7") do
|
|
[200, { "Content-Type" => "application/json" }, { "action" => { "id" => 7, "status" => "success" } }]
|
|
end
|
|
stubs.get("/servers/42") do
|
|
[
|
|
200,
|
|
{ "Content-Type" => "application/json" },
|
|
{
|
|
"server" => {
|
|
"id" => 42,
|
|
"name" => "mltv-stream-ingest-01",
|
|
"status" => "running",
|
|
"public_net" => { "ipv4" => { "ip" => "49.13.1.2" } },
|
|
"private_net" => []
|
|
}
|
|
}
|
|
]
|
|
end
|
|
|
|
instance = provider.create_node(name: "mltv-stream-ingest-01", labels: { role: "stream-node" })
|
|
expect(instance.id).to eq("42")
|
|
expect(instance.public_ip).to eq("49.13.1.2")
|
|
expect(instance.status).to eq("running")
|
|
end
|
|
end
|
|
|
|
it "destroys a server" do
|
|
stubs.delete("/servers/42") { [204, {}, ""] }
|
|
expect(provider.destroy_node("42")).to eq(true)
|
|
end
|
|
end
|