Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ linters:
- gosec
issues:
exclude-rules:
# Allow dot imports for ginkgo and gomega
- source: ginkgo|gomega
linters:
- golint
text: "should not use dot imports"

- linters:
- gosec
# these exclusion rules are for current failures in the code base for gosec which are
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/operator-sdk/bundle/internal/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"os"
"testing"

. "github.com/onsi/ginkgo" //nolint:golint
. "github.com/onsi/gomega" //nolint:golint
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
)

Expand Down
4 changes: 1 addition & 3 deletions test/e2e-ansible/e2e_ansible_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/operator-framework/operator-sdk/internal/version"
testutils "github.com/operator-framework/operator-sdk/test/internal"
)

Expand Down Expand Up @@ -114,8 +113,7 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).Should(Succeed())

By("replacing project Dockerfile to use ansible base image with the dev tag")
version := strings.TrimSuffix(version.Version, "+git")
testutils.ReplaceInFile(filepath.Join(tc.Dir, "Dockerfile"), version, "dev")
testutils.ReplaceRegexInFile(filepath.Join(tc.Dir, "Dockerfile"), "quay.io/operator-framework/ansible-operator:.*", "quay.io/operator-framework/ansible-operator:dev")

By("adding Memcached mock task to the role")
testutils.ReplaceInFile(filepath.Join(tc.Dir, "roles", strings.ToLower(tc.Kind), "tasks", "main.yml"),
Expand Down
4 changes: 2 additions & 2 deletions test/e2e-helm/e2e_helm_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"strings"
"time"

. "github.com/onsi/ginkgo" //nolint:golint
. "github.com/onsi/gomega" //nolint:golint
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
kbtestutils "sigs.k8s.io/kubebuilder/test/e2e/utils"

testutils "github.com/operator-framework/operator-sdk/test/internal"
Expand Down
4 changes: 2 additions & 2 deletions test/e2e-helm/e2e_helm_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package e2e_helm_test
import (
"os/exec"

. "github.com/onsi/ginkgo" //nolint:golint
. "github.com/onsi/gomega" //nolint:golint
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Running Helm projects", func() {
Expand Down
4 changes: 1 addition & 3 deletions test/e2e-helm/e2e_helm_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/operator-framework/operator-sdk/internal/version"
testutils "github.com/operator-framework/operator-sdk/test/internal"
)

Expand Down Expand Up @@ -105,8 +104,7 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).Should(Succeed())

By("replacing project Dockerfile to use Helm base image with the dev tag")
version := strings.TrimSuffix(version.Version, "+git")
testutils.ReplaceInFile(filepath.Join(tc.Dir, "Dockerfile"), version, "dev")
testutils.ReplaceRegexInFile(filepath.Join(tc.Dir, "Dockerfile"), "quay.io/operator-framework/helm-operator:.*", "quay.io/operator-framework/helm-operator:dev")

By("checking the kustomize setup")
err = tc.Make("kustomize")
Expand Down
22 changes: 19 additions & 3 deletions test/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

. "github.com/onsi/ginkgo" //nolint:golint
. "github.com/onsi/gomega" //nolint:golint

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
kbtestutils "sigs.k8s.io/kubebuilder/test/e2e/utils"
)

Expand Down Expand Up @@ -101,6 +101,22 @@ func ReplaceInFile(path, old, new string) {
b, err := ioutil.ReadFile(path)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
s := strings.Replace(string(b), old, new, -1)
ExpectWithOffset(1, s).NotTo(Equal(string(b)), "No replacement occurred")
err = ioutil.WriteFile(path, []byte(s), info.Mode())
ExpectWithOffset(1, err).NotTo(HaveOccurred())
}

// ReplaceRegexInFile finds all strings that match `match` and replaces them
// with `replace` in the file at path.
func ReplaceRegexInFile(path, match, replace string) {
matcher, err := regexp.Compile(match)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
info, err := os.Stat(path)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
b, err := ioutil.ReadFile(path)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
s := matcher.ReplaceAllString(string(b), replace)
ExpectWithOffset(1, s).NotTo(Equal(string(b)), "No replacement occurred")
err = ioutil.WriteFile(path, []byte(s), info.Mode())
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also should return an error when the content is not found to avoid this kind of scenario.
However, we can do it as follow up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and added a check to make sure a replacement actually occurs.

}
Expand Down