Skip to content

Intrinsic function short form usage in integration test fixtures causes fixture loading to fail #8627

Closed

Description

@fredericbarthelet

When writing an integration test for the framework, using any intrinsic function short syntax - i.e. !GetAtt instead of Fn::GetAtt - causes fixtures.setup to return null without triggering an error. This is quite confusing as short syntax is perfectly fine for deploying the same service in the context of an actual project.

In the exemple of test/fixtures/httpApiExport/serverless.yml, using Ref: HttpApi works perfectly fine

However, replacing this with short syntax (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html#ref-declaration) !Ref HttpApi will cause fixture setup to fail.

⚠️⚠️ REPLACE WITH FULL COMMAND NAME output
AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npx mocha test/integration/httpApi.test.js

Installed version

Framework Core: 2.15.0
Plugin: 4.2.0
SDK: 2.3.2
Components: 3.4.3

IMHO, the issue comes from @serverless/test package get-fixtures-engine.js file code block bellow :

try {
  return loadYaml(configContent);
} catch (error) {
  return null;
}

Activity

  1. medikoo commented on Dec 15, 2020

    @medikoo
    Contributor

    When writing an integration test for the framework, using any intrinsic function short syntax - i.e. !GetAtt instead of Fn::GetAtt - causes fixtures.setup to return null without triggering an error.

    This should be picked by runServerless with config validation, and run should fail with meaningful error. Wasn't that the case?

  2. medikoo commented on Dec 15, 2020

    @medikoo
    Contributor

    Additionally we accept JSON as config extension, and short syntax is specific to YAML, so I don't think this really apply here.

  3. fredericbarthelet commented on Dec 15, 2020

    @fredericbarthelet
    ContributorAuthor

    @medikoo, sorry, I was not precise enough.

    The failing line in my exemple command AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npx mocha test/integration/httpApi.test.js is

    const exportServiceData = await fixtures.setup('httpApiExport');

    This shorthand syntax is not part of the config extension, but is part of the serverless.yml file within the httpApiExport test fixture. If you go in this fixture directory - test/fixtures/httpApiExport - and run the sls deploy command with the short syntax in the serverless.yml, everything is fine. If you run a test with this service file, it silently crashes since fixtures.setup returns null

    Do you see what I mean ?

  4. medikoo commented on Dec 16, 2020

    @medikoo
    Contributor

    @fredericbarthelet I see, the problem is at part in which fixture engine tries to assign a generated service name to the config. It parses the config and crashes.

    While just for fixture setup purpose I would argue, that we can simply not use shorthand syntax. Still I think it's valuable to have support for that, for the sake of testing that short syntax works as expected.

    I believe it can be fixed by:

    1. Moving lib/plugins/aws/lib/clouformationSchema.js to @serverless/utils package
    2. Parse config with schema option in fixture setup in @servelress/test/get-fixtures-engine

    PR's in all those projects are welcome!

  5. fredericbarthelet commented on Jan 7, 2021

    @fredericbarthelet
    ContributorAuthor

    @medikoo I just realized the issue is actually not resolved until a new version of @serverless/test is released with the latest commit updating utils version (https://github.com/serverless/test/commit/85aad008fd5deaa389200bd0cd4b2cea90ebdec0).

    Could you release a new version of this package and I'll produce a PR on serverless/serverless to update the @serverlerss/test version ?

  6. medikoo commented on Jan 8, 2021

    @medikoo
    Contributor

    Could you release a new version of this package and I'll produce a PR on serverless/serverless to update the @serverlerss/test version ?

    Sure, it's released now. Still there's no need to bump version in serverless, as CI automatically is run against latest version of dependencies and we always bump dependencies prior releasing new version (so it's guaranteed to happen then)

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions