-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from Bowenislandsong/understand-packages
[feature] Understanding packages from bundle directory
- Loading branch information
Showing
49 changed files
with
20,168 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package bundle | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"sort" | ||
|
||
"github.com/operator-framework/operator-registry/pkg/registry" | ||
) | ||
|
||
type bundleDirInterpreter struct { | ||
bundleCsvName string | ||
pkg *registry.Package | ||
} | ||
|
||
func NewBundleDirInterperter(bundleDir string) (*bundleDirInterpreter, error) { | ||
csv, err := registry.ReadCSVFromBundleDirectory(bundleDir) | ||
if err != nil { | ||
return nil, fmt.Errorf("error loading CSV from bundle directory, %v", err) | ||
} | ||
|
||
pkgDir, err := registry.NewPackageGraphLoaderFromDir(path.Join(bundleDir, "..")) | ||
if err != nil { | ||
return nil, fmt.Errorf("error loading package from directory, %v", err) | ||
} | ||
|
||
p, err := pkgDir.Generate() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &bundleDirInterpreter{bundleCsvName: csv.GetName(), pkg: p}, nil | ||
} | ||
|
||
func (b *bundleDirInterpreter) GetBundleChannels() (channelNames []string) { | ||
for channelName, channel := range b.pkg.Channels { | ||
for bundle, _ := range channel.Nodes { | ||
if bundle.CsvName == b.bundleCsvName { | ||
channelNames = append(channelNames, channelName) | ||
break | ||
} | ||
} | ||
} | ||
sort.Strings(channelNames) | ||
return | ||
} | ||
|
||
func (b *bundleDirInterpreter) GetDefaultChannel() string { | ||
return b.pkg.DefaultChannel | ||
} | ||
|
||
func (b *bundleDirInterpreter) GetPackageName() string { | ||
return b.pkg.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package bundle | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBundleDirectoryInterpreter(t *testing.T) { | ||
tests := []struct { | ||
dir string | ||
fail bool | ||
bundleChannels []string | ||
defaultChannel string | ||
PackageName string | ||
}{ | ||
{ | ||
dir: "../../registry/testdata/validPackages/etcd/0.6.1", | ||
fail: false, | ||
bundleChannels: []string{"alpha", "beta", "stable"}, | ||
defaultChannel: "alpha", | ||
PackageName: "etcd", | ||
}, | ||
{ | ||
dir: "../../registry/testdata/validPackages/etcd/0.9.0", | ||
fail: false, | ||
bundleChannels: []string{"alpha", "beta", "stable"}, | ||
defaultChannel: "alpha", | ||
PackageName: "etcd", | ||
}, | ||
{ | ||
dir: "../../registry/testdata/validPackages/etcd/0.9.2", | ||
fail: false, | ||
bundleChannels: []string{"alpha", "stable"}, | ||
defaultChannel: "alpha", | ||
PackageName: "etcd", | ||
}, | ||
{ | ||
dir: "../../registry/testdata/validPackages/prometheus/0.14.0", | ||
fail: false, | ||
bundleChannels: []string{"preview"}, | ||
defaultChannel: "preview", | ||
PackageName: "prometheus", | ||
}, | ||
{ | ||
dir: "../../registry/testdata/invalidPackges/3scale-community-operator/0.3.0", | ||
fail: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run("Loading Package Graph from "+tt.dir, func(t *testing.T) { | ||
bundle, err := NewBundleDirInterperter(tt.dir) | ||
if tt.fail { | ||
assert.Error(t, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
|
||
assert.EqualValues(t, tt.bundleChannels, bundle.GetBundleChannels()) | ||
|
||
assert.EqualValues(t, tt.defaultChannel, bundle.GetDefaultChannel()) | ||
|
||
assert.EqualValues(t, tt.PackageName, bundle.GetPackageName()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.