refactor: implement mocking functions and tests
This commit is contained in:
parent
339dba4e13
commit
f8ef2ef2d5
21 changed files with 398 additions and 90 deletions
51
utils.go
51
utils.go
|
|
@ -2,17 +2,19 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
// "io"
|
||||
"log"
|
||||
// "net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
// "runtime"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
execCommand = exec.Command
|
||||
execLookPath = exec.LookPath
|
||||
)
|
||||
|
||||
func getSudoPassword() (string, error) {
|
||||
var password string
|
||||
form := huh.NewForm(
|
||||
|
|
@ -31,37 +33,6 @@ func getSudoPassword() (string, error) {
|
|||
return password, nil
|
||||
}
|
||||
|
||||
// func downloadGolang(golangVersion string) error {
|
||||
// var link string
|
||||
// if runtime.GOARCH == "arm64" {
|
||||
// link = "https://go.dev/dl/go" + golangVersion + ".linux-arm64.tar.gz"
|
||||
// } else {
|
||||
// link = "https://go.dev/dl/go" + golangVersion + ".linux-amd64.tar.gz"
|
||||
// }
|
||||
// resp, err := http.Get(link)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("fehler beim Herunterladen von Go: %v", err)
|
||||
// }
|
||||
// defer resp.Body.Close()
|
||||
|
||||
// if resp.StatusCode != http.StatusOK {
|
||||
// return fmt.Errorf("unerwarteter HTTP-Status: %s", resp.Status)
|
||||
// }
|
||||
|
||||
// outFile, err := os.Create("go" + golangVersion + ".linux-" + runtime.GOARCH + ".tar.gz")
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("fehler beim Erstellen der Ausgabedatei: %v", err)
|
||||
// }
|
||||
// defer outFile.Close()
|
||||
|
||||
// _, err = io.Copy(outFile, resp.Body)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("fehler beim Schreiben der Ausgabedatei: %v", err)
|
||||
// }
|
||||
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
|
|
@ -69,18 +40,8 @@ func max(a, b int) int {
|
|||
return b
|
||||
}
|
||||
|
||||
// func installPackageWithProgress(name string, installFunc func() error) error {
|
||||
// err := installFunc()
|
||||
// if err != nil {
|
||||
// fmt.Printf("\r❌ %s\n", name)
|
||||
// return err
|
||||
// }
|
||||
// fmt.Printf("\r✓ %s\n", name)
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func executeShellCommand(command string, env string) error {
|
||||
cmd := exec.Command("bash", "-c", command)
|
||||
cmd := execCommand("bash", "-c", command)
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Env = append(cmd.Env, env)
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue