Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4d2d23f

Browse files
committedAug 8, 2019
test(directory): add bad manifests test
1 parent 4ce2b9e commit 4d2d23f

File tree

13 files changed

+233
-14
lines changed

13 files changed

+233
-14
lines changed
 

‎go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/operator-framework/go-appr v0.0.0-20180917210448-f2aef88446f2
3030
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190125151539-1e295784b30a
3131
github.com/operator-framework/operator-marketplace v0.0.0-20190216021216-57300a3ef3ba
32+
github.com/otiai10/copy v1.0.1
3233
github.com/sirupsen/logrus v1.2.0
3334
github.com/soheilhy/cmux v0.1.4 // indirect
3435
github.com/spf13/cobra v0.0.3
@@ -40,6 +41,7 @@ require (
4041
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
4142
golang.org/x/tools v0.0.0-20181207222222-4c874b978acb // indirect
4243
google.golang.org/grpc v1.17.0
44+
gopkg.in/yaml.v2 v2.2.1
4345
k8s.io/api v0.0.0-20190118113203-912cbe2bfef3
4446
k8s.io/apiextensions-apiserver v0.0.0-20181204003618-e419c5771cdc
4547
k8s.io/apimachinery v0.0.0-20190118094746-1525e4dadd2d

‎go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bitbucket.org/ww/goautoneg v0.0.0-20120707110453-75cd24fc2f2c/go.mod h1:1vhO7Mn/FZMgOgDVGLy5X1mE6rq1HbkBdkF/yj8zkcg=
2+
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
23
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
34
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
45
github.com/NYTimes/gziphandler v1.0.1/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
@@ -141,6 +142,9 @@ github.com/operator-framework/operator-marketplace v0.0.0-20190216021216-57300a3
141142
github.com/operator-framework/operator-marketplace v0.0.0-20190216021216-57300a3ef3ba/go.mod h1:msZSL8pXwzQjB+hU+awVrZQw94IwJi3sNZVD3NoESIs=
142143
github.com/operator-framework/operator-registry v1.0.1/go.mod h1:1xEdZjjUg2hPEd52LG3YQ0jtwiwEGdm98S1TH5P4RAA=
143144
github.com/operator-framework/operator-registry v1.0.4/go.mod h1:hve6YwcjM2nGVlscLtNsp9sIIBkNZo6jlJgzWw7vP9s=
145+
github.com/otiai10/copy v1.0.1 h1:gtBjD8aq4nychvRZ2CyJvFWAw0aja+VHazDdruZKGZA=
146+
github.com/otiai10/copy v1.0.1/go.mod h1:8bMCJrAqOtN/d9oyh5HR7HhLQMvcGMpGdwRDYsfOCHc=
147+
github.com/otiai10/mint v1.2.3/go.mod h1:YnfyPNhBvnY8bW4SGQHCs/aAFhkgySlMZbrF5U0bOVw=
144148
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
145149
github.com/petar/GoLLRB v0.0.0-20130427215148-53be0d36a84c/go.mod h1:HUpKUBZnpzkdx0kD/+Yfuft+uD3zHGtXF/XJB14TUr4=
146150
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=

‎pkg/registry/types.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ type DefinitionKey struct {
2626
// channels under a single package.
2727
type PackageManifest struct {
2828
// PackageName is the name of the overall package, ala `etcd`.
29-
PackageName string `json:"packageName"`
29+
PackageName string `json:"packageName" yaml:"packageName"`
3030

3131
// Channels are the declared channels for the package, ala `stable` or `alpha`.
32-
Channels []PackageChannel `json:"channels"`
32+
Channels []PackageChannel `json:"channels" yaml:"channels"`
3333

3434
// DefaultChannelName is, if specified, the name of the default channel for the package. The
3535
// default channel will be installed if no other channel is explicitly given. If the package
3636
// has a single channel, then that channel is implicitly the default.
37-
DefaultChannelName string `json:"defaultChannel"`
37+
DefaultChannelName string `json:"defaultChannel" yaml:"defaultChannel"`
3838
}
3939

4040
// GetDefaultChannel gets the default channel or returns the only one if there's only one. returns empty string if it
@@ -53,11 +53,11 @@ func (m PackageManifest) GetDefaultChannel() string {
5353
// package.
5454
type PackageChannel struct {
5555
// Name is the name of the channel, e.g. `alpha` or `stable`
56-
Name string `json:"name"`
56+
Name string `json:"name" yaml:"name"`
5757

5858
// CurrentCSVName defines a reference to the CSV holding the version of this package currently
5959
// for the channel.
60-
CurrentCSVName string `json:"currentCSV"`
60+
CurrentCSVName string `json:"currentCSV" yaml:"currentCSV"`
6161
}
6262

6363
// IsDefaultChannel returns true if the PackageChennel is the default for the PackageManifest

‎pkg/sqlite/directory_test.go

+49-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package sqlite
22

33
import (
44
"context"
5+
"io/ioutil"
56
"os"
7+
"path/filepath"
68
"testing"
79

10+
"github.com/otiai10/copy"
811
"github.com/sirupsen/logrus"
912
"github.com/stretchr/testify/require"
13+
"gopkg.in/yaml.v2"
1014

1115
"github.com/operator-framework/operator-registry/pkg/registry"
1216
)
@@ -26,6 +30,47 @@ func TestDirectoryLoader(t *testing.T) {
2630
require.NoError(t, loader.Populate())
2731
}
2832

33+
func TestDirectoryLoaderWithBadManifests(t *testing.T) {
34+
logrus.SetLevel(logrus.DebugLevel)
35+
36+
store, err := NewSQLLiteLoader("test.db")
37+
require.NoError(t, err)
38+
defer func() {
39+
if err := os.Remove("test.db"); err != nil {
40+
t.Fatal(err)
41+
}
42+
}()
43+
44+
// Copy golden manifests to a temp dir
45+
dir, err := ioutil.TempDir("testdata", "manifests-")
46+
require.NoError(t, err)
47+
defer func() {
48+
if err := os.RemoveAll(dir); err != nil {
49+
t.Fatal(err)
50+
}
51+
}()
52+
require.NoError(t, copy.Copy("../../manifests", dir))
53+
54+
// Point the first channel at a CSV that doesn't exist
55+
path := filepath.Join(dir, "etcd/etcd.package.yaml")
56+
r, err := os.Open(path)
57+
require.NoError(t, err)
58+
59+
pkg := new(registry.PackageManifest)
60+
require.NoError(t, yaml.NewDecoder(r).Decode(pkg))
61+
require.True(t, len(pkg.Channels) > 1)
62+
pkg.Channels[0].CurrentCSVName = "imaginary"
63+
64+
// Replace file contents
65+
w, err := os.Create(path)
66+
require.NoError(t, err)
67+
require.NoError(t, yaml.NewEncoder(w).Encode(pkg))
68+
69+
// Load and expect error
70+
loader := NewSQLLoaderForDirectory(store, dir)
71+
require.Error(t, loader.Populate(), "error loading package into db: no bundle found for csv imaginary")
72+
}
73+
2974
func TestQuerierForDirectory(t *testing.T) {
3075
load, err := NewSQLLiteLoader("test.db")
3176
require.NoError(t, err)
@@ -77,7 +122,7 @@ func TestQuerierForDirectory(t *testing.T) {
77122

78123
etcdChannelEntries, err := store.GetChannelEntriesThatReplace(context.TODO(), "etcdoperator.v0.9.0")
79124
require.NoError(t, err)
80-
require.ElementsMatch(t, []*registry.ChannelEntry{{"etcd", "alpha", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"},{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}, }, etcdChannelEntries)
125+
require.ElementsMatch(t, []*registry.ChannelEntry{{"etcd", "alpha", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}, {"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}}, etcdChannelEntries)
81126

82127
etcdBundleByReplaces, err := store.GetBundleThatReplaces(context.TODO(), "etcdoperator.v0.9.0", "etcd", "alpha")
83128
require.NoError(t, err)
@@ -94,13 +139,13 @@ func TestQuerierForDirectory(t *testing.T) {
94139
{"etcd", "stable", "etcdoperator.v0.6.1", ""},
95140
{"etcd", "stable", "etcdoperator.v0.9.0", "etcdoperator.v0.6.1"},
96141
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.1"},
97-
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"},}, etcdChannelEntriesThatProvide)
142+
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}}, etcdChannelEntriesThatProvide)
98143

99144
etcdLatestChannelEntriesThatProvide, err := store.GetLatestChannelEntriesThatProvide(context.TODO(), "etcd.database.coreos.com", "v1beta2", "EtcdCluster")
100145
require.NoError(t, err)
101146
require.ElementsMatch(t, []*registry.ChannelEntry{{"etcd", "alpha", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"},
102-
{"etcd", "beta", "etcdoperator.v0.9.0", "etcdoperator.v0.6.1"},
103-
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}}, etcdLatestChannelEntriesThatProvide)
147+
{"etcd", "beta", "etcdoperator.v0.9.0", "etcdoperator.v0.6.1"},
148+
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}}, etcdLatestChannelEntriesThatProvide)
104149

105150
etcdBundleByProvides, entry, err := store.GetBundleThatProvides(context.TODO(), "etcd.database.coreos.com", "v1beta2", "EtcdCluster")
106151
require.NoError(t, err)

‎pkg/sqlite/testdata/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
manifests-*

‎vendor/github.com/otiai10/copy/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/otiai10/copy/.travis.yml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/otiai10/copy/LICENSE

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/otiai10/copy/README.md

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/otiai10/copy/copy.go

+106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/otiai10/copy/go.mod

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/otiai10/copy/go.sum

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/modules.txt

+7-5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ github.com/operator-framework/operator-marketplace/pkg/client/clientset/versione
113113
github.com/operator-framework/operator-marketplace/pkg/apis/marketplace/v1alpha1
114114
github.com/operator-framework/operator-marketplace/pkg/client/clientset/versioned/scheme
115115
github.com/operator-framework/operator-marketplace/pkg/apis
116+
# github.com/otiai10/copy v1.0.1
117+
github.com/otiai10/copy
116118
# github.com/peterbourgon/diskv v2.0.1+incompatible
117119
github.com/peterbourgon/diskv
118120
# github.com/pmezard/go-difflib v1.0.0
@@ -152,13 +154,13 @@ google.golang.org/genproto/googleapis/rpc/status
152154
# google.golang.org/grpc v1.17.0
153155
google.golang.org/grpc
154156
google.golang.org/grpc/reflection
157+
google.golang.org/grpc/connectivity
155158
google.golang.org/grpc/codes
156159
google.golang.org/grpc/credentials
157160
google.golang.org/grpc/health/grpc_health_v1
158161
google.golang.org/grpc/status
159162
google.golang.org/grpc/balancer
160163
google.golang.org/grpc/balancer/roundrobin
161-
google.golang.org/grpc/connectivity
162164
google.golang.org/grpc/encoding
163165
google.golang.org/grpc/encoding/proto
164166
google.golang.org/grpc/grpclog
@@ -205,10 +207,10 @@ k8s.io/api/batch/v1
205207
k8s.io/api/batch/v1beta1
206208
k8s.io/api/batch/v2alpha1
207209
k8s.io/api/certificates/v1beta1
208-
k8s.io/api/events/v1beta1
209210
k8s.io/api/extensions/v1beta1
210-
k8s.io/api/networking/v1
211211
k8s.io/api/policy/v1beta1
212+
k8s.io/api/events/v1beta1
213+
k8s.io/api/networking/v1
212214
k8s.io/api/rbac/v1
213215
k8s.io/api/rbac/v1alpha1
214216
k8s.io/api/rbac/v1beta1
@@ -262,8 +264,8 @@ k8s.io/apimachinery/third_party/forked/golang/reflect
262264
k8s.io/apimachinery/pkg/util/wait
263265
k8s.io/apimachinery/pkg/version
264266
k8s.io/apimachinery/pkg/util/clock
265-
k8s.io/apimachinery/pkg/util/strategicpatch
266267
k8s.io/apimachinery/pkg/util/framer
268+
k8s.io/apimachinery/pkg/util/strategicpatch
267269
k8s.io/apimachinery/pkg/apis/meta/v1beta1
268270
k8s.io/apimachinery/pkg/util/mergepatch
269271
k8s.io/apimachinery/third_party/forked/golang/json
@@ -273,7 +275,6 @@ k8s.io/apiserver/pkg/util/feature
273275
k8s.io/client-go/kubernetes
274276
k8s.io/client-go/rest
275277
k8s.io/client-go/tools/clientcmd
276-
k8s.io/client-go/kubernetes/scheme
277278
k8s.io/client-go/discovery
278279
k8s.io/client-go/kubernetes/typed/admissionregistration/v1alpha1
279280
k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1
@@ -316,6 +317,7 @@ k8s.io/client-go/tools/auth
316317
k8s.io/client-go/tools/clientcmd/api/latest
317318
k8s.io/client-go/util/homedir
318319
k8s.io/client-go/tools/record
320+
k8s.io/client-go/kubernetes/scheme
319321
k8s.io/client-go/tools/reference
320322
k8s.io/client-go/util/integer
321323
k8s.io/client-go/pkg/apis/clientauthentication

0 commit comments

Comments
 (0)
Please sign in to comment.