Giter Site home page Giter Site logo

Comments (5)

mruoss avatar mruoss commented on August 16, 2024 1

That being said I'm gonna change the template to not add the operator to the supervision tree in :test env. Thanks for the issue.

from bonny.

mruoss avatar mruoss commented on August 16, 2024

What is the errors you see? Can you try with mix test --no-start?

from bonny.

kennethito avatar kennethito commented on August 16, 2024

What is the errors you see? Can you try with mix test --no-start?

The error and steps are in the repro link, but reposting here.

** (Mix) Could not start application bonny_example: BonnyExample.Application.start(:normal, [env: :test]) returned an error: shutdown: failed to start child: BonnyExample.Operator
    ** (EXIT) shutdown: failed to start child: %K8s.Operation{api_version: "bonny-example.test.com/v1", data: nil, method: :get, name: "BonnyExample", path_params: [namespace: "default"], query_params: [], verb: :list}
        ** (EXIT) exited in: GenServer.call(K8s.Client.DynamicHTTPProvider, {:locate, #PID<0.352.0>}, 5000)
            ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

from bonny.

kennethito avatar kennethito commented on August 16, 2024

mix test --no-start looks like it works. Is that the intended way to run the tests? --no-start refers to the application?

from bonny.

mruoss avatar mruoss commented on August 16, 2024

--no-start refers to the application?

Yes, it means don't start the appilcation. But it is actually documented.

Is that the intended way to run the tests?

It depends on how you want to test your operator. Do you want to implement and run only unit tests or do you want to test it agains a real kubernetes cluster (integration tests) as well?

Unit tests only

You have two options:

  • Use --no-start as described above
  • In your appilcation.ex you get the mix environment. For :dev don't add the operator to the supervision tree
defmodule YourOperator.Application do
  use Application

  def start(_type, env: env) do
    children =
      case env do
        :test -> []
        _ -> [{YourOperator.Operator, conn: YourOperator.K8sConn.get!(env), name: YourOperator.Operator}]
      end

    opts = [strategy: :one_for_one, name: YourOperator.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

With integration tests

This is advanced but if you want to run integration tests you're gonna have to create a local cluster (e.g. using k3d) and connect to that cluster. So you have to change YourOperator.K8sConn.get!(:test) to return a conn object to your local cluster. Make sure you generate the manifest and apply it to your cluster before you start the operator. This repository actually comes with integration tests. Use it to get inspired.

from bonny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.