-
Couldn't load subscription status.
- Fork 6
Add menu validate command to validate the format of menu files.
#363
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add `menu validate` command to validate the format of menu files. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from ..yaml import InfrahubFile, InfrahubFileKind | ||
| from .object import InfrahubObjectFileData | ||
| from .object import InfrahubObjectFileData, ObjectFile | ||
|
|
||
|
|
||
| class InfrahubMenuFileData(InfrahubObjectFileData): | ||
|
|
@@ -18,7 +18,7 @@ def enrich_node(cls, data: dict, context: dict) -> dict: | |
| return data | ||
|
|
||
|
|
||
| class MenuFile(InfrahubFile): | ||
| class MenuFile(ObjectFile): | ||
| _spec: InfrahubMenuFileData | None = None | ||
|
|
||
| @property | ||
|
|
@@ -28,7 +28,7 @@ def spec(self) -> InfrahubMenuFileData: | |
| return self._spec | ||
|
|
||
| def validate_content(self) -> None: | ||
| super().validate_content() | ||
| InfrahubFile.validate_content(self) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we making this change? Swapping from inheriting from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree this isn't ideal, and it calls for a larger redesign / cleaned of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if self.kind != InfrahubFileKind.MENU: | ||
| raise ValueError("File is not an Infrahub Menu file") | ||
| self._spec = InfrahubMenuFileData(**self.data.spec) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| apiVersion: infrahub.app/v1 | ||
| kind: Menu | ||
| spec: | ||
| data: | ||
| - nampace: Testing | ||
| name: Animal | ||
| label: Animals | ||
| kind: TestingAnimal | ||
| children: | ||
| data: | ||
| - namespace: Testing | ||
| name: Dog | ||
| label: Dog | ||
| kind: TestingDog | ||
|
|
||
| - namespace: Testing | ||
| name: Cat | ||
| label: Cat | ||
| kind: TestingCat |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| apiVersion: infrahub.app/v1 | ||
| kind: Menu | ||
| spec: | ||
| - namespace: Testing | ||
| - not valid | ||
| name: Animal | ||
| label: Animals | ||
| kind: TestingAnimal | ||
| children: | ||
| data: | ||
| - namespace: Testing | ||
| name: Dog | ||
| label: Dog | ||
| kind: TestingDog | ||
|
|
||
| - namespace: Testing | ||
| name: Cat | ||
| label: Cat | ||
| kind: TestingCat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice with a unit test even if it's just for the failure scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I added some unit tests