Giter Site home page Giter Site logo

`default_test` option about mahaul HOT 8 CLOSED

mgibowski avatar mgibowski commented on July 21, 2024
`default_test` option

from mahaul.

Comments (8)

mgibowski avatar mgibowski commented on July 21, 2024 1

thanks @emadalam just tried the feature branch, and it works great for me!

from mahaul.

emadalam avatar emadalam commented on July 21, 2024 1

@mgibowski For consistency reasons, the parsing of values to correct data types happen only from string values like how you set in the actual environment variables. So the correct way to set any defaults is to set the string values exactly like how you would do while setting the environment variables. So in your example you should do,

  use Mahaul,
    REDPANDA_NUM_PARTITIONS: [
      type: :int,
      defaults: [dev: "1"]
    ]

Regardless of the type, you always should set string values for defaults, I have it in the documentation, but maybe I'd need to reemphasize that and improve documentation. Also I could improve this through a compile time validation in future.

from mahaul.

mgibowski avatar mgibowski commented on July 21, 2024 1

Alright, makes sense - thanks!

from mahaul.

emadalam avatar emadalam commented on July 21, 2024

@mgibowski Thanks for trying it out and giving the feedback 🙌

Currently the default_dev works for both :dev and :test mix environments. The name might have been a little confusing but the idea was to have a default that can work for local development (that includes both :dev and :test).

Having said that, I'm still contemplating what could be the best way to allow setting mix environment specific defaults since mix environments can be any number of custom values. I'm thinking of introducing a unified defaults keyword list option to allow this flexibility. Any other suggestions are more than welcome.

from mahaul.

mgibowski avatar mgibowski commented on July 21, 2024

In my case, I just need a different default value for test, different for dev, and no default for prod (always set from env variable).

defaults: [dev: “a”, test: “b”]would be fine for my use case.

from mahaul.

emadalam avatar emadalam commented on July 21, 2024

@mgibowski I have added the configuration option defaults as part of a new feature branch. Have a look at this PR #5 and see if it serves the purpose. I'd make a release tomorrow if you don't have any further comments to the approach.

Side note: I have also soft deprecated the default_dev option with warnings to prefer using the new defaults option.

from mahaul.

mgibowski avatar mgibowski commented on July 21, 2024

@emadalam I was a bit too quick.

Something doesn't work.

Here is the code fragment:

  use Mahaul,
    REDPANDA_NUM_PARTITIONS: [type: :int, defaults: [dev: 1]]

When I invoke MyApp.Env.redpanda_num_partitions()

I get the error:

** (FunctionClauseError) no function clause matching in Integer.parse/2    
    
    The following arguments were given to Integer.parse/2:
    
        # 1
        1
    
        # 2
        10
    
    Attempted function clauses (showing 2 out of 2):
    
        def parse(_binary, base) when not (is_integer(base) and (base >= 2 and base <= 36))
        def parse(binary, base) when is_binary(binary)
    
    (elixir 1.14.3) lib/integer.ex:275: Integer.parse/2
    (mahaul 0.4.0) lib/mahaul/helpers.ex:226: Mahaul.Helpers.parse/2

Is it a bug in mahaul, or did I make some mistake?

from mahaul.

emadalam avatar emadalam commented on July 21, 2024

Also I could improve this through a compile time validation in future.

@mgibowski In retrospect, this should have been implemented with the new defaults option, as we already had compile time checks for invalid default and default_dev options.

Nonetheless I have added those compile time checks in v0.4.1 🙌

Screenshot 2023-03-07 at 16 40 19

Screenshot 2023-03-07 at 16 39 58

from mahaul.

Related Issues (5)

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.