-
-
Notifications
You must be signed in to change notification settings - Fork 27
fix(explorer): clear quick filter when goto jumps between resource types #541
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
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package app | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/janosmiko/lfk/internal/k8s" | ||
| "github.com/janosmiko/lfk/internal/model" | ||
| "github.com/janosmiko/lfk/internal/security" | ||
| ) | ||
|
|
||
| // These tests pin TASK-839's rule across every path that lands the user on a | ||
| // different resource list: the committed quick filter of the origin list must | ||
| // never leak into the destination. | ||
|
|
||
| // Regular navigation: jobs (filtered) -> h to types -> descend into deployments. | ||
| func TestNavigateChild_TypeSwitchClearsFilter(t *testing.T) { | ||
| m := gotoTestModel() | ||
| m.discoveredResources["ctx"] = append(m.discoveredResources["ctx"], | ||
| model.ResourceTypeEntry{Kind: "Job", APIGroup: "batch", APIVersion: "v1", Resource: "jobs", Namespaced: true}) | ||
| typesItems := model.BuildSidebarItems(m.discoveredResources["ctx"]) | ||
| m.setMiddleItems(typesItems) | ||
| m.pushLeft() | ||
| m.nav.Level = model.LevelResources | ||
| m.nav.ResourceType = model.ResourceTypeEntry{Kind: "Job", APIGroup: "batch", APIVersion: "v1", Resource: "jobs", Namespaced: true} | ||
| m.filterText = "my-job" | ||
| m.filterInput.Set("my-job") | ||
|
|
||
| out, _ := m.navigateParent() | ||
| m = out.(Model) | ||
| if m.filterText != "" { | ||
| t.Fatalf("after back-nav to types, filterText=%q", m.filterText) | ||
| } | ||
|
|
||
| dep := model.ResourceTypeEntry{Kind: "Deployment", APIGroup: "apps", APIVersion: "v1", Resource: "deployments", Namespaced: true} | ||
| for i, item := range m.visibleMiddleItems() { | ||
| if item.Extra == dep.ResourceRef() { | ||
| m.setCursor(i) | ||
| break | ||
| } | ||
| } | ||
| out, _ = m.navigateChild() | ||
| m = out.(Model) | ||
| if m.filterText != "" || m.filterInput.Value != "" { | ||
| t.Fatalf("regular navigation leaked the filter: filterText=%q input=%q", m.filterText, m.filterInput.Value) | ||
| } | ||
| } | ||
|
|
||
| // Security-finding teleport: Enter on an affected resource must not carry the | ||
| // finding view's filter into the real resource list. | ||
| func TestJumpToFindingResource_ClearsQuickFilter(t *testing.T) { | ||
| m := baseModelBoost2() | ||
| m.discoveredResources["test-ctx"] = []model.ResourceTypeEntry{ | ||
| {Kind: "Deployment", APIGroup: "apps", APIVersion: "v1", Resource: "deployments", Namespaced: true}, | ||
| } | ||
| m.nav.Level = model.LevelOwned | ||
| m.nav.ResourceType = model.ResourceTypeEntry{Kind: "__security_falco__", APIGroup: "_security"} | ||
| m.nav.ResourceName = "privileged" | ||
| m.securityActiveGroup = "privileged" | ||
| m.filterText = "api" | ||
| m.filterInput.Set("api") | ||
| sel := &model.Item{ | ||
| Kind: "__security_affected_resource__", | ||
| Name: "deploy/api", | ||
| Namespace: "prod", | ||
| Columns: []model.KeyValue{ | ||
| {Key: "__resource_key__", Value: "prod/Deployment/api"}, | ||
| }, | ||
| } | ||
| m.middleItems = []model.Item{*sel} | ||
| m.setCursor(0) | ||
|
|
||
| out, _ := m.jumpToFindingResource(sel) | ||
| rm := out.(Model) | ||
| if rm.nav.Level != model.LevelResources { | ||
| t.Fatalf("expected teleport to LevelResources, got %v", rm.nav.Level) | ||
| } | ||
| if rm.filterText != "" || rm.filterInput.Value != "" { | ||
| t.Fatalf("finding teleport leaked the filter: filterText=%q input=%q", rm.filterText, rm.filterInput.Value) | ||
| } | ||
| } | ||
|
|
||
| // Security-findings teleport: opening a resource's findings pseudo-list must | ||
| // not keep the origin list's filter or preset state. | ||
| func TestOpenSecurityFindingsForResource_ClearsQuickFilter(t *testing.T) { | ||
| m := baseModelBoost2() | ||
| m.nav.Level = model.LevelResources | ||
| m.nav.ResourceType = model.ResourceTypeEntry{Kind: "Pod", APIVersion: "v1", Resource: "pods", Namespaced: true} | ||
| m.filterText = "nginx" | ||
| m.filterInput.Set("nginx") | ||
| m.filterBroadMode = true | ||
| m.activeFilterPreset = &FilterPreset{Name: "p"} | ||
| m.unfilteredMiddleItems = []model.Item{{Name: "pod-a"}} | ||
|
|
||
| rm, _ := m.openSecurityFindingsForResource( | ||
| []security.ResourceRef{{Namespace: "prod", Kind: "Pod", Name: "api"}}, "Pod", "api") | ||
| if rm.nav.ResourceType.Kind != model.SecurityResourceFindingsKind { | ||
| t.Fatalf("expected findings pseudo type, got %q", rm.nav.ResourceType.Kind) | ||
| } | ||
| if rm.filterText != "" || rm.filterInput.Value != "" || rm.filterActive || rm.filterBroadMode { | ||
| t.Fatalf("findings teleport leaked filter state: text=%q input=%q active=%v broad=%v", | ||
| rm.filterText, rm.filterInput.Value, rm.filterActive, rm.filterBroadMode) | ||
| } | ||
| if rm.activeFilterPreset != nil || rm.unfilteredMiddleItems != nil { | ||
| t.Fatal("findings teleport must clear filter preset state") | ||
| } | ||
| } | ||
|
|
||
| // Port-forwards teleport: opening the Port Forwards pseudo-list must not keep | ||
| // the origin list's filter (it would hide the forwards). | ||
| func TestNavigateToPortForwards_ClearsQuickFilter(t *testing.T) { | ||
| m := baseModelWithFakeClient() | ||
| m.portForwardMgr = k8s.NewPortForwardManager() | ||
| m.nav.Level = model.LevelResources | ||
| m.nav.ResourceType = model.ResourceTypeEntry{Kind: "Pod", APIVersion: "v1", Resource: "pods", Namespaced: true} | ||
| m.filterText = "nginx" | ||
| m.filterInput.Set("nginx") | ||
|
|
||
| m.navigateToPortForwards() | ||
| if m.nav.ResourceType.Kind != "__port_forwards__" { | ||
| t.Fatalf("expected port-forwards pseudo type, got %q", m.nav.ResourceType.Kind) | ||
| } | ||
| if m.filterText != "" || m.filterInput.Value != "" { | ||
| t.Fatalf("port-forwards teleport leaked the filter: filterText=%q input=%q", m.filterText, m.filterInput.Value) | ||
| } | ||
| } |
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
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.