|
| 1 | +package installer |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/openbootdotdev/openboot/internal/config" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestFindMatchingPackages(t *testing.T) { |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + selectedPkgs map[string]bool |
| 14 | + onlinePkgs []config.Package |
| 15 | + triggerPkgs []string |
| 16 | + wantCount int |
| 17 | + wantContains []string |
| 18 | + }{ |
| 19 | + { |
| 20 | + name: "zoom installed matches trigger", |
| 21 | + selectedPkgs: map[string]bool{"zoom": true, "git": true, "curl": true}, |
| 22 | + triggerPkgs: []string{"zoom", "microsoft-teams", "obs", "loom", "feishu", "lark"}, |
| 23 | + wantCount: 1, |
| 24 | + wantContains: []string{"zoom"}, |
| 25 | + }, |
| 26 | + { |
| 27 | + name: "multiple matches", |
| 28 | + selectedPkgs: map[string]bool{"zoom": true, "obs": true, "git": true}, |
| 29 | + triggerPkgs: []string{"zoom", "microsoft-teams", "obs", "loom", "feishu", "lark"}, |
| 30 | + wantCount: 2, |
| 31 | + wantContains: []string{"zoom", "obs"}, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "no matches - only non-trigger packages", |
| 35 | + selectedPkgs: map[string]bool{"git": true, "curl": true, "google-chrome": true}, |
| 36 | + triggerPkgs: []string{"zoom", "microsoft-teams", "obs", "loom", "feishu", "lark"}, |
| 37 | + wantCount: 0, |
| 38 | + }, |
| 39 | + { |
| 40 | + name: "empty selected packages", |
| 41 | + selectedPkgs: map[string]bool{}, |
| 42 | + triggerPkgs: []string{"zoom", "microsoft-teams"}, |
| 43 | + wantCount: 0, |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "empty trigger list", |
| 47 | + selectedPkgs: map[string]bool{"zoom": true}, |
| 48 | + triggerPkgs: []string{}, |
| 49 | + wantCount: 0, |
| 50 | + }, |
| 51 | + { |
| 52 | + name: "nil selected packages", |
| 53 | + selectedPkgs: nil, |
| 54 | + triggerPkgs: []string{"zoom"}, |
| 55 | + wantCount: 0, |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "feishu matches", |
| 59 | + selectedPkgs: map[string]bool{"feishu": true}, |
| 60 | + triggerPkgs: []string{"zoom", "microsoft-teams", "obs", "loom", "feishu", "lark"}, |
| 61 | + wantCount: 1, |
| 62 | + wantContains: []string{"feishu"}, |
| 63 | + }, |
| 64 | + { |
| 65 | + name: "lark matches", |
| 66 | + selectedPkgs: map[string]bool{"lark": true, "node": true}, |
| 67 | + triggerPkgs: []string{"zoom", "microsoft-teams", "obs", "loom", "feishu", "lark"}, |
| 68 | + wantCount: 1, |
| 69 | + wantContains: []string{"lark"}, |
| 70 | + }, |
| 71 | + { |
| 72 | + name: "online packages match", |
| 73 | + selectedPkgs: map[string]bool{"git": true}, |
| 74 | + onlinePkgs: []config.Package{{Name: "zoom", IsCask: true}}, |
| 75 | + triggerPkgs: []string{"zoom", "microsoft-teams"}, |
| 76 | + wantCount: 1, |
| 77 | + wantContains: []string{"zoom"}, |
| 78 | + }, |
| 79 | + { |
| 80 | + name: "both selected and online match", |
| 81 | + selectedPkgs: map[string]bool{"zoom": true}, |
| 82 | + onlinePkgs: []config.Package{{Name: "loom", IsCask: true}}, |
| 83 | + triggerPkgs: []string{"zoom", "loom"}, |
| 84 | + wantCount: 2, |
| 85 | + wantContains: []string{"zoom", "loom"}, |
| 86 | + }, |
| 87 | + } |
| 88 | + |
| 89 | + for _, tt := range tests { |
| 90 | + t.Run(tt.name, func(t *testing.T) { |
| 91 | + cfg := &config.Config{ |
| 92 | + SelectedPkgs: tt.selectedPkgs, |
| 93 | + OnlinePkgs: tt.onlinePkgs, |
| 94 | + } |
| 95 | + result := findMatchingPackages(cfg, tt.triggerPkgs) |
| 96 | + assert.Len(t, result, tt.wantCount) |
| 97 | + for _, want := range tt.wantContains { |
| 98 | + assert.Contains(t, result, want) |
| 99 | + } |
| 100 | + }) |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +func TestGetScreenRecordingPackages(t *testing.T) { |
| 105 | + pkgs := config.GetScreenRecordingPackages() |
| 106 | + assert.NotEmpty(t, pkgs) |
| 107 | + assert.Contains(t, pkgs, "zoom") |
| 108 | + assert.Contains(t, pkgs, "microsoft-teams") |
| 109 | + assert.Contains(t, pkgs, "obs") |
| 110 | + assert.Contains(t, pkgs, "loom") |
| 111 | + assert.Contains(t, pkgs, "feishu") |
| 112 | + assert.Contains(t, pkgs, "lark") |
| 113 | + // Verify excluded packages are NOT in the list |
| 114 | + assert.NotContains(t, pkgs, "google-chrome") |
| 115 | + assert.NotContains(t, pkgs, "slack") |
| 116 | + assert.NotContains(t, pkgs, "discord") |
| 117 | +} |
0 commit comments