Remove ioutil
Signed-off-by: inosato <si17_21@yahoo.co.jp>
This commit is contained in:
parent
b1438ccd40
commit
791e542100
|
@ -18,7 +18,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -150,7 +150,7 @@ func TestAddAlerts(t *testing.T) {
|
||||||
|
|
||||||
api.addAlerts(w, r)
|
api.addAlerts(w, r)
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
body, _ := ioutil.ReadAll(res.Body)
|
body, _ := io.ReadAll(res.Body)
|
||||||
|
|
||||||
require.Equal(t, tc.code, w.Code, fmt.Sprintf("test case: %d, StartsAt %v, EndsAt %v, Response: %s", i, tc.start, tc.end, string(body)))
|
require.Equal(t, tc.code, w.Code, fmt.Sprintf("test case: %d, StartsAt %v, EndsAt %v, Response: %s", i, tc.start, tc.end, string(body)))
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ func TestListAlerts(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
api.listAlerts(w, r)
|
api.listAlerts(w, r)
|
||||||
body, _ := ioutil.ReadAll(w.Result().Body)
|
body, _ := io.ReadAll(w.Result().Body)
|
||||||
|
|
||||||
var res response
|
var res response
|
||||||
err = json.Unmarshal(body, &res)
|
err = json.Unmarshal(body, &res)
|
||||||
|
|
|
@ -16,7 +16,7 @@ package v2
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -204,7 +204,7 @@ func TestDeleteSilenceHandler(t *testing.T) {
|
||||||
HTTPRequest: r,
|
HTTPRequest: r,
|
||||||
})
|
})
|
||||||
responder.WriteResponse(w, p)
|
responder.WriteResponse(w, p)
|
||||||
body, _ := ioutil.ReadAll(w.Result().Body)
|
body, _ := io.ReadAll(w.Result().Body)
|
||||||
|
|
||||||
require.Equal(t, tc.expectedCode, w.Code, fmt.Sprintf("test case: %d, response: %s", i, string(body)))
|
require.Equal(t, tc.expectedCode, w.Code, fmt.Sprintf("test case: %d, response: %s", i, string(body)))
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ func TestPostSilencesHandler(t *testing.T) {
|
||||||
Silence: &silence,
|
Silence: &silence,
|
||||||
})
|
})
|
||||||
responder.WriteResponse(w, p)
|
responder.WriteResponse(w, p)
|
||||||
body, _ := ioutil.ReadAll(w.Result().Body)
|
body, _ := io.ReadAll(w.Result().Body)
|
||||||
|
|
||||||
require.Equal(t, tc.expectedCode, w.Code, fmt.Sprintf("test case: %d, response: %s", i, string(body)))
|
require.Equal(t, tc.expectedCode, w.Code, fmt.Sprintf("test case: %d, response: %s", i, string(body)))
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
@ -37,7 +36,7 @@ func NewResolver(files []string, legacyFlags map[string]string) (*Resolver, erro
|
||||||
if _, err := os.Stat(f); err != nil {
|
if _, err := os.Stat(f); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
b, err := ioutil.ReadFile(f)
|
b, err := os.ReadFile(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
@ -30,8 +30,8 @@ func newApp() *kingpin.Application {
|
||||||
id = new(string)
|
id = new(string)
|
||||||
|
|
||||||
app := kingpin.New("app", "")
|
app := kingpin.New("app", "")
|
||||||
app.UsageWriter(ioutil.Discard)
|
app.UsageWriter(io.Discard)
|
||||||
app.ErrorWriter(ioutil.Discard)
|
app.ErrorWriter(io.Discard)
|
||||||
app.Terminate(nil)
|
app.Terminate(nil)
|
||||||
|
|
||||||
app.Flag("url", "").StringVar(url)
|
app.Flag("url", "").StringVar(url)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
promconfig "github.com/prometheus/common/config"
|
promconfig "github.com/prometheus/common/config"
|
||||||
|
@ -23,7 +23,7 @@ import (
|
||||||
|
|
||||||
// LoadHTTPConfigFile returns HTTPClientConfig for the given http_config file
|
// LoadHTTPConfigFile returns HTTPClientConfig for the given http_config file
|
||||||
func LoadHTTPConfigFile(filename string) (*promconfig.HTTPClientConfig, error) {
|
func LoadHTTPConfigFile(filename string) (*promconfig.HTTPClientConfig, error) {
|
||||||
b, err := ioutil.ReadFile(filename)
|
b, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ func (c *templateRenderCmd) render(ctx context.Context, _ *kingpin.ParseContext)
|
||||||
if c.templateData == nil {
|
if c.templateData == nil {
|
||||||
data = defaultData
|
data = defaultData
|
||||||
} else {
|
} else {
|
||||||
content, err := ioutil.ReadAll(c.templateData)
|
content, err := io.ReadAll(c.templateData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
package cluster
|
package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/prometheus/common/config"
|
"github.com/prometheus/common/config"
|
||||||
|
@ -31,7 +31,7 @@ func GetTLSTransportConfig(configPath string) (*TLSTransportConfig, error) {
|
||||||
if configPath == "" {
|
if configPath == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadFile(configPath)
|
bytes, err := os.ReadFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@ package config
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -192,7 +192,7 @@ func Load(s string) (*Config, error) {
|
||||||
|
|
||||||
// LoadFile parses the given YAML file into a Config.
|
// LoadFile parses the given YAML file into a Config.
|
||||||
func LoadFile(filename string) (*Config, error) {
|
func LoadFile(filename string) (*Config, error) {
|
||||||
content, err := ioutil.ReadFile(filename)
|
content, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,14 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Fatal(http.ListenAndServe(":5001", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
log.Fatal(http.ListenAndServe(":5001", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
b, err := ioutil.ReadAll(r.Body)
|
b, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ package nflog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -98,7 +98,7 @@ func TestLogSnapshot(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
f, err := ioutil.TempFile("", "snapshot")
|
f, err := os.CreateTemp("", "snapshot")
|
||||||
require.NoError(t, err, "creating temp file failed")
|
require.NoError(t, err, "creating temp file failed")
|
||||||
|
|
||||||
l1 := &Log{
|
l1 := &Log{
|
||||||
|
@ -127,7 +127,7 @@ func TestLogSnapshot(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithMaintenance_SupportsCustomCallback(t *testing.T) {
|
func TestWithMaintenance_SupportsCustomCallback(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "snapshot")
|
f, err := os.CreateTemp("", "snapshot")
|
||||||
require.NoError(t, err, "creating temp file failed")
|
require.NoError(t, err, "creating temp file failed")
|
||||||
|
|
||||||
stopc := make(chan struct{})
|
stopc := make(chan struct{})
|
||||||
|
@ -154,7 +154,7 @@ func TestWithMaintenance_SupportsCustomCallback(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReplaceFile(t *testing.T) {
|
func TestReplaceFile(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "replace_file")
|
dir, err := os.MkdirTemp("", "replace_file")
|
||||||
require.NoError(t, err, "creating temp dir failed")
|
require.NoError(t, err, "creating temp dir failed")
|
||||||
|
|
||||||
origFilename := filepath.Join(dir, "testfile")
|
origFilename := filepath.Join(dir, "testfile")
|
||||||
|
@ -176,7 +176,7 @@ func TestReplaceFile(t *testing.T) {
|
||||||
require.NoError(t, err, "opening original file failed")
|
require.NoError(t, err, "opening original file failed")
|
||||||
defer ofr.Close()
|
defer ofr.Close()
|
||||||
|
|
||||||
res, err := ioutil.ReadAll(ofr)
|
res, err := io.ReadAll(ofr)
|
||||||
require.NoError(t, err, "reading original file failed")
|
require.NoError(t, err, "reading original file failed")
|
||||||
require.Equal(t, "test", string(res), "unexpected file contents")
|
require.Equal(t, "test", string(res), "unexpected file contents")
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ package email
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -128,7 +128,7 @@ func (m *mailDev) doEmailRequest(method, path string) (int, []byte, error) {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
b, err := ioutil.ReadAll(res.Body)
|
b, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ type emailTestConfig struct {
|
||||||
|
|
||||||
func loadEmailTestConfiguration(f string) (emailTestConfig, error) {
|
func loadEmailTestConfiguration(f string) (emailTestConfig, error) {
|
||||||
c := emailTestConfig{}
|
c := emailTestConfig{}
|
||||||
b, err := ioutil.ReadFile(f)
|
b, err := os.ReadFile(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
|
@ -276,7 +276,7 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h
|
||||||
if n.conf.APIKey != "" {
|
if n.conf.APIKey != "" {
|
||||||
apiKey = tmpl(string(n.conf.APIKey))
|
apiKey = tmpl(string(n.conf.APIKey))
|
||||||
} else {
|
} else {
|
||||||
content, err := ioutil.ReadFile(n.conf.APIKeyFile)
|
content, err := os.ReadFile(n.conf.APIKeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, errors.Wrap(err, "read key_file error")
|
return nil, false, errors.Wrap(err, "read key_file error")
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,10 @@ package opsgenie
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ func TestGettingOpsGegineApikeyFromFile(t *testing.T) {
|
||||||
|
|
||||||
key := "key"
|
key := "key"
|
||||||
|
|
||||||
f, err := ioutil.TempFile("", "opsgenie_test")
|
f, err := os.CreateTemp("", "opsgenie_test")
|
||||||
require.NoError(t, err, "creating temp file failed")
|
require.NoError(t, err, "creating temp file failed")
|
||||||
_, err = f.WriteString(key)
|
_, err = f.WriteString(key)
|
||||||
require.NoError(t, err, "writing to temp file failed")
|
require.NoError(t, err, "writing to temp file failed")
|
||||||
|
@ -322,7 +323,7 @@ func TestOpsGenieWithUpdate(t *testing.T) {
|
||||||
|
|
||||||
func readBody(t *testing.T, r *http.Request) string {
|
func readBody(t *testing.T, r *http.Request) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return string(body)
|
return string(body)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
|
@ -190,7 +190,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
|
||||||
if n.conf.APIURL != nil {
|
if n.conf.APIURL != nil {
|
||||||
u = n.conf.APIURL.String()
|
u = n.conf.APIURL.String()
|
||||||
} else {
|
} else {
|
||||||
content, err := ioutil.ReadFile(n.conf.APIURLFile)
|
content, err := os.ReadFile(n.conf.APIURLFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ package slack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
|
@ -63,7 +63,7 @@ func TestGettingSlackURLFromFile(t *testing.T) {
|
||||||
ctx, u, fn := test.GetContextWithCancelingURL()
|
ctx, u, fn := test.GetContextWithCancelingURL()
|
||||||
defer fn()
|
defer fn()
|
||||||
|
|
||||||
f, err := ioutil.TempFile("", "slack_test")
|
f, err := os.CreateTemp("", "slack_test")
|
||||||
require.NoError(t, err, "creating temp file failed")
|
require.NoError(t, err, "creating temp file failed")
|
||||||
_, err = f.WriteString(u.String())
|
_, err = f.WriteString(u.String())
|
||||||
require.NoError(t, err, "writing to temp file failed")
|
require.NoError(t, err, "writing to temp file failed")
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
@ -78,7 +77,7 @@ func request(ctx context.Context, client *http.Client, method, url, bodyType str
|
||||||
// Drain consumes and closes the response's body to make sure that the
|
// Drain consumes and closes the response's body to make sure that the
|
||||||
// HTTP client can reuse existing connections.
|
// HTTP client can reuse existing connections.
|
||||||
func Drain(r *http.Response) {
|
func Drain(r *http.Response) {
|
||||||
io.Copy(ioutil.Discard, r.Body)
|
io.Copy(io.Discard, r.Body)
|
||||||
r.Body.Close()
|
r.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +160,7 @@ func readAll(r io.Reader) string {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
bs, err := ioutil.ReadAll(r)
|
bs, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -156,7 +155,7 @@ func TestRetrierCheck(t *testing.T) {
|
||||||
if status != http.StatusServiceUnavailable {
|
if status != http.StatusServiceUnavailable {
|
||||||
return "invalid"
|
return "invalid"
|
||||||
}
|
}
|
||||||
bs, _ := ioutil.ReadAll(b)
|
bs, _ := io.ReadAll(b)
|
||||||
return fmt.Sprintf("server response is %q", string(bs))
|
return fmt.Sprintf("server response is %q", string(bs))
|
||||||
}},
|
}},
|
||||||
status: http.StatusServiceUnavailable,
|
status: http.StatusServiceUnavailable,
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
@ -171,7 +171,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
|
||||||
return true, fmt.Errorf("unexpected status code %v", resp.StatusCode)
|
return true, fmt.Errorf("unexpected status code %v", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Don't flag lines such as "io.Copy(ioutil.Discard, resp.Body)".
|
// Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
|
||||||
io.Copy
|
io.Copy
|
||||||
// The next two are used in HTTP handlers, any error is handled by the server itself.
|
// The next two are used in HTTP handlers, any error is handled by the server itself.
|
||||||
io.WriteString
|
io.WriteString
|
||||||
|
|
|
@ -16,7 +16,6 @@ package silence
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -156,7 +155,7 @@ func TestSilencesSnapshot(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
f, err := ioutil.TempFile("", "snapshot")
|
f, err := os.CreateTemp("", "snapshot")
|
||||||
require.NoError(t, err, "creating temp file failed")
|
require.NoError(t, err, "creating temp file failed")
|
||||||
|
|
||||||
s1 := &Silences{st: state{}, metrics: newMetrics(nil, nil)}
|
s1 := &Silences{st: state{}, metrics: newMetrics(nil, nil)}
|
||||||
|
@ -184,7 +183,7 @@ func TestSilencesSnapshot(t *testing.T) {
|
||||||
|
|
||||||
// This tests a regression introduced by https://github.com/prometheus/alertmanager/pull/2689.
|
// This tests a regression introduced by https://github.com/prometheus/alertmanager/pull/2689.
|
||||||
func TestSilences_Maintenance_DefaultMaintenanceFuncDoesntCrash(t *testing.T) {
|
func TestSilences_Maintenance_DefaultMaintenanceFuncDoesntCrash(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "snapshot")
|
f, err := os.CreateTemp("", "snapshot")
|
||||||
require.NoError(t, err, "creating temp file failed")
|
require.NoError(t, err, "creating temp file failed")
|
||||||
clock := clock.NewMock()
|
clock := clock.NewMock()
|
||||||
s := &Silences{st: state{}, logger: log.NewNopLogger(), clock: clock, metrics: newMetrics(nil, nil)}
|
s := &Silences{st: state{}, logger: log.NewNopLogger(), clock: clock, metrics: newMetrics(nil, nil)}
|
||||||
|
@ -204,7 +203,7 @@ func TestSilences_Maintenance_DefaultMaintenanceFuncDoesntCrash(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSilences_Maintenance_SupportsCustomCallback(t *testing.T) {
|
func TestSilences_Maintenance_SupportsCustomCallback(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "snapshot")
|
f, err := os.CreateTemp("", "snapshot")
|
||||||
require.NoError(t, err, "creating temp file failed")
|
require.NoError(t, err, "creating temp file failed")
|
||||||
clock := clock.NewMock()
|
clock := clock.NewMock()
|
||||||
s := &Silences{st: state{}, logger: log.NewNopLogger(), clock: clock, metrics: newMetrics(nil, nil)}
|
s := &Silences{st: state{}, logger: log.NewNopLogger(), clock: clock, metrics: newMetrics(nil, nil)}
|
||||||
|
|
|
@ -16,7 +16,7 @@ package template
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
tmplhtml "html/template"
|
tmplhtml "html/template"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -59,7 +59,7 @@ func FromGlobs(paths ...string) (*Template, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
b, err := ioutil.ReadAll(f)
|
b, err := io.ReadAll(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -145,7 +145,7 @@ func (t *AcceptanceTest) AlertmanagerCluster(conf string, size int) *Alertmanage
|
||||||
opts: t.opts,
|
opts: t.opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "am_test")
|
dir, err := os.MkdirTemp("", "am_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ func (am *Alertmanager) Start(additionalArg []string) error {
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return fmt.Errorf("starting alertmanager failed: expected HTTP status '200', got '%d'", resp.StatusCode)
|
return fmt.Errorf("starting alertmanager failed: expected HTTP status '200', got '%d'", resp.StatusCode)
|
||||||
}
|
}
|
||||||
_, err = ioutil.ReadAll(resp.Body)
|
_, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("starting alertmanager failed: %s", err)
|
return fmt.Errorf("starting alertmanager failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -115,7 +115,7 @@ func (t *AcceptanceTest) Alertmanager(conf string) *Alertmanager {
|
||||||
opts: t.opts,
|
opts: t.opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "am_test")
|
dir, err := os.MkdirTemp("", "am_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ func (am *Alertmanager) Start() {
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
am.t.Fatalf("Starting alertmanager failed: expected HTTP status '200', got '%d'", resp.StatusCode)
|
am.t.Fatalf("Starting alertmanager failed: expected HTTP status '200', got '%d'", resp.StatusCode)
|
||||||
}
|
}
|
||||||
_, err = ioutil.ReadAll(resp.Body)
|
_, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
am.t.Fatalf("Starting alertmanager failed: %s", err)
|
am.t.Fatalf("Starting alertmanager failed: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ func (am *Alertmanager) SetSilence(at float64, sil *TestSilence) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -125,7 +124,7 @@ func (t *AcceptanceTest) AlertmanagerCluster(conf string, size int) *Alertmanage
|
||||||
opts: t.opts,
|
opts: t.opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "am_test")
|
dir, err := os.MkdirTemp("", "am_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue