File size: 1,253 Bytes
c9c49ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
defmodule Plausible.InternalStatsApiVersionTest do
  use ExUnit.Case, async: true

  alias Plausible.InternalStatsApiVersion

  describe "api_version/0" do
    test "returns a non-negative integer" do
      assert is_integer(InternalStatsApiVersion.api_version())
      assert InternalStatsApiVersion.api_version() >= 0
    end
  end

  describe "effective_version/0" do
    test "equals api_version in single-node setup" do
      assert InternalStatsApiVersion.effective_version() ==
               InternalStatsApiVersion.api_version()
    end
  end

  describe "cluster_min/1" do
    test "returns the minimum integer from results" do
      assert InternalStatsApiVersion.cluster_min([3, 2, 2]) == 2
    end

    test "ignores non-integer results" do
      assert InternalStatsApiVersion.cluster_min([{:badrpc, :timeout}, 2, 3]) == 2
    end

    test "falls back to local api_version when all results are non-integer" do
      assert InternalStatsApiVersion.cluster_min([{:badrpc, :timeout}]) ==
               InternalStatsApiVersion.api_version()
    end

    test "falls back to local api_version for empty results" do
      assert InternalStatsApiVersion.cluster_min([]) ==
               InternalStatsApiVersion.api_version()
    end
  end
end