misc: lint and remove deprecated ioutil method calls

This commit is contained in:
Joel Rebello 2022-11-24 16:16:40 +01:00
parent ed927404da
commit 816e98350c
No known key found for this signature in database
GPG Key ID: EDB938BE882F8078
3 changed files with 13 additions and 28 deletions

View File

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
@ -105,8 +104,8 @@ type preserveConfig struct {
} }
// Firmware flash progress // Firmware flash progress
//{ "id": 1, "action": "Flashing...", "progress": "12% done ", "state": 0 } // { "id": 1, "action": "Flashing...", "progress": "12% done ", "state": 0 }
//{ "id": 1, "action": "Flashing...", "progress": "100% done", "state": 0 } // { "id": 1, "action": "Flashing...", "progress": "100% done", "state": 0 }
type upgradeProgress struct { type upgradeProgress struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
Action string `json:"action,omitempty"` Action string `json:"action,omitempty"`
@ -463,12 +462,7 @@ func (a *ASRockRack) biosUpgradeConfiguration(ctx context.Context) error {
} }
f := &firmwareInfo{} f := &firmwareInfo{}
err = json.Unmarshal(resp, f) return json.Unmarshal(resp, f)
if err != nil {
return err
}
return nil
} }
// Run BIOS upgrade // Run BIOS upgrade
@ -493,12 +487,7 @@ func (a *ASRockRack) upgradeBIOS(ctx context.Context) error {
} }
f := &firmwareInfo{} f := &firmwareInfo{}
err = json.Unmarshal(resp, f) return json.Unmarshal(resp, f)
if err != nil {
return err
}
return nil
} }
// Returns the chassis status object which includes the power state // Returns the chassis status object which includes the power state
@ -560,13 +549,10 @@ func (a *ASRockRack) httpsLogout(ctx context.Context) error {
return fmt.Errorf("Error logging out: " + err.Error()) return fmt.Errorf("Error logging out: " + err.Error())
} }
if err != nil {
return fmt.Errorf("Error logging out: " + err.Error())
}
if statusCode != http.StatusOK { if statusCode != http.StatusOK {
return fmt.Errorf("non 200 response at https logout: %d", statusCode) return fmt.Errorf("non 200 response at https logout: %d", statusCode)
} }
return nil return nil
} }
@ -614,7 +600,7 @@ func (a *ASRockRack) queryHTTPS(ctx context.Context, endpoint, method string, pa
a.log.V(3).Info("trace", "responseDump", string(respDump)) a.log.V(3).Info("trace", "responseDump", string(respDump))
} }
body, err = ioutil.ReadAll(resp.Body) body, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
return body, 0, err return body, 0, err
} }

View File

@ -3,7 +3,7 @@ package asrockrack
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"log" "log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -71,7 +71,7 @@ func TestMain(m *testing.M) {
os.Exit(m.Run()) os.Exit(m.Run())
} }
/////////////// mock bmc service /////////////////////////// // ///////////// mock bmc service ///////////////////////////
func mockASRockBMC() *httptest.Server { func mockASRockBMC() *httptest.Server {
handler := http.NewServeMux() handler := http.NewServeMux()
handler.HandleFunc("/", index) handler.HandleFunc("/", index)
@ -270,7 +270,7 @@ func sensorsinfo(w http.ResponseWriter, r *http.Request) {
log.Fatal(err) log.Fatal(err)
} }
b, err := ioutil.ReadAll(fh) b, err := io.ReadAll(fh)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -296,7 +296,7 @@ func session(w http.ResponseWriter, r *http.Request) {
switch r.Method { switch r.Method {
case "POST": case "POST":
// login to BMC // login to BMC
b, _ := ioutil.ReadAll(r.Body) b, _ := io.ReadAll(r.Body)
if string(b) == string(loginPayload) { if string(b) == string(loginPayload) {
// login request needs to be of the right content-typ // login request needs to be of the right content-typ
if r.Header.Get("Content-Type") != "application/x-www-form-urlencoded" { if r.Header.Get("Content-Type") != "application/x-www-form-urlencoded" {

View File

@ -3,7 +3,6 @@ package ipmitool
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -17,7 +16,7 @@ func TestMain(m *testing.M) {
var tempDir string var tempDir string
_, err := exec.LookPath("ipmitool") _, err := exec.LookPath("ipmitool")
if err != nil { if err != nil {
tempDir, err = ioutil.TempDir("/tmp", "") tempDir, err = os.MkdirTemp("/tmp", "")
if err != nil { if err != nil {
os.Exit(2) os.Exit(2)
} }
@ -25,7 +24,7 @@ func TestMain(m *testing.M) {
os.Setenv("PATH", path) os.Setenv("PATH", path)
fmt.Println(os.Getenv("PATH")) fmt.Println(os.Getenv("PATH"))
f := filepath.Join(tempDir, "ipmitool") f := filepath.Join(tempDir, "ipmitool")
err = ioutil.WriteFile(f, []byte{}, 0755) err = os.WriteFile(f, []byte{}, 0755)
if err != nil { if err != nil {
os.RemoveAll(tempDir) os.RemoveAll(tempDir)
os.Exit(3) os.Exit(3)