Skip to content

Commit

Permalink
registry/index: test for checking if RegistryPod uses the custom dbpath
Browse files Browse the repository at this point in the history
This also resolves code sanity failure:
```
go vet ./...
tools/scripts/fetch golangci-lint 1.31.0 && tools/bin/golangci-lint run
golangci-lint missing or not version '1.31.0', downloading...
golangci/golangci-lint info checking GitHub for tag 'v1.31.0'
golangci/golangci-lint info found version: 1.31.0 for v1.31.0/linux/amd64
golangci/golangci-lint info installed /home/runner/work/operator-sdk/operator-sdk/tools/bin/golangci-lint
internal/olm/operator/registry/index/registry_pod_test.go:234:26: `containerCommandFor` - `dbPath` always receives `defaultDBPath` (`"/database/index.db"`) (unparam)
func containerCommandFor(dbPath string, items []BundleItem, hasCA bool) string {
                         ^
Makefile:122: recipe for target 'test-sanity' failed
make: *** [test-sanity] Error 1
Error: Process completed with exit code 2.
```
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
  • Loading branch information
avalluri committed Apr 22, 2021
1 parent caf2c69 commit dc4c035
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/olm/operator/registry/index/registry_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package index
import (
"context"
"fmt"
"path/filepath"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -91,6 +92,14 @@ var _ = Describe("RegistryPod", func() {
Expect(rp.DBPath).To(Equal("/database/index.db"))
})

It("should create a registry with custom database path", func() {
customDBPath := "/foo/bar/database.db"
rp.DBPath = customDBPath
output, err := rp.getContainerCmd()
Expect(err).To(BeNil())
Expect(output).Should(Equal(containerCommandFor(customDBPath, defaultBundleItems, false)))
})

It("should return a valid container command for one image", func() {
output, err := rp.getContainerCmd()
Expect(err).To(BeNil())
Expand Down Expand Up @@ -240,5 +249,5 @@ func containerCommandFor(dbPath string, items []BundleItem, hasCA bool) string {
for _, item := range items {
additions.WriteString(fmt.Sprintf("/bin/opm registry add -d %s -b %s --mode=%s%s --skip-tls=%v && \\\n", dbPath, item.ImageTag, item.AddMode, caFlag, item.SkipTLS))
}
return fmt.Sprintf("/bin/mkdir -p /database && \\\n%s/bin/opm registry serve -d /database/index.db -p 50051\n", additions.String())
return fmt.Sprintf("/bin/mkdir -p %s && \\\n%s/bin/opm registry serve -d %s -p 50051\n", filepath.Dir(dbPath), additions.String(), dbPath)
}

0 comments on commit dc4c035

Please sign in to comment.