Skip to content

Commit

Permalink
Modify API to return empty struct instead of error while querrying em…
Browse files Browse the repository at this point in the history
…pty bundle
  • Loading branch information
anik120 committed Oct 21, 2019
1 parent 208ae69 commit 23875af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func (s *RegistryServer) GetBundle(ctx context.Context, req *api.GetBundleReques
if err != nil {
return nil, err
}
// if the value of the `bundle` field in the OperatorBundle table is NULL, return an
// empty Bundle struct
if bundleString == "" {
return new(api.Bundle), nil
}
entry := &registry.ChannelEntry{
PackageName: req.GetPkgName(),
ChannelName: req.GetChannelName(),
Expand Down
13 changes: 13 additions & 0 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ func TestGetBundleForChannel(t *testing.T) {
require.Equal(t, expected, bundle)
}

func TestGetBundlePath(t *testing.T) {
c, conn := client(t)
defer conn.Close()

bundlePath, err := c.GetBundlePath(context.TODO(), &api.GetBundlePathRequest{PkgName: "etcd", ChannelName: "alpha", CsvName: "etcdoperator.v0.6.1"})
require.NoError(t, err)

expectedBundlePath := &api.BundlePath{
Path: "",
}
require.Equal(t, expectedBundlePath, bundlePath)
}

func TestGetChannelEntriesThatReplace(t *testing.T) {
c, conn := client(t)
defer conn.Close()
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *SQLQuerier) GetBundle(ctx context.Context, pkgName, channelName, csvNam
}

if !rows.Next() {
return "", fmt.Errorf("no bundle found for csv %s", csvName)
return "", fmt.Errorf("no entry found for csv %s", csvName)
}
var bundleStringSQL sql.NullString
if err := rows.Scan(&bundleStringSQL); err != nil {
Expand Down

0 comments on commit 23875af

Please sign in to comment.