Correct way to test adding a child to a Dynamic Supervisor

I am trying to create a dynamic supervisor and add nodes on request to it and then testing the same

Here is my code for Dynamic Supervisor

defmodule NodeDynamicSupervisor do
  use DynamicSupervisor

def start_link() do
  DynamicSupervisor.start_link(__MODULE__, :ok, name: __MODULE__)
end

def init(:ok) do
  DynamicSupervisor.init(strategy: :one_for_one)
end

def add_node(private_key, public_key, address, num_of_coins) do
  child_spec = {Node, {private_key, public_key, address, num_of_coins}}
  DynamicSupervisor.start_child(__MODULE__, child_spec)
  end
end

Here is how i decide to test it

defmodule NodeCreationTest do
  use ExUnit.Case

  import ExUnit.CaptureIO

  test "should create node" do
    {:ok, node_pid} = NodeDynamicSupervisor.start_link()
    capture_io(node_pid.add_node(private_key, public_key, address, 0))
  end 

end

I get the following failure in the test case

 code: capture_io(node_pid.add_node(private_key, public_key, address, 0))
 stacktrace:
   :erlang.apply(#PID<0.163.0>, :add_node, [])
   test/create_nodes_test.exs:12: (test)

Am i missing something. Why am I not able to add a node. Thanks in Advance.

Hey @prateek1192 the supervisor functions are not called on the pid, they aren’t methods. You have naked your supervisor and hen hard coded the name here DynamicSupervisor.start_child(__MODULE__, child_spec) so you don’t actually need to do anything with the pid at all.

  test "should create node" do
    {:ok, _} = NodeDynamicSupervisor.start_link()
    capture_io(NodeDynamicSupervisor.add_node(private_key, public_key, address, 0))
  end