|
9 | 9 | "testing" |
10 | 10 | "testing/fstest" |
11 | 11 |
|
| 12 | + "github.com/stretchr/testify/assert" |
12 | 13 | "github.com/stretchr/testify/require" |
13 | 14 | "k8s.io/apimachinery/pkg/util/yaml" |
14 | 15 |
|
@@ -246,6 +247,113 @@ func TestRender(t *testing.T) { |
246 | 247 | } |
247 | 248 | } |
248 | 249 |
|
| 250 | +func TestRenderDBFile(t *testing.T) { |
| 251 | + |
| 252 | + foov1csv, err := bundleImageV1.ReadFile("testdata/foo-bundle-v0.1.0/manifests/foo.v0.1.0.csv.yaml") |
| 253 | + require.NoError(t, err) |
| 254 | + foov1crd, err := bundleImageV1.ReadFile("testdata/foo-bundle-v0.1.0/manifests/foos.test.foo.crd.yaml") |
| 255 | + require.NoError(t, err) |
| 256 | + foov2csv, err := bundleImageV2.ReadFile("testdata/foo-bundle-v0.2.0/manifests/foo.v0.2.0.csv.yaml") |
| 257 | + require.NoError(t, err) |
| 258 | + foov2crd, err := bundleImageV2.ReadFile("testdata/foo-bundle-v0.2.0/manifests/foos.test.foo.crd.yaml") |
| 259 | + require.NoError(t, err) |
| 260 | + |
| 261 | + foov1csv, err = yaml.ToJSON(foov1csv) |
| 262 | + require.NoError(t, err) |
| 263 | + foov1crd, err = yaml.ToJSON(foov1crd) |
| 264 | + require.NoError(t, err) |
| 265 | + foov2csv, err = yaml.ToJSON(foov2csv) |
| 266 | + require.NoError(t, err) |
| 267 | + foov2crd, err = yaml.ToJSON(foov2crd) |
| 268 | + require.NoError(t, err) |
| 269 | + |
| 270 | + expectCfg := &declcfg.DeclarativeConfig{ |
| 271 | + Packages: []declcfg.Package{ |
| 272 | + { |
| 273 | + Schema: "olm.package", |
| 274 | + Name: "foo", |
| 275 | + DefaultChannel: "beta", |
| 276 | + }, |
| 277 | + }, |
| 278 | + Bundles: []declcfg.Bundle{ |
| 279 | + { |
| 280 | + Schema: "olm.bundle", |
| 281 | + Name: "foo.v0.1.0", |
| 282 | + Package: "foo", |
| 283 | + Image: "test.registry/foo-operator/foo-bundle:v0.1.0", |
| 284 | + Properties: []property.Property{ |
| 285 | + property.MustBuildChannel("beta", ""), |
| 286 | + property.MustBuildGVK("test.foo", "v1", "Foo"), |
| 287 | + property.MustBuildGVKRequired("test.bar", "v1alpha1", "Bar"), |
| 288 | + property.MustBuildPackage("foo", "0.1.0"), |
| 289 | + property.MustBuildPackageRequired("bar", "v0.1.0"), |
| 290 | + property.MustBuildSkipRange("<0.1.0"), |
| 291 | + property.MustBuildBundleObjectData(foov1csv), |
| 292 | + property.MustBuildBundleObjectData(foov1crd), |
| 293 | + }, |
| 294 | + RelatedImages: []declcfg.RelatedImage{ |
| 295 | + { |
| 296 | + Name: "operator", |
| 297 | + Image: "test.registry/foo-operator/foo:v0.1.0", |
| 298 | + }, |
| 299 | + { |
| 300 | + Image: "test.registry/foo-operator/foo-bundle:v0.1.0", |
| 301 | + }, |
| 302 | + }, |
| 303 | + CsvJSON: string(foov1csv), |
| 304 | + Objects: []string{string(foov1csv), string(foov1crd)}, |
| 305 | + }, |
| 306 | + { |
| 307 | + Schema: "olm.bundle", |
| 308 | + Name: "foo.v0.2.0", |
| 309 | + Package: "foo", |
| 310 | + Image: "test.registry/foo-operator/foo-bundle:v0.2.0", |
| 311 | + Properties: []property.Property{ |
| 312 | + property.MustBuildChannel("beta", "foo.v0.1.0"), |
| 313 | + property.MustBuildGVK("test.foo", "v1", "Foo"), |
| 314 | + property.MustBuildGVKRequired("test.bar", "v1alpha1", "Bar"), |
| 315 | + property.MustBuildPackage("foo", "0.2.0"), |
| 316 | + property.MustBuildPackageRequired("bar", "v0.1.0"), |
| 317 | + property.MustBuildSkipRange("<0.2.0"), |
| 318 | + property.MustBuildSkips("foo.v0.1.1"), |
| 319 | + property.MustBuildSkips("foo.v0.1.2"), |
| 320 | + property.MustBuildBundleObjectData(foov2csv), |
| 321 | + property.MustBuildBundleObjectData(foov2crd), |
| 322 | + }, |
| 323 | + RelatedImages: []declcfg.RelatedImage{ |
| 324 | + { |
| 325 | + Name: "operator", |
| 326 | + Image: "test.registry/foo-operator/foo:v0.2.0", |
| 327 | + }, |
| 328 | + { |
| 329 | + Image: "test.registry/foo-operator/foo-bundle:v0.2.0", |
| 330 | + }, |
| 331 | + }, |
| 332 | + CsvJSON: string(foov2csv), |
| 333 | + Objects: []string{string(foov2csv), string(foov2crd)}, |
| 334 | + }, |
| 335 | + }, |
| 336 | + } |
| 337 | + |
| 338 | + dir := t.TempDir() |
| 339 | + |
| 340 | + dbFile := filepath.Join(dir, "index.db") |
| 341 | + imageMap := map[image.Reference]string{ |
| 342 | + image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.1.0"): "testdata/foo-bundle-v0.1.0", |
| 343 | + image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.2.0"): "testdata/foo-bundle-v0.2.0", |
| 344 | + } |
| 345 | + assert.NoError(t, generateSqliteFile(dbFile, imageMap)) |
| 346 | + |
| 347 | + render := action.Render{ |
| 348 | + Refs: []string{dbFile}, |
| 349 | + Registry: &image.MockRegistry{RemoteImages: map[image.Reference]*image.MockImage{}}, |
| 350 | + } |
| 351 | + |
| 352 | + actualCfg, actualErr := render.Run(context.Background()) |
| 353 | + assert.NoError(t, actualErr) |
| 354 | + assert.Equal(t, expectCfg, actualCfg) |
| 355 | +} |
| 356 | + |
249 | 357 | //go:embed testdata/foo-bundle-v0.1.0/manifests/* |
250 | 358 | //go:embed testdata/foo-bundle-v0.1.0/metadata/* |
251 | 359 | var bundleImageV1 embed.FS |
@@ -281,25 +389,25 @@ func newRegistry() (image.Registry, error) { |
281 | 389 | } |
282 | 390 | return &image.MockRegistry{ |
283 | 391 | RemoteImages: map[image.Reference]*image.MockImage{ |
284 | | - image.SimpleReference("test.registry/foo-operator/foo-index-sqlite:v0.2.0"): &image.MockImage{ |
| 392 | + image.SimpleReference("test.registry/foo-operator/foo-index-sqlite:v0.2.0"): { |
285 | 393 | Labels: map[string]string{ |
286 | 394 | containertools.DbLocationLabel: "/database/index.db", |
287 | 395 | }, |
288 | 396 | FS: subSqliteImage, |
289 | 397 | }, |
290 | | - image.SimpleReference("test.registry/foo-operator/foo-index-declcfg:v0.2.0"): &image.MockImage{ |
| 398 | + image.SimpleReference("test.registry/foo-operator/foo-index-declcfg:v0.2.0"): { |
291 | 399 | Labels: map[string]string{ |
292 | 400 | "operators.operatorframework.io.index.configs.v1": "/foo", |
293 | 401 | }, |
294 | 402 | FS: subDeclcfgImage, |
295 | 403 | }, |
296 | | - image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.1.0"): &image.MockImage{ |
| 404 | + image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.1.0"): { |
297 | 405 | Labels: map[string]string{ |
298 | 406 | bundle.PackageLabel: "foo", |
299 | 407 | }, |
300 | 408 | FS: subBundleImageV1, |
301 | 409 | }, |
302 | | - image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.2.0"): &image.MockImage{ |
| 410 | + image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.2.0"): { |
303 | 411 | Labels: map[string]string{ |
304 | 412 | bundle.PackageLabel: "foo", |
305 | 413 | }, |
|
0 commit comments