Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(laconia-config): register integer and float converters to EnvVarC… #638

Merged
merged 1 commit into from
Sep 1, 2020

Conversation

reestolonio
Copy link

  • Added IntegerConfigConverter and FloatConfigConverter in EnvVarConfigFactory

@hugosenari
Copy link
Contributor

@reestolonio to me is ok, thank you. 🎉

Inviting a more experienced dev (@geoffdutton) to review.

@geoffdutton
Copy link
Contributor

@reestolonio Nice catch! I think I'm the one that made the integer and float converters, so you fixed my bug--thanks ;)

The only thing I'd say is add a test that the function exports.envVarInstances returns an EnvVarConfigFactory with all of the converters.

Copy link
Contributor

@geoffdutton geoffdutton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test that expects the .converters prop has the keys ['boolean', 'integer', 'float', 'ssm', 's3', 'secretsManager']

@reestolonio
Copy link
Author

reestolonio commented Sep 1, 2020

Add test that expects the .converters prop has the keys ['boolean', 'integer', 'float', 'ssm', 's3', 'secretsManager']

Hi @geoffdutton , was checking way to test the .converters. Unfortunately, there is no way to test through index.spec.js. This test cannot access the instance of EnvVarConfigFactory, therefore, cannot assert .converters. Any suggestion?

Also, while this kind of test is good verify the current behavior, it does not verify if new converter is added to the config.

@geoffdutton
Copy link
Contributor

geoffdutton commented Sep 1, 2020

@reestolonio You are correct it doesn't verify when new converters are added. I view it as more of a preemptive regression test when refactoring.

Let me look through it a bit more.

In the meantime, is this something you'd like to see get released and deployed soon?

Edit: @hugosenari and @ceilfors I think it's fine to release as is

@geoffdutton geoffdutton self-requested a review September 1, 2020 04:45
Copy link
Contributor

@geoffdutton geoffdutton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we figure out a "sanity check" test at some point, but otherwise looks good to me.

@reestolonio
Copy link
Author

@geoffdutton , yeah if possible. I have a code in development waiting for this 😄 . But I respect your release schedule. I can use parseXXX for now.

@geoffdutton geoffdutton merged commit ac1a8d5 into nearst:master Sep 1, 2020
@geoffdutton
Copy link
Contributor

@reestolonio I believe @ceilfors is the one that has to publish to NPM.

@hugosenari
Copy link
Contributor

We could use it in Acceptance Tests, will not verify when new converters are added, but will check any changes that break 'contract' (API)

@hugosenari hugosenari linked an issue Sep 1, 2020 that may be closed by this pull request
@geoffdutton
Copy link
Contributor

Or can we define the type definition that requires all of the converters to instantiate an EnvVarConfigFactory object? I'm not too familiar with Typescript.

@reestolonio
Copy link
Author

reestolonio commented Sep 2, 2020

Validating the 'contract'-breaking changes can also be done at package-/unit- level. Sample unit test below would satisfy the requirement of @hugosenari in above comment

The idea is to test if all converters are loaded by default to the factory. Other tests in laconfig-config don't have this validation.

describe("@laconia/config", () => {
  describe("#envVarInstances", () => {
    it.only("resolves all config objects", async () => {
      const $ssm = // mock
      const $s3 = // mock
      const $secretsManager = // mock
      
      // !!! developer will be required to add entry here if new converter is added.
      const env = {
        LACONIA_CONFIG_TEST_BOOL: 'boolean:true',
        LACONIA_CONFIG_TEST_INTEGER: 'integer:1',
        LACONIA_CONFIG_TEST_SSM: 'ssm:/path/to/parameter',
        // add more variables here
      }
      const instances = await config.envVarInstances()({ env, $ssm, $s3, $secretsManager });
      expect(instances).toHaveProperty('testBool', true)
      expect(instances).toHaveProperty('testInteger', 1)
      // add more validations to all the objects created  by config
    })
  });
});

@reestolonio reestolonio deleted the issue-637 branch September 10, 2020 01:31
@ceilfors
Copy link
Collaborator

@all-contributors please add @reestolonio for code

@allcontributors
Copy link
Contributor

@ceilfors

I've put up a pull request to add @reestolonio! 🎉

@ceilfors
Copy link
Collaborator

Apologies for my slow reply, for some reason GitHub has no longer send a notification to my email! Still figuring out how to fix this

Thanks for the PR! I'm going to release this now!

@ceilfors
Copy link
Collaborator

Released at v1.10.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

integer and float configs are not passed in laconia context
5 participants