Skip to content

Commit

Permalink
manual test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan <jordan@nimblewidget.com>
  • Loading branch information
grokspawn committed Jan 9, 2025
1 parent 57eb7f5 commit da0410c
Show file tree
Hide file tree
Showing 57 changed files with 493 additions and 446 deletions.
9 changes: 9 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ linters-settings:
- pkg: github.com/blang/semver/v4
alias: bsemver

issues:
# exclusion rules, mostly to avoid functionally complete areas and reduce unit test noise
exclude-rules:
- path: _test\.go
linters:
- unused
- govet


output:
formats:
- format: tab
2 changes: 1 addition & 1 deletion alpha/action/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestMigrate(t *testing.T) {
return
}
actualFS := os.DirFS(s.migrate.OutputDir)
fs.WalkDir(actualFS, ".", func(path string, d fs.DirEntry, err error) error {
_ = fs.WalkDir(actualFS, ".", func(path string, d fs.DirEntry, err error) error {
require.NoError(t, err)
if d.IsDir() {
return nil
Expand Down
2 changes: 1 addition & 1 deletion alpha/action/migrations/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestMigrations(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var config declcfg.DeclarativeConfig = unmigratedCatalogFBC()
var config = unmigratedCatalogFBC()

for _, m := range test.migrators.Migrations {
err := m.Migrate(&config)
Expand Down
17 changes: 7 additions & 10 deletions alpha/action/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"embed"
"encoding/json"
"errors"
"fmt"
"io/fs"
"os"
Expand All @@ -13,7 +12,6 @@ import (
"testing/fstest"
"text/template"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/yaml"

Expand Down Expand Up @@ -86,7 +84,7 @@ func TestRender(t *testing.T) {
image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.1.0"): "testdata/foo-bundle-v0.1.0",
image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.2.0"): "testdata/foo-bundle-v0.2.0",
}
assert.NoError(t, generateSqliteFile(dbFile, imageMap))
require.NoError(t, generateSqliteFile(dbFile, imageMap))
testMigrations := migrations.Migrations{
Migrations: []migrations.Migration{
fauxMigration{"faux-migration", "my help text", func(d *declcfg.DeclarativeConfig) error {
Expand Down Expand Up @@ -1235,7 +1233,7 @@ func TestAllowRefMask(t *testing.T) {
image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.1.0"): "testdata/foo-bundle-v0.1.0",
image.SimpleReference("test.registry/foo-operator/foo-bundle:v0.2.0"): "testdata/foo-bundle-v0.2.0",
}
assert.NoError(t, generateSqliteFile(dbFile, imageMap))
require.NoError(t, generateSqliteFile(dbFile, imageMap))

specs := []spec{
{
Expand Down Expand Up @@ -1365,18 +1363,17 @@ func TestAllowRefMask(t *testing.T) {
for _, s := range specs {
t.Run(s.name, func(t *testing.T) {
_, err := s.render.Run(context.Background())
require.True(t, errors.Is(err, s.expectErr), "expected error %#v to be %#v", err, s.expectErr)
require.ErrorIs(t, err, s.expectErr, "expected error %#v to be %#v", err, s.expectErr)
})
}
}

func TestAllowRefMaskAllowed(t *testing.T) {
type spec struct {
name string
mask action.RefType
pass []action.RefType
fail []action.RefType
expect bool
name string
mask action.RefType
pass []action.RefType
fail []action.RefType
}

specs := []spec{
Expand Down
2 changes: 1 addition & 1 deletion alpha/declcfg/declcfg_to_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func TestConvertToModelRoundtrip(t *testing.T) {

assert.Equal(t, expected.Packages, actual.Packages)
assert.Equal(t, expected.Bundles, actual.Bundles)
assert.Len(t, actual.Others, 0, "expected unrecognized schemas not to make the roundtrip")
assert.Empty(t, actual.Others, "expected unrecognized schemas not to make the roundtrip")
}

func hasError(expectedError string) require.ErrorAssertionFunc {
Expand Down
8 changes: 4 additions & 4 deletions alpha/declcfg/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ func withNoBundleData() func(*Bundle) {
}

func newTestBundle(packageName, version string, opts ...bundleOpt) Bundle {
csvJson := fmt.Sprintf(`{"kind": "ClusterServiceVersion", "apiVersion": "operators.coreos.com/v1alpha1", "metadata":{"name":%q}}`, testBundleName(packageName, version))
csvJSON := fmt.Sprintf(`{"kind": "ClusterServiceVersion", "apiVersion": "operators.coreos.com/v1alpha1", "metadata":{"name":%q}}`, testBundleName(packageName, version))
b := Bundle{
Schema: SchemaBundle,
Name: testBundleName(packageName, version),
Package: packageName,
Image: testBundleImage(packageName, version),
Properties: []property.Property{
property.MustBuildPackage(packageName, version),
property.MustBuildBundleObject([]byte(csvJson)),
property.MustBuildBundleObject([]byte(csvJSON)),
property.MustBuildBundleObject([]byte(`{"kind": "CustomResourceDefinition", "apiVersion": "apiextensions.k8s.io/v1"}`)),
},
RelatedImages: []RelatedImage{
Expand All @@ -163,9 +163,9 @@ func newTestBundle(packageName, version string, opts ...bundleOpt) Bundle {
Image: testBundleImage(packageName, version),
},
},
CsvJSON: csvJson,
CsvJSON: csvJSON,
Objects: []string{
csvJson,
csvJSON,
`{"kind": "CustomResourceDefinition", "apiVersion": "apiextensions.k8s.io/v1"}`,
},
}
Expand Down
21 changes: 17 additions & 4 deletions alpha/declcfg/load_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package declcfg_test

import (
"context"
"crypto/rand"
"encoding/base64"
"fmt"
"math/rand"
"math/big"
"os"
"runtime"
"testing"
Expand Down Expand Up @@ -65,7 +66,11 @@ func generateFBC(b *testing.B, numPackages, numChannels, numBundles int) *declcf
})
}
for i := 0; i < numChannels; i++ {
pkgName := fbc.Packages[rand.Intn(numPackages)].Name
r, err := rand.Int(rand.Reader, big.NewInt(int64(numPackages)))
if err != nil {
b.Error(err)
}
pkgName := fbc.Packages[r.Int64()].Name
channelName := fmt.Sprintf("channel-%d", i)
fbc.Channels = append(fbc.Channels, declcfg.Channel{
Schema: declcfg.SchemaChannel,
Expand All @@ -74,7 +79,11 @@ func generateFBC(b *testing.B, numPackages, numChannels, numBundles int) *declcf
})
}
for i := 0; i < numBundles; i++ {
pkgName := fbc.Packages[rand.Intn(numPackages)].Name
r, err := rand.Int(rand.Reader, big.NewInt(int64(numPackages)))
if err != nil {
b.Error(err)
}
pkgName := fbc.Packages[r.Int64()].Name
bundleName := fmt.Sprintf("bundle-%d", i)
version := fmt.Sprintf("0.%d.0", i)
bundle := declcfg.Bundle{
Expand All @@ -94,7 +103,11 @@ func generateFBC(b *testing.B, numPackages, numChannels, numBundles int) *declcf
bundle.Properties = append(bundle.Properties, property.MustBuildCSVMetadata(csv))
fbc.Bundles = append(fbc.Bundles, bundle)

chIdx := rand.Intn(numChannels)
p, err := rand.Int(rand.Reader, big.NewInt(int64(numChannels)))
if err != nil {
b.Error(err)
}
chIdx := p.Int64()
ch := fbc.Channels[chIdx]
replaces := ""
if len(ch.Entries) > 0 {
Expand Down
20 changes: 10 additions & 10 deletions alpha/declcfg/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,9 @@ func TestLoadFile(t *testing.T) {
path: "unrecognized-schema.json",
assertion: require.NoError,
expect: func(t *testing.T, d *DeclarativeConfig) {
require.Equal(t, 1, len(d.Packages))
require.Equal(t, 1, len(d.Bundles))
require.Equal(t, 1, len(d.Others))
require.Len(t, d.Packages, 1)
require.Len(t, d.Bundles, 1)
require.Len(t, d.Others, 1)
},
},
{
Expand All @@ -1000,9 +1000,9 @@ func TestLoadFile(t *testing.T) {
path: "etcd.yaml",
assertion: require.NoError,
expect: func(t *testing.T, d *DeclarativeConfig) {
require.Equal(t, 1, len(d.Packages))
require.Equal(t, 6, len(d.Bundles))
require.Equal(t, 0, len(d.Others))
require.Len(t, d.Packages, 1)
require.Len(t, d.Bundles, 6)
require.Empty(t, d.Others)
},
},
{
Expand All @@ -1011,10 +1011,10 @@ func TestLoadFile(t *testing.T) {
path: "deprecations.yaml",
assertion: require.NoError,
expect: func(t *testing.T, d *DeclarativeConfig) {
require.Equal(t, 0, len(d.Packages))
require.Equal(t, 0, len(d.Bundles))
require.Equal(t, 0, len(d.Others))
require.Equal(t, 1, len(d.Deprecations))
require.Empty(t, d.Packages)
require.Empty(t, d.Bundles)
require.Empty(t, d.Others)
require.Len(t, d.Deprecations, 1)
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion alpha/declcfg/model_to_declcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/operator-framework/operator-registry/alpha/model"
)
Expand All @@ -26,7 +27,7 @@ func TestConvertFromModel(t *testing.T) {
for _, s := range specs {
t.Run(s.name, func(t *testing.T) {
s.m.Normalize()
assert.NoError(t, s.m.Validate())
require.NoError(t, s.m.Validate())
actual := ConvertFromModel(s.m)

removeJSONWhitespace(&s.expectCfg)
Expand Down
4 changes: 2 additions & 2 deletions alpha/declcfg/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,13 @@ func removeJSONWhitespace(cfg *DeclarativeConfig) {
for ib := range cfg.Bundles {
for ip := range cfg.Bundles[ib].Properties {
var buf bytes.Buffer
json.Compact(&buf, cfg.Bundles[ib].Properties[ip].Value)
_ = json.Compact(&buf, cfg.Bundles[ib].Properties[ip].Value)
cfg.Bundles[ib].Properties[ip].Value = buf.Bytes()
}
}
for io := range cfg.Others {
var buf bytes.Buffer
json.Compact(&buf, cfg.Others[io].Blob)
_ = json.Compact(&buf, cfg.Others[io].Blob)
cfg.Others[io].Blob = buf.Bytes()
}
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/api/conversion_test.go

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func TestCache_GetBundle(t *testing.T) {
t.Run(name, func(t *testing.T) {
b, err := testQuerier.GetBundle(context.TODO(), "etcd", "singlenamespace-alpha", "etcdoperator.v0.9.4")
require.NoError(t, err)
require.Equal(t, b.PackageName, "etcd")
require.Equal(t, b.ChannelName, "singlenamespace-alpha")
require.Equal(t, b.CsvName, "etcdoperator.v0.9.4")
require.Equal(t, "etcd", b.PackageName)
require.Equal(t, "singlenamespace-alpha", b.ChannelName)
require.Equal(t, "etcdoperator.v0.9.4", b.CsvName)
})
}
}
Expand All @@ -31,9 +31,9 @@ func TestCache_GetBundleForChannel(t *testing.T) {

require.NoError(t, err)
require.NotNil(t, b)
require.Equal(t, b.PackageName, "etcd")
require.Equal(t, b.ChannelName, "singlenamespace-alpha")
require.Equal(t, b.CsvName, "etcdoperator.v0.9.4")
require.Equal(t, "etcd", b.PackageName)
require.Equal(t, "singlenamespace-alpha", b.ChannelName)
require.Equal(t, "etcdoperator.v0.9.4", b.CsvName)
})
}
}
Expand All @@ -44,9 +44,9 @@ func TestCache_GetBundleThatProvides(t *testing.T) {
b, err := testQuerier.GetBundleThatProvides(context.TODO(), "etcd.database.coreos.com", "v1beta2", "EtcdBackup")
require.NoError(t, err)
require.NotNil(t, b)
require.Equal(t, b.PackageName, "etcd")
require.Equal(t, b.ChannelName, "singlenamespace-alpha")
require.Equal(t, b.CsvName, "etcdoperator.v0.9.4")
require.Equal(t, "etcd", b.PackageName)
require.Equal(t, "singlenamespace-alpha", b.ChannelName)
require.Equal(t, "etcdoperator.v0.9.4", b.CsvName)
})
}
}
Expand All @@ -57,9 +57,9 @@ func TestCache_GetBundleThatReplaces(t *testing.T) {
b, err := testQuerier.GetBundleThatReplaces(context.TODO(), "etcdoperator.v0.9.0", "etcd", "singlenamespace-alpha")
require.NoError(t, err)
require.NotNil(t, b)
require.Equal(t, b.PackageName, "etcd")
require.Equal(t, b.ChannelName, "singlenamespace-alpha")
require.Equal(t, b.CsvName, "etcdoperator.v0.9.2")
require.Equal(t, "etcd", b.PackageName)
require.Equal(t, "singlenamespace-alpha", b.ChannelName)
require.Equal(t, "etcdoperator.v0.9.2", b.CsvName)
})
}
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestCache_ListPackages(t *testing.T) {
packages, err := testQuerier.ListPackages(context.TODO())
require.NoError(t, err)
require.NotNil(t, packages)
require.Equal(t, 2, len(packages))
require.Len(t, packages, 2)
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cache/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cache

import (
"bytes"
"errors"
"fmt"
"hash/fnv"
"io/fs"
Expand All @@ -26,7 +25,7 @@ func Test_fsToTar(t *testing.T) {
return notExist
},
expect: func(t *testing.T, bytes []byte, err error) {
require.True(t, errors.Is(err, fs.ErrNotExist))
require.ErrorIs(t, err, fs.ErrNotExist)
},
},
{
Expand Down
Loading

0 comments on commit da0410c

Please sign in to comment.