@@ -63,129 +63,6 @@ func TestNewPropolisProvider(t *testing.T) {
6363 })
6464}
6565
66- // TestBuildBackendOpts verifies the merging logic in buildBackendOpts.
67- // Since libkrun.Option is an opaque func type, we assert on option count
68- // to verify which branches were taken. Each configuration produces a
69- // unique count.
70- func TestBuildBackendOpts (t * testing.T ) {
71- t .Parallel ()
72-
73- rtSrc := extract .Dir (t .TempDir ())
74- fwSrc := extract .Dir (t .TempDir ())
75- altSrc := extract .Dir (t .TempDir ())
76-
77- tests := []struct {
78- name string
79- provider * PropolisProvider
80- opts CreateVMOpts
81- wantCount int
82- }{
83- {
84- name : "no sources no paths" ,
85- provider : NewPropolisProvider (),
86- opts : CreateVMOpts {DataDir : "/tmp" },
87- wantCount : 0 ,
88- },
89- {
90- name : "runner path only" ,
91- provider : NewPropolisProvider (),
92- opts : CreateVMOpts {
93- RunnerPath : "/usr/bin/propolis-runner" ,
94- DataDir : "/tmp" ,
95- },
96- wantCount : 1 ,
97- },
98- {
99- name : "runner path and lib dir" ,
100- provider : NewPropolisProvider (),
101- opts : CreateVMOpts {
102- RunnerPath : "/usr/bin/propolis-runner" ,
103- LibDir : "/usr/lib" ,
104- DataDir : "/tmp" ,
105- },
106- wantCount : 2 ,
107- },
108- {
109- name : "provider runtime source only" ,
110- provider : NewPropolisProvider (WithRuntimeSource (rtSrc )),
111- opts : CreateVMOpts {DataDir : "/tmp" },
112- // WithRuntime + WithCacheDir = 2
113- wantCount : 2 ,
114- },
115- {
116- name : "provider firmware source only" ,
117- provider : NewPropolisProvider (WithFirmwareSource (fwSrc )),
118- opts : CreateVMOpts {DataDir : "/tmp" },
119- // WithFirmware + WithCacheDir = 2
120- wantCount : 2 ,
121- },
122- {
123- name : "provider both sources" ,
124- provider : NewPropolisProvider (
125- WithRuntimeSource (rtSrc ),
126- WithFirmwareSource (fwSrc ),
127- ),
128- opts : CreateVMOpts {DataDir : "/tmp" },
129- // WithRuntime + WithFirmware + WithCacheDir = 3
130- wantCount : 3 ,
131- },
132- {
133- name : "runtime source suppresses runner path and lib dir" ,
134- provider : NewPropolisProvider (WithRuntimeSource (rtSrc )),
135- opts : CreateVMOpts {
136- RunnerPath : "/usr/bin/propolis-runner" ,
137- LibDir : "/usr/lib" ,
138- DataDir : "/tmp" ,
139- },
140- // WithRuntime + WithCacheDir = 2 (RunnerPath/LibDir ignored)
141- wantCount : 2 ,
142- },
143- {
144- name : "per-call runtime source overrides provider" ,
145- provider : NewPropolisProvider (WithRuntimeSource (rtSrc )),
146- opts : CreateVMOpts {
147- RuntimeSource : altSrc ,
148- DataDir : "/tmp" ,
149- },
150- // WithRuntime(altSrc) + WithCacheDir = 2
151- wantCount : 2 ,
152- },
153- {
154- name : "per-call firmware source overrides provider" ,
155- provider : NewPropolisProvider (WithFirmwareSource (fwSrc )),
156- opts : CreateVMOpts {
157- FirmwareSource : altSrc ,
158- DataDir : "/tmp" ,
159- },
160- // WithFirmware(altSrc) + WithCacheDir = 2
161- wantCount : 2 ,
162- },
163- {
164- name : "explicit cache dir used over data dir" ,
165- provider : NewPropolisProvider (
166- WithRuntimeSource (rtSrc ),
167- WithFirmwareSource (fwSrc ),
168- ),
169- opts : CreateVMOpts {
170- DataDir : "/tmp/data" ,
171- CacheDir : "/tmp/cache" ,
172- },
173- // WithRuntime + WithFirmware + WithCacheDir = 3
174- wantCount : 3 ,
175- },
176- }
177-
178- for _ , tt := range tests {
179- t .Run (tt .name , func (t * testing.T ) {
180- t .Parallel ()
181- got := tt .provider .buildBackendOpts (tt .opts )
182- if len (got ) != tt .wantCount {
183- t .Errorf ("buildBackendOpts returned %d options, want %d" , len (got ), tt .wantCount )
184- }
185- })
186- }
187- }
188-
18966func TestInitInjector (t * testing.T ) {
19067 t .Parallel ()
19168
0 commit comments