-
Notifications
You must be signed in to change notification settings - Fork 261
pkg/sqlite: use consistent starting depth when building channel_entry table #868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "context" | ||
| "database/sql" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "strings" | ||
| "testing" | ||
|
|
@@ -154,6 +155,71 @@ func TestAddPackageChannels(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestAddBundleSemver(t *testing.T) { | ||
| // Create a test DB | ||
| db, cleanup := CreateTestDb(t) | ||
| defer cleanup() | ||
| store, err := NewSQLLiteLoader(db) | ||
| require.NoError(t, err) | ||
| err = store.Migrate(context.TODO()) | ||
| require.NoError(t, err) | ||
| graphLoader, err := NewSQLGraphLoaderFromDB(db) | ||
| require.NoError(t, err) | ||
|
|
||
| // Seed the db with a replaces-mode bundle/package | ||
| replacesBundle := newBundle(t, "csv-a", "pkg-foo", []string{"stable"}, newUnstructuredCSV(t, "csv-a", "")) | ||
| err = store.AddOperatorBundle(replacesBundle) | ||
| require.NoError(t, err) | ||
|
|
||
| err = store.AddPackageChannels(registry.PackageManifest{ | ||
| PackageName: "pkg-foo", | ||
| Channels: []registry.PackageChannel{ | ||
| { | ||
| Name: "stable", | ||
| CurrentCSVName: "csv-a", | ||
| }, | ||
| }, | ||
| DefaultChannelName: "stable", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| // Add semver bundles in non-semver order. | ||
| bundles := []*registry.Bundle{ | ||
| newBundle(t, "csv-3", "pkg-0", []string{"stable"}, newUnstructuredCSVWithVersion(t, "csv-3", "0.3.0")), | ||
| newBundle(t, "csv-1", "pkg-0", []string{"stable"}, newUnstructuredCSVWithVersion(t, "csv-1", "0.1.0")), | ||
| newBundle(t, "csv-2", "pkg-0", []string{"stable"}, newUnstructuredCSVWithVersion(t, "csv-2", "0.2.0")), | ||
| } | ||
| for _, b := range bundles { | ||
| graph, err := graphLoader.Generate(b.Package) | ||
| require.Conditionf(t, func() bool { | ||
| return err == nil || errors.Is(err, registry.ErrPackageNotInDatabase) | ||
| }, "got unexpected error: %v", err) | ||
| bundleLoader := registry.BundleGraphLoader{} | ||
| updatedGraph, err := bundleLoader.AddBundleToGraph(b, graph, ®istry.AnnotationsFile{Annotations: *b.Annotations}, false) | ||
| require.NoError(t, err) | ||
| err = store.AddBundleSemver(updatedGraph, b) | ||
| require.NoError(t, err) | ||
| } | ||
|
Comment on lines
+192
to
+202
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love that all of this code is in the test. It seems like this should be better encapsulated in non-test code. I suppose I could re-write the test using the DirectoryPopulator abstraction, but that would require using the We could also look at making this something that could be more easily called in a test. I'm just not sure it's worth it given all of this code is deprecated. |
||
|
|
||
| // Ensure bundles can be queried with expected replaces and skips values. | ||
| querier := NewSQLLiteQuerierFromDb(db) | ||
| gotBundles, err := querier.ListBundles(context.Background()) | ||
| require.NoError(t, err) | ||
| replaces := map[string]string{} | ||
| for _, b := range gotBundles { | ||
| if b.PackageName != "pkg-0" { | ||
| continue | ||
| } | ||
| require.Len(t, b.Skips, 0, "unexpected skips value(s) for bundle %q", b.CsvName) | ||
| replaces[b.CsvName] = b.Replaces | ||
| } | ||
| require.Equal(t, map[string]string{ | ||
| "csv-3": "csv-2", | ||
| "csv-2": "csv-1", | ||
| "csv-1": "", | ||
| }, replaces) | ||
| } | ||
|
|
||
| func TestClearNonHeadBundles(t *testing.T) { | ||
| db, cleanup := CreateTestDb(t) | ||
| defer cleanup() | ||
|
|
@@ -237,6 +303,18 @@ func newUnstructuredCSVWithSkips(t *testing.T, name, replaces string, skips ...s | |
| return &unstructured.Unstructured{Object: out} | ||
| } | ||
|
|
||
| func newUnstructuredCSVWithVersion(t *testing.T, name, version string) *unstructured.Unstructured { | ||
| csv := ®istry.ClusterServiceVersion{} | ||
| csv.TypeMeta.Kind = "ClusterServiceVersion" | ||
| csv.SetName(name) | ||
| versionJson := fmt.Sprintf(`{"version": "%s"}`, version) | ||
| csv.Spec = json.RawMessage(versionJson) | ||
|
|
||
| out, err := runtime.DefaultUnstructuredConverter.ToUnstructured(csv) | ||
| require.NoError(t, err) | ||
| return &unstructured.Unstructured{Object: out} | ||
| } | ||
|
|
||
| func newBundle(t *testing.T, name, pkgName string, channels []string, objs ...*unstructured.Unstructured) *registry.Bundle { | ||
| bundle := registry.NewBundle(name, ®istry.Annotations{ | ||
| PackageName: pkgName, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.