• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coryodaniel / k8s / 807e93631268e5fd52ca29e3e4755088cf11bf27-PR-262

pending completion
807e93631268e5fd52ca29e3e4755088cf11bf27-PR-262

Pull #262

github

mruoss
add possibility to wait for delete
Pull Request #262: add possibility to wait for delete

6 of 6 new or added lines in 1 file covered. (100.0%)

732 of 1009 relevant lines covered (72.55%)

44.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/lib/k8s/client/runner/stream/list_request.ex
1
defmodule K8s.Client.Runner.Stream.ListRequest do
2
  @moduledoc "`:list` `K8s.Operation` encapsulated with pagination and `K8s.Conn`"
3

4
  alias K8s.Client.Runner.Base
5

6
  @limit 10
7
  @typedoc "Pagination continue token"
8
  @type continue_t :: nil | :halt | binary()
9

10
  @type responses_t :: map() | {:error, K8s.Client.HTTPError.t()}
11

12
  @typedoc "List operation as a Stream data type"
13
  @type t :: %__MODULE__{
14
          operation: K8s.Operation.t(),
15
          conn: K8s.Conn.t(),
16
          continue: continue_t,
17
          limit: pos_integer,
18
          http_opts: Keyword.t()
19
        }
20
  defstruct operation: nil, conn: nil, continue: nil, http_opts: [], limit: @limit
21

22
  @spec stream(K8s.Conn.t(), K8s.Operation.t(), Keyword.t()) :: Enumerable.t(responses_t)
23
  def stream(conn, op, http_opts) do
24
    Stream.resource(
1✔
25
      fn ->
26
        struct!(__MODULE__, operation: op, conn: conn, http_opts: http_opts)
1✔
27
      end,
28
      &next_item/1,
29
      &Function.identity/1
30
    )
31
  end
32

33
  @spec next_item(t()) :: {responses_t(), t()}
34
  def next_item(%__MODULE__{continue: :halt}), do: {:halt, nil}
×
35

36
  def next_item(state) do
37
    with {:ok, response} <-
1✔
38
           list(state.conn, state.operation, state.http_opts, state.limit, state.continue),
1✔
39
         cont <- maybe_continue(response),
1✔
40
         {:ok, items} <- Map.fetch(response, "items") do
1✔
41
      {items, struct!(state, continue: cont)}
42
    else
43
      :halt ->
44
        {:halt, nil}
45

46
      :error ->
47
        {:halt, nil}
48

49
      {:error, error} ->
50
        {[{:error, error}], struct!(state, continue: :halt)}
51
    end
52
  end
53

54
  @spec list(K8s.Conn.t(), K8s.Operation.t(), Keyword.t(), integer(), continue_t()) ::
55
          K8s.Client.Provider.response_t()
56
  defp list(conn, op, http_opts, limit, continue) do
57
    new_params = [limit: limit, continue: continue]
1✔
58
    http_opts = Keyword.update(http_opts, :params, new_params, &Keyword.merge(&1, new_params))
1✔
59

60
    Base.run(conn, op, http_opts)
1✔
61
  end
62

63
  @spec maybe_continue(map | :halt) :: continue_t()
64
  defp maybe_continue(%{"metadata" => %{"continue" => ""}}), do: :halt
×
65

66
  defp maybe_continue(%{"metadata" => %{"continue" => cont}}) when is_binary(cont),
67
    do: cont
×
68

69
  defp maybe_continue(_map), do: :halt
1✔
70
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc