diff --git a/pkg/utils/exec.go b/pkg/utils/exec.go deleted file mode 100644 index 66d82fcad10443f15ae4a2acdc3886965931264a..0000000000000000000000000000000000000000 --- a/pkg/utils/exec.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2023 KylinSoft Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package utils - -import ( - "bytes" - "fmt" - "os/exec" -) - -// RunCommand runs the specified command and returns an error if the command fails. -func RunCommand(command string) (string, error) { - cmd := exec.Command("sh", "-c", command) - var out bytes.Buffer - cmd.Stdout = &out - - err := cmd.Run() - if err != nil { - return "", fmt.Errorf("failed to run command: %v", err) - } - - return out.String(), nil -} diff --git a/pkg/utils/exec_test.go b/pkg/utils/exec_test.go deleted file mode 100644 index a25090f21ea34aa3733f3d88d50b1d668014a5e7..0000000000000000000000000000000000000000 --- a/pkg/utils/exec_test.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2024 KylinSoft Co., Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package utils - -import ( - "testing" -) - -func TestRunCommand(t *testing.T) { - tests := []struct { - name string - command string - wantOutput string - wantErr bool - }{ - { - name: "Valid command", - command: "echo 'Hello, World!'", - wantOutput: "Hello, World!\n", - wantErr: false, - }, - { - name: "Invalid command", - command: "invalidcommand", - wantErr: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - gotOutput, err := RunCommand(tt.command) - if (err != nil) != tt.wantErr { - t.Logf("RunCommand() error = %v, wantErr %v", err, tt.wantErr) - return - } - if gotOutput != tt.wantOutput { - t.Logf("RunCommand() gotOutput = %v, want %v", gotOutput, tt.wantOutput) - } - }) - } -}