From d97b76104eabcd670aa78b8281832ab128373d36 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 7 Aug 2020 15:10:34 +0200 Subject: [PATCH] Mix Task Frontend: Add tests. --- test/fixtures/tesla_mock/frontend.zip | Bin 0 -> 186 bytes test/fixtures/test.txt | 1 - test/tasks/frontend_test.exs | 69 ++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/tesla_mock/frontend.zip delete mode 100644 test/fixtures/test.txt create mode 100644 test/tasks/frontend_test.exs diff --git a/test/fixtures/tesla_mock/frontend.zip b/test/fixtures/tesla_mock/frontend.zip new file mode 100644 index 0000000000000000000000000000000000000000..114d576a3806cb864566e06b1fdd8e4cec0b83a7 GIT binary patch literal 186 zcmWIWW@h1H00FfHUIC}W{!bSHvO$=GL586uwYWsDq@pA=gp+}}VufQ|KbKB?X$3a} zBg+eB1_m%ul95@g07QujC8-r93Tc@+sayfxj7)OOxXhIRS;xQ##0wfhEQBqr5L?h} U2=HcQ1F2&KLO&oK2I4RP06@qk+yDRo literal 0 HcmV?d00001 diff --git a/test/fixtures/test.txt b/test/fixtures/test.txt deleted file mode 100644 index e9ea42a12..000000000 --- a/test/fixtures/test.txt +++ /dev/null @@ -1 +0,0 @@ -this is a text file diff --git a/test/tasks/frontend_test.exs b/test/tasks/frontend_test.exs new file mode 100644 index 000000000..5cd4594e2 --- /dev/null +++ b/test/tasks/frontend_test.exs @@ -0,0 +1,69 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.FrontendTest do + use Pleroma.DataCase + alias Mix.Tasks.Pleroma.Frontend + + @dir "test/frontend_static_test" + + setup do + File.mkdir_p!(@dir) + clear_config([:instance, :static_dir], @dir) + + on_exit(fn -> + File.rm_rf(@dir) + end) + end + + test "it downloads and unzips a known frontend" do + clear_config([:frontends, :available], %{ + "pleroma" => %{ + "ref" => "fantasy", + "name" => "pleroma", + "build_url" => "http://gensokyo.2hu/builds/${ref}", + "build_dir" => "" + } + }) + + Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} -> + %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")} + end) + + Frontend.run(["install", "pleroma"]) + assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"])) + end + + test "it also works given a file" do + clear_config([:frontends, :available], %{ + "pleroma" => %{ + "ref" => "fantasy", + "name" => "pleroma", + "build_dir" => "" + } + }) + + Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"]) + assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"])) + end + + test "it downloads and unzips unknown frontends" do + Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} -> + %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")} + end) + + Frontend.run([ + "install", + "unknown", + "--ref", + "baka", + "--build-url", + "http://gensokyo.2hu/madeup.zip", + "--build-dir", + "" + ]) + + assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"])) + end +end