-
Notifications
You must be signed in to change notification settings - Fork 105
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
[env] Do not share config between tests #396
Changes from all commits
b1923a4
0c0954e
64b5e51
8d60627
95976f7
56e4a65
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 |
---|---|---|
|
@@ -107,14 +107,15 @@ func (c *Config) WithClient(client klient.Client) *Config { | |
return c | ||
} | ||
|
||
// GetClient returns the client for the environment | ||
func (c *Config) GetClient() klient.Client { | ||
return c.client | ||
} | ||
|
||
// NewClient is a constructor function that returns a previously | ||
// created klient.Client or create a new one based on configuration | ||
// previously set. Will return an error if unable to do so. | ||
func (c *Config) NewClient() (klient.Client, error) { | ||
if c.client != nil { | ||
return c.client, nil | ||
} | ||
|
||
client, err := klient.NewWithKubeConfigFile(c.kubeconfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("envconfig: client failed: %w", err) | ||
|
@@ -130,16 +131,11 @@ func (c *Config) NewClient() (klient.Client, error) { | |
// are confident in the configuration or call NewClient() to ensure its | ||
// safe creation. | ||
func (c *Config) Client() klient.Client { | ||
if c.client != nil { | ||
return c.client | ||
} | ||
|
||
client, err := klient.NewWithKubeConfigFile(c.kubeconfig) | ||
client, err := c.NewClient() | ||
if err != nil { | ||
panic(fmt.Errorf("envconfig: client failed: %w", err).Error()) | ||
panic(err) | ||
} | ||
c.client = client | ||
return c.client | ||
return client | ||
} | ||
Comment on lines
133
to
139
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.
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. See #413 for an attempt at solving this 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. Do you have a real example of this being an issue? 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. It's just that this would be a behavior change, currently someone creating a config with an injected client would always get that same client when calling 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. ok, it makes sense then. If you can find a way to support this without overcomplicating thing, I'm all in. 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. See my draft PR, unfortunately I couldn't get the tests to run yet. |
||
|
||
// WithNamespace updates the environment namespace value | ||
|
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.
I know we do something similar for
deepCopyFeature
, but in that case it's kind of simpler and so the risk to forget to update it for new fields is lower, here I feel it would be higher, so would it make sense to either autogenerate or rely on reflect.DeepCopy directly? The performance hit would not be so relevant here probably.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.
I tried using
xreflect.DeepCopy
however it does not quite work:Config
isnil
withpanic: reflect: call of reflect.Value.Set on zero Value
panic: reflect.Set: value of type *syntax.Prog is not assignable to type *regexp.onePassProg
I didn't try to go deeper but I think a bunch of fixes would be needed in xreflect to be able to use it 😞
Concerning, if we can autogenerate it, I've not considered it. Mainly because I've no idea how to do it 😅
and I don't know if it would be able to do the deep copy on complex struct fields like the regex ones.
Still, if you think it would work, I can try. In that case, could you link some doc I can use to get started?
What do you think?