Skip to content

add mockability, make tests work #111

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

Closed
wants to merge 4 commits into from

Conversation

obs-gh-mattcotter
Copy link
Collaborator

No description provided.

@obs-gh-mattcotter
Copy link
Collaborator Author

@obs-gh-alexlew I made a few changes so the tests pass, let me know what you think! If it looks good, I can rebase all of your changes off of main and add this to your original PR

paths := make([]string, 0)
for _, field := range c.ConfigFields {
val := rawConnConfig.GetBool(field.configYAMLPath)
if val && field.colConfigFilePath != "" {
configPath, _ := c.RenderConfigTemplate(ctx, tmpDir, field.colConfigFilePath, confValues)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we fail to render a fragment, should we still start the agent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question; I think it's better to exit. I'll change this

}

func (c *ConnectionType) GetConfigFilePaths(ctx context.Context, tmpDir string) []string {
var rawConnConfig = viper.Sub(c.Name)
var rawConnConfig = c.getConfig()
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we pass the whole config into each fragment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is still just the sub config by default, but having a dynamic function to retrieve it allows for mocks in the test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah i see, you've moved the function onto the struct

}
configFilePaths, overridePath, err := config.GetAllOtelConfigFilePaths(ctx, tmpDir)
if err != nil {
os.RemoveAll(tmpDir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why don't we just call cleanup here? we've already created the override file right?

return c
}

func WithConfigFolderPath(configFolderPath string) ConnectionTypeOption {
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these just test helper functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this was recommended to me as a way to allow tests to override the defaults.

suite.Run(t, new(ConnectionsTestSuite))
}

func (suite *ConnectionsTestSuite) TestConnections_RenderConfigTemplate() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

would be good to check that variable types beyond string get rendered correctly, i.e. arrays or even nested structs

@obs-gh-alexlew
Copy link
Collaborator

looks great! nice job

@obs-gh-mattcotter
Copy link
Collaborator Author

Thanks for the review! The rebase was pretty ugly, so I'm going to close this one and #100 in favor of the new PR: #114

@obs-gh-mattcotter obs-gh-mattcotter deleted the mattc/conf-templates branch October 25, 2024 22:20
obs-gh-mattcotter added a commit that referenced this pull request Oct 28, 2024
### Description

OB-37310 Process all config fragments as golang templates

Replaces #100 and #111

### Checklist
- [x] Created tests which fail without the change (if possible)
- [ ] Extended the README / documentation, if necessary

Co-authored-by: Alex Lew <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants