1 package v2
2
3 import (
4 "fmt"
5 "testing"
6
7 "github.com/stretchr/testify/require"
8
9 v1 "edge-infra.dev/pkg/sds/display/k8s/apis/v1"
10 )
11
12 var (
13 v1Primary = v1.Primary(true)
14 v1NotPrimary = v1.Primary(false)
15
16 v1EloTouchSolutionsUSB = v1.InputDeviceName("Elo Touch Solutions Elo Touch Solutions Pcap USB Interface")
17 v1EGalaxEXC3189 = v1.InputDeviceName("eGalax Inc. eGalaxTouch EXC3189-2506-09.00.00.00")
18 v1EGalaxEXC3189Mouse = v1.InputDeviceName("eGalax Inc. eGalaxTouch EXC3189-2506-09.00.00.00 Mouse")
19 )
20
21 func TestDisplayConfigFromV1(t *testing.T) {
22 tcs := []struct {
23 v1 *v1.DisplayConfig
24 displayConfig *DisplayConfig
25 expectedV2 *DisplayConfig
26 expectedDisconnectedIDs map[DisplayPort]MPID
27 }{
28 {
29
30
31 v1: &v1.DisplayConfig{},
32 displayConfig: &DisplayConfig{},
33 expectedV2: &DisplayConfig{},
34 expectedDisconnectedIDs: map[DisplayPort]MPID{},
35 },
36 {
37
38
39 v1: &v1.DisplayConfig{
40 Displays: v1.Displays{
41 "NCR-1234": v1.Display{
42 Orientation: &v1.NormalOrientation,
43 Resolution: &v1.Resolution{
44 Width: 1920,
45 Height: 1080,
46 },
47 Primary: &v1Primary,
48 InputDeviceMappings: []v1.InputDeviceName{
49 v1EloTouchSolutionsUSB,
50 },
51 },
52 "NCR-5678": v1.Display{
53 Orientation: &v1.InvertedOrientation,
54 Resolution: &v1.Resolution{
55 Width: 800,
56 Height: 600,
57 },
58 Primary: &v1NotPrimary,
59 InputDeviceMappings: []v1.InputDeviceName{
60 v1EGalaxEXC3189,
61 v1EGalaxEXC3189Mouse,
62 },
63 },
64 },
65 },
66 displayConfig: &DisplayConfig{
67 Displays: Displays{
68 {
69 DisplayPort: "card0-HDMI1",
70 MPID: &ncr1234,
71 Orientation: &NormalOrientation,
72 Resolution: &Resolution{
73 Width: 1260,
74 Height: 720,
75 },
76 Primary: ¬Primary,
77 },
78 {
79 DisplayPort: "card0-HDMI2",
80 MPID: &ncr5678,
81 Orientation: &NormalOrientation,
82 Resolution: &Resolution{
83 Width: 400,
84 Height: 300,
85 },
86 Primary: &primary,
87 },
88 },
89 },
90 expectedV2: &DisplayConfig{
91 Displays: Displays{
92 {
93 DisplayPort: "card0-HDMI1",
94 Orientation: &NormalOrientation,
95 Resolution: &Resolution{
96 Width: 1920,
97 Height: 1080,
98 },
99 Primary: &primary,
100 InputDeviceMappings: []InputDeviceName{
101 eloTouchSolutionsUSB,
102 },
103 },
104 {
105 DisplayPort: "card0-HDMI2",
106 Orientation: &InvertedOrientation,
107 Resolution: &Resolution{
108 Width: 800,
109 Height: 600,
110 },
111 Primary: ¬Primary,
112 InputDeviceMappings: []InputDeviceName{
113 eGalaxEXC3189,
114 eGalaxEXC3189Mouse,
115 },
116 },
117 },
118 },
119 expectedDisconnectedIDs: map[DisplayPort]MPID{},
120 },
121 {
122
123
124 v1: &v1.DisplayConfig{
125 Displays: v1.Displays{
126 "ARC-2332": v1.Display{
127 Primary: &v1Primary,
128 },
129 "NCR-1234": v1.Display{
130 Resolution: &v1.Resolution{
131 Width: 1920,
132 Height: 1080,
133 },
134 },
135 "NCR-5678": v1.Display{
136 Orientation: &v1.InvertedOrientation,
137 InputDeviceMappings: []v1.InputDeviceName{
138 v1EGalaxEXC3189,
139 v1EGalaxEXC3189Mouse,
140 },
141 },
142 },
143 },
144 displayConfig: &DisplayConfig{
145 Displays: Displays{
146 {
147 DisplayPort: "card0-HDMI1",
148 MPID: &ncr1234,
149 Orientation: &NormalOrientation,
150 Resolution: &Resolution{
151 Width: 1260,
152 Height: 720,
153 },
154 Primary: &primary,
155 },
156 },
157 },
158 expectedV2: &DisplayConfig{
159 Displays: Displays{
160 {
161 DisplayPort: "unknown-disconnected-1",
162 Primary: &primary,
163 },
164 {
165 DisplayPort: "card0-HDMI1",
166 Resolution: &Resolution{
167 Width: 1920,
168 Height: 1080,
169 },
170 },
171 {
172 DisplayPort: "unknown-disconnected-2",
173 Orientation: &InvertedOrientation,
174 InputDeviceMappings: []InputDeviceName{
175 eGalaxEXC3189,
176 eGalaxEXC3189Mouse,
177 },
178 },
179 },
180 },
181 expectedDisconnectedIDs: map[DisplayPort]MPID{
182 "unknown-disconnected-1": "ARC-2332",
183 "unknown-disconnected-2": "NCR-5678",
184 },
185 },
186 }
187 for idx, tc := range tcs {
188 v2, disconnectedIDs := DisplayConfigFromV1(tc.v1, tc.displayConfig)
189 require.Equal(t, tc.expectedV2, v2, fmt.Sprintf("test case %d failed", idx+1))
190 require.Equal(t, tc.expectedDisconnectedIDs, disconnectedIDs, fmt.Sprintf("test case %d failed", idx+1))
191 }
192 }
193
View as plain text