Skip to content

Commit 492b764

Browse files
authored
commands/.../test,pkg/test: fix test local --up-local (#1109)
**Description of the change:** Disable creation of namespaced resources when running `test local --up-local` and fix running of local command in `test local --up-local`. **Motivation for the change:** `test local --up-local` was broken. Fixes #1105
1 parent 7e578b4 commit 492b764

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

commands/operator-sdk/cmd/test/local.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,29 @@ func testLocalGoFunc(cmd *cobra.Command, args []string) error {
122122

123123
// if no namespaced manifest path is given, combine deploy/service_account.yaml, deploy/role.yaml, deploy/role_binding.yaml and deploy/operator.yaml
124124
if tlConfig.namespacedManPath == "" && !tlConfig.noSetup {
125-
file, err := yamlutil.GenerateCombinedNamespacedManifest(scaffold.DeployDir)
126-
if err != nil {
127-
return err
125+
if !tlConfig.upLocal {
126+
file, err := yamlutil.GenerateCombinedNamespacedManifest(scaffold.DeployDir)
127+
if err != nil {
128+
return err
129+
}
130+
tlConfig.namespacedManPath = file.Name()
131+
} else {
132+
file, err := ioutil.TempFile("", "empty.yaml")
133+
tlConfig.namespacedManPath = file.Name()
134+
emptyBytes := []byte{}
135+
if err := file.Chmod(os.FileMode(fileutil.DefaultFileMode)); err != nil {
136+
return fmt.Errorf("could not chown temporary namespaced manifest file: (%v)", err)
137+
}
138+
if _, err := file.Write(emptyBytes); err != nil {
139+
return fmt.Errorf("could not create temporary namespaced manifest file: (%v)", err)
140+
}
141+
if err := file.Close(); err != nil {
142+
return err
143+
}
144+
if err != nil {
145+
return fmt.Errorf("could not create empty manifest file: (%v)", err)
146+
}
128147
}
129-
tlConfig.namespacedManPath = file.Name()
130148
defer func() {
131149
err := os.Remove(tlConfig.namespacedManPath)
132150
if err != nil {

pkg/test/main_entry.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ func MainEntry(m *testing.M) {
7373
if err := projutil.ExecCmd(bc); err != nil {
7474
log.Fatalf("Failed to build local operator binary: %s", err)
7575
}
76-
77-
localCmd = exec.Command(outputBinName, args...)
76+
localCmd = exec.Command(outputBinName)
7877
localCmd.Stdout = &localCmdOutBuf
7978
localCmd.Stderr = &localCmdErrBuf
8079
c := make(chan os.Signal)

0 commit comments

Comments
 (0)