···6464 live "/nix/caches/:sid/edit", Nix.CacheLive.Index, :edit
6565 live "/nix/caches/:sid", Nix.CacheLive.Show, :show
6666 live "/nix/caches/:sid/show/edit", Nix.CacheLive.Show, :edit
6767- live "/nix/store_paths", Nix.StorePathLive.Index, :index
6868- live "/nix/store_paths/:digest", Nix.StorePathLive.Show, :show
69677068 live "/settings", Settings.IndexLive, :index
7169 live "/settings/access-tokens", Settings.AccessTokenLive.Index, :index
···107105 get "/nix/caches", Nix.CacheController, :list
108106 get "/seeds", SeedController, :list
109107 get "/seeds/:sid", SeedController, :get
110110- get "/seeds/:sid/paths/latest", SeedController, :latest
108108+ get "/seeds/latest", SeedController, :latest
111109 post "/seeds", SeedController, :new
112112- post "/seeds/:sid/paths", SeedController, :new_store_path
113110 end
114111115112 scope "/auth" do
···11-defmodule Sower.Repo.Migrations.AddSeedPathDigestIndex do
22- use Ecto.Migration
33-44- def change do
55- create unique_index(:store_paths, [:path_digest])
66- end
77-end
-54
apps/sower/test/sower/nix_test.exs
···6666 assert %Ecto.Changeset{} = Nix.change_cache(cache)
6767 end
6868 end
6969-7070- describe "store_paths" do
7171- alias Sower.Nix.StorePath
7272-7373- import Sower.NixFixtures
7474-7575- @invalid_attrs %{path: nil}
7676-7777- test "list_store_paths/0 returns all store_paths" do
7878- store_path = store_path_fixture()
7979- assert Nix.list_store_paths() == [store_path]
8080- end
8181-8282- test "get_store_path!/1 returns the store_path with given id" do
8383- store_path = store_path_fixture()
8484- assert Nix.get_store_path!(store_path.id) == store_path
8585- end
8686-8787- test "create_store_path/1 with valid data creates a store_path" do
8888- valid_attrs = %{path: random_store_path()}
8989-9090- assert {:ok, %StorePath{} = store_path} = Nix.create_store_path(valid_attrs)
9191- assert store_path.path == valid_attrs.path
9292- end
9393-9494- test "create_store_path/1 with invalid data returns error changeset" do
9595- assert {:error, %Ecto.Changeset{}} = Nix.create_store_path(@invalid_attrs)
9696- end
9797-9898- test "update_store_path/2 with valid data updates the store_path" do
9999- store_path = store_path_fixture()
100100- update_attrs = %{path: random_store_path()}
101101-102102- assert {:ok, %StorePath{} = store_path} = Nix.update_store_path(store_path, update_attrs)
103103- assert store_path.path == update_attrs.path
104104- end
105105-106106- test "update_store_path/2 with invalid data returns error changeset" do
107107- store_path = store_path_fixture()
108108- assert {:error, %Ecto.Changeset{}} = Nix.update_store_path(store_path, @invalid_attrs)
109109- assert store_path == Nix.get_store_path!(store_path.id)
110110- end
111111-112112- test "delete_store_path/1 deletes the store_path" do
113113- store_path = store_path_fixture()
114114- assert {:ok, %StorePath{}} = Nix.delete_store_path(store_path)
115115- assert_raise Ecto.NoResultsError, fn -> Nix.get_store_path!(store_path.id) end
116116- end
117117-118118- test "change_store_path/1 returns a store_path changeset" do
119119- store_path = store_path_fixture()
120120- assert %Ecto.Changeset{} = Nix.change_store_path(store_path)
121121- end
122122- end
12369end
+18-3
apps/sower/test/sower/orchestration_test.exs
···22 use Sower.DataCase
3344 alias Sower.Orchestration
55+ import Sower.AccountsFixtures
66+77+ setup _ do
88+ org = organization_fixture()
99+ Sower.Repo.put_org_id(org.org_id)
1010+1111+ %{organization: org}
1212+ end
513614 describe "agents" do
715 alias Sower.Orchestration.Agent
···7987 test "create_subscription/1 with valid data creates a subscription" do
8088 valid_attrs = %{sid: "some sid"}
81898282- assert {:ok, %Subscription{} = subscription} = Orchestration.create_subscription(valid_attrs)
9090+ assert {:ok, %Subscription{} = subscription} =
9191+ Orchestration.create_subscription(valid_attrs)
9292+8393 assert subscription.sid == "some sid"
8494 end
8595···91101 subscription = subscription_fixture()
92102 update_attrs = %{sid: "some updated sid"}
931039494- assert {:ok, %Subscription{} = subscription} = Orchestration.update_subscription(subscription, update_attrs)
104104+ assert {:ok, %Subscription{} = subscription} =
105105+ Orchestration.update_subscription(subscription, update_attrs)
106106+95107 assert subscription.sid == "some updated sid"
96108 end
9710998110 test "update_subscription/2 with invalid data returns error changeset" do
99111 subscription = subscription_fixture()
100100- assert {:error, %Ecto.Changeset{}} = Orchestration.update_subscription(subscription, @invalid_attrs)
112112+113113+ assert {:error, %Ecto.Changeset{}} =
114114+ Orchestration.update_subscription(subscription, @invalid_attrs)
115115+101116 assert subscription == Orchestration.get_subscription!(subscription.id)
102117 end
103118
+4-22
apps/sower/test/sower/seed_test.exs
···2525 end
2626 end
27272828- describe "submit/1" do
2828+ describe "create/1" do
2929 test "creates the seed if it does not exist" do
3030 name = unique_seed_name()
3131···3535 assert %Seed{id: ^id} = Seed.latest(seed.name, "nixos")
3636 end
37373838- test "adds a store path if seed already exists" do
3939- seed = seed_fixture()
4040-4141- {:ok, _} =
4242- Seed.submit(seed.sid, random_store_path())
4343-4444- assert Enum.count(seed |> Sower.Repo.preload(:store_paths) |> Map.get(:store_paths)) == 1
4545-4646- {:ok, _} =
4747- Seed.submit(seed.sid, random_store_path())
4848-4949- assert Enum.count(seed |> Sower.Repo.preload(:store_paths) |> Map.get(:store_paths)) == 2
5050- end
5151-5252- test "no new store paths if seed and path already exist" do
5353- store_path = store_path_fixture()
3838+ test "upserts" do
5439 seed = seed_fixture()
55405656- {:ok, _} = Seed.submit(seed.sid, store_path.path)
5757-5858- seed = seed |> Sower.Repo.preload(:store_paths)
4141+ {:ok, _} = Seed.create(Map.from_struct(seed))
59426060- assert Enum.count(seed.store_paths) == 1
6161- assert Repo.all(Sower.Nix.StorePath) |> Enum.count() == 1
4343+ assert Repo.all(Sower.Seed) |> Enum.count() == 1
6244 end
6345 end
6446end