| 1 | package plugin |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestCapabilityViewsWithoutServers(t *testing.T) { |
| 9 | for _, profile := range []HostProfile{HostProfileCore, HostProfileInteractive, HostProfileDesktopApps} { |
| 10 | t.Run(profile.String(), func(t *testing.T) { |
| 11 | h := NewHostWithProfile(profile) |
| 12 | views := h.CapabilityViews() |
| 13 | if len(views) != 4 { |
| 14 | t.Fatalf("views = %d, want 4", len(views)) |
| 15 | } |
| 16 | wantIDs := []string{"protocol", "core", "interactive", "apps"} |
| 17 | for i, id := range wantIDs { |
| 18 | if views[i].ID != id { |
| 19 | t.Fatalf("view[%d].ID = %q, want %q", i, views[i].ID, id) |
| 20 | } |
| 21 | } |
| 22 | wantInteractive := CapabilityStateUnavailable |
| 23 | if profile.Capabilities().ElicitationForms { |
| 24 | wantInteractive = CapabilityStateSupported |
| 25 | } |
| 26 | if views[2].State != wantInteractive { |
| 27 | t.Fatalf("interactive state = %q, want %q", views[2].State, wantInteractive) |
| 28 | } |
| 29 | wantApps := CapabilityStateUnavailable |
| 30 | if profile.Capabilities().AppsUI { |
| 31 | wantApps = CapabilityStateSupported |
| 32 | } |
| 33 | if views[3].State != wantApps { |
| 34 | t.Fatalf("apps state = %q, want %q", views[3].State, wantApps) |
| 35 | } |
| 36 | for _, v := range views { |
| 37 | if v.State == CapabilityStateNegotiated { |
| 38 | t.Fatalf("layer %s negotiated with zero servers", v.ID) |
| 39 | } |
| 40 | if v.Detail == "" { |
| 41 | t.Fatalf("layer %s has empty detail", v.ID) |
| 42 | } |
| 43 | } |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func TestCapabilityViewsLayersAndFormat(t *testing.T) { |
| 49 | h := NewHostWithProfile(HostProfileDesktopApps) |
| 50 | views := h.CapabilityViews() |
| 51 | wantLayers := []string{LayerProtocol, LayerCore, LayerInteractive, LayerApps} |
| 52 | for i, want := range wantLayers { |
| 53 | if views[i].Layer != want { |
| 54 | t.Fatalf("view[%d].Layer = %q, want %q", i, views[i].Layer, want) |
| 55 | } |
| 56 | } |
| 57 | formatted := FormatCapabilityViews(views) |
| 58 | for _, want := range wantLayers { |
| 59 | if !strings.Contains(formatted, want) { |
| 60 | t.Fatalf("formatted matrix missing layer %q:\n%s", want, formatted) |
| 61 | } |
| 62 | } |
| 63 | SortCapabilityViews(views) |
| 64 | for i, id := range []string{"protocol", "core", "interactive", "apps"} { |
| 65 | if views[i].ID != id { |
| 66 | t.Fatalf("unsorted after SortCapabilityViews: %v", views) |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | func TestServerStatusCarriesProfile(t *testing.T) { |
| 72 | h := NewHostWithProfile(HostProfileInteractive) |
| 73 | if got := h.Profile(); got != HostProfileInteractive { |
| 74 | t.Fatalf("profile = %q", got) |
| 75 | } |
| 76 | for _, s := range h.Servers() { |
| 77 | if s.HostProfile != HostProfileInteractive.String() { |
| 78 | t.Fatalf("server status profile = %q", s.HostProfile) |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func TestProfileNormalizeMapsUnknownToCore(t *testing.T) { |
| 84 | if got := HostProfile("future-v9").Normalize(); got != HostProfileCore { |
| 85 | t.Fatalf("unknown profile normalized to %q", got) |
| 86 | } |
| 87 | if got := HostProfile("").UsesEnhancedCache(); got { |
| 88 | t.Fatal("empty profile must not use the enhanced cache") |
| 89 | } |
| 90 | } |
| 91 |