Skip to content

Refactor integration commands into package#21

Merged
rafusel merged 8 commits intomainfrom
refactors-integrations-into-package
Jun 23, 2021
Merged

Refactor integration commands into package#21
rafusel merged 8 commits intomainfrom
refactors-integrations-into-package

Conversation

@rafusel
Copy link
Copy Markdown
Contributor

@rafusel rafusel commented Jun 10, 2021

No description provided.

@rafusel rafusel changed the title Refactor complete, tests failing. Refactor integration commands into package Jun 10, 2021
Comment thread cmd/cmdutil/config.go Outdated
@rafusel rafusel marked this pull request as ready for review June 10, 2021 15:07
@rafusel rafusel force-pushed the refactors-integrations-into-package branch 2 times, most recently from 1030de7 to c7d356b Compare June 11, 2021 16:23
Copy link
Copy Markdown

@ChezCrawford ChezCrawford left a comment

Choose a reason for hiding this comment

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

In general this looks great. The tests are super nice. Left a few comments to have a look at...

Comment thread cmd/server.go
Comment thread cmd/status.go
Comment thread cmd/stop.go
Comment thread cmd/retry.go
Comment thread cmd/cmdutil/runCommand.go Outdated
return nil
}

func RunRetryCommand(config *Config, routingKey string) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure we need to share most of these...

Copy link
Copy Markdown
Contributor Author

@rafusel rafusel Jun 22, 2021

Choose a reason for hiding this comment

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

Good point, since this is basically all the same feedback I'll resolve the rest of these and put the commit here: 25853c8

Comment thread cmd/cmdutil/defaults.go
Comment thread cmd/integrations/nagios/nagios_enqueue.go Outdated

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
viper.SetDefault("address", cmdutil.GetDefaults().Address)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm interested in why this is required here. (I see that if we remove it, the tests don't work but i'd like to understand why.)

As I am looking at this, i'm wondering if we also might want to spend a little time refactoring cmdutil.Defaults and cmdutil.Config

Copy link
Copy Markdown
Contributor Author

@rafusel rafusel Jun 22, 2021

Choose a reason for hiding this comment

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

Yeah for sure I'm also confused why this is necessary here, and not in the cmd tests. I did spend an hour or so trying to figure this out, but I'll put some more time into this today to see if I can get a definitive answer because this obviously isn't ideal.

To comment on the second part, I'm not really sure what you mean about refactoring cmdutil.Defaults and cmdutil.Config, could you elaborate a bit on what you'd want the refactor to look like?

Copy link
Copy Markdown
Contributor Author

@rafusel rafusel Jun 22, 2021

Choose a reason for hiding this comment

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

Good news! I figured why address was not getting set in the nagios package tests. The cmd package has an init function that gets run whenever the package is used, so in cmd tests the viper stuff gets initialized but this won't happen in the tests for the integrations because they'll be in their own packages. I pushed a few commits trying some things but this is the final solution I ended on. Lmk what you think: 61699b2

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The solution you've put in place here is better.

As we discussed, we may want to do some further refactoring in the future to pull viper and its side-effects further to the edges of the application and have the inner layers access config through a config object.

rafusel and others added 7 commits June 23, 2021 00:24
This refactor should make adding new tests easier
and more closely follows established Go testing
patterns.
We now store the command's inputs in a new type,
and do a direct mapping from the new type to a
V2 event type. This should make the code more
readable.
@rafusel rafusel force-pushed the refactors-integrations-into-package branch from 82282cd to 2fbf2af Compare June 23, 2021 04:33
@rafusel rafusel force-pushed the refactors-integrations-into-package branch from 2fbf2af to 61699b2 Compare June 23, 2021 04:36
Copy link
Copy Markdown

@ChezCrawford ChezCrawford left a comment

Choose a reason for hiding this comment

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

Great work!

@rafusel rafusel merged commit eab7f52 into main Jun 23, 2021
@rafusel rafusel deleted the refactors-integrations-into-package branch June 23, 2021 21:13
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