-
Couldn't load subscription status.
- Fork 122
Add inactivity_timeout support to Fleet agent policy resource with duration string type and version validation #1285
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
Merged
+247
−37
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bdb81b4
Initial plan
Copilot f6f4a9b
Add inactivity_timeout support to Fleet agent policy resource
Copilot 6cf5c3c
Update changelog and generate documentation for inactivity_timeout fe…
Copilot 1be987c
Add version check for inactivity_timeout field in Fleet agent policy
Copilot a39c062
Add comprehensive tests for inactivity_timeout version validation
Copilot 5385514
Fix inactivity_timeout and supports_agentless field handling in Fleet…
Copilot 4020952
Convert inactivity_timeout to string duration type with seconds conve…
Copilot d448c54
Update documentation for inactivity_timeout duration string support
Copilot cd13249
Apply code review suggestions: improve duration conversion and simpli…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package agent_policy | ||
|
|
||
| import ( | ||
| "context" | ||
| "github.com/hashicorp/go-version" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestMinVersionInactivityTimeout(t *testing.T) { | ||
| // Test that the MinVersionInactivityTimeout constant is set correctly | ||
| expected := "8.7.0" | ||
| actual := MinVersionInactivityTimeout.String() | ||
| if actual != expected { | ||
| t.Errorf("Expected MinVersionInactivityTimeout to be '%s', got '%s'", expected, actual) | ||
| } | ||
|
|
||
| // Test version comparison - should be greater than 8.6.0 | ||
| olderVersion := version.Must(version.NewVersion("8.6.0")) | ||
| if MinVersionInactivityTimeout.LessThan(olderVersion) { | ||
| t.Errorf("MinVersionInactivityTimeout (%s) should be greater than %s", MinVersionInactivityTimeout.String(), olderVersion.String()) | ||
| } | ||
|
|
||
| // Test version comparison - should be less than 8.8.0 | ||
| newerVersion := version.Must(version.NewVersion("8.8.0")) | ||
| if MinVersionInactivityTimeout.GreaterThan(newerVersion) { | ||
| t.Errorf("MinVersionInactivityTimeout (%s) should be less than %s", MinVersionInactivityTimeout.String(), newerVersion.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestInactivityTimeoutVersionValidation(t *testing.T) { | ||
| ctx := context.Background() | ||
|
|
||
| // Test case where inactivity_timeout is not supported (older version) | ||
| model := &agentPolicyModel{ | ||
| Name: types.StringValue("test"), | ||
| Namespace: types.StringValue("default"), | ||
| InactivityTimeout: types.Float32Value(120.0), | ||
| } | ||
|
|
||
| // Create features with inactivity timeout NOT supported | ||
| feat := features{ | ||
| SupportsInactivityTimeout: false, | ||
| } | ||
|
|
||
| // Test toAPICreateModel - should return error when inactivity_timeout is used but not supported | ||
| _, diags := model.toAPICreateModel(ctx, feat) | ||
| if !diags.HasError() { | ||
| t.Error("Expected error when using inactivity_timeout on unsupported version, but got none") | ||
| } | ||
|
|
||
| // Check that the error message contains the expected text | ||
| found := false | ||
| for _, diag := range diags { | ||
| if diag.Summary() == "Unsupported Elasticsearch version" { | ||
| found = true | ||
| break | ||
| } | ||
| } | ||
| if !found { | ||
| t.Error("Expected 'Unsupported Elasticsearch version' error, but didn't find it") | ||
| } | ||
|
|
||
| // Test toAPIUpdateModel - should return error when inactivity_timeout is used but not supported | ||
| _, diags = model.toAPIUpdateModel(ctx, feat) | ||
| if !diags.HasError() { | ||
| t.Error("Expected error when using inactivity_timeout on unsupported version in update, but got none") | ||
| } | ||
|
|
||
| // Test case where inactivity_timeout IS supported (newer version) | ||
| featSupported := features{ | ||
| SupportsInactivityTimeout: true, | ||
| } | ||
|
|
||
| // Test toAPICreateModel - should NOT return error when inactivity_timeout is supported | ||
| _, diags = model.toAPICreateModel(ctx, featSupported) | ||
| if diags.HasError() { | ||
| t.Errorf("Did not expect error when using inactivity_timeout on supported version: %v", diags) | ||
| } | ||
|
|
||
| // Test toAPIUpdateModel - should NOT return error when inactivity_timeout is supported | ||
| _, diags = model.toAPIUpdateModel(ctx, featSupported) | ||
| if diags.HasError() { | ||
| t.Errorf("Did not expect error when using inactivity_timeout on supported version in update: %v", diags) | ||
| } | ||
|
|
||
| // Test case where inactivity_timeout is not set (should not cause validation errors) | ||
| modelWithoutTimeout := &agentPolicyModel{ | ||
| Name: types.StringValue("test"), | ||
| Namespace: types.StringValue("default"), | ||
| // InactivityTimeout is not set (null/unknown) | ||
| } | ||
|
|
||
| // Test toAPICreateModel - should NOT return error when inactivity_timeout is not set, even on unsupported version | ||
| _, diags = modelWithoutTimeout.toAPICreateModel(ctx, feat) | ||
| if diags.HasError() { | ||
| t.Errorf("Did not expect error when inactivity_timeout is not set: %v", diags) | ||
| } | ||
|
|
||
| // Test toAPIUpdateModel - should NOT return error when inactivity_timeout is not set, even on unsupported version | ||
| _, diags = modelWithoutTimeout.toAPIUpdateModel(ctx, feat) | ||
| if diags.HasError() { | ||
| t.Errorf("Did not expect error when inactivity_timeout is not set in update: %v", diags) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.