mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-30 02:43:05 +00:00
Merge pull request #720 from juanfont/replace-ioutil
Replaced legacy ioutil usage
This commit is contained in:
commit
a03a99569d
5 changed files with 11 additions and 16 deletions
|
@ -1,7 +1,6 @@
|
||||||
package headscale
|
package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ func (s *Suite) ResetDB(c *check.C) {
|
||||||
os.RemoveAll(tmpDir)
|
os.RemoveAll(tmpDir)
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
tmpDir, err = ioutil.TempDir("", "autoygg-client-test")
|
tmpDir, err = os.MkdirTemp("", "autoygg-client-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -28,7 +27,7 @@ func (s *Suite) TearDownSuite(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Suite) TestConfigFileLoading(c *check.C) {
|
func (*Suite) TestConfigFileLoading(c *check.C) {
|
||||||
tmpDir, err := ioutil.TempDir("", "headscale")
|
tmpDir, err := os.MkdirTemp("", "headscale")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +72,7 @@ func (*Suite) TestConfigFileLoading(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Suite) TestConfigLoading(c *check.C) {
|
func (*Suite) TestConfigLoading(c *check.C) {
|
||||||
tmpDir, err := ioutil.TempDir("", "headscale")
|
tmpDir, err := os.MkdirTemp("", "headscale")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -117,7 +116,7 @@ func (*Suite) TestConfigLoading(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Suite) TestDNSConfigLoading(c *check.C) {
|
func (*Suite) TestDNSConfigLoading(c *check.C) {
|
||||||
tmpDir, err := ioutil.TempDir("", "headscale")
|
tmpDir, err := os.MkdirTemp("", "headscale")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -152,14 +151,14 @@ func (*Suite) TestDNSConfigLoading(c *check.C) {
|
||||||
func writeConfig(c *check.C, tmpDir string, configYaml []byte) {
|
func writeConfig(c *check.C, tmpDir string, configYaml []byte) {
|
||||||
// Populate a custom config file
|
// Populate a custom config file
|
||||||
configFile := filepath.Join(tmpDir, "config.yaml")
|
configFile := filepath.Join(tmpDir, "config.yaml")
|
||||||
err := ioutil.WriteFile(configFile, configYaml, 0o600)
|
err := os.WriteFile(configFile, configYaml, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatalf("Couldn't write file %s", configFile)
|
c.Fatalf("Couldn't write file %s", configFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Suite) TestTLSConfigValidation(c *check.C) {
|
func (*Suite) TestTLSConfigValidation(c *check.C) {
|
||||||
tmpDir, err := ioutil.TempDir("", "headscale")
|
tmpDir, err := os.MkdirTemp("", "headscale")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
3
derp.go
3
derp.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -50,7 +49,7 @@ func loadDERPMapFromURL(addr url.URL) (*tailcfg.DERPMap, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -362,7 +361,7 @@ func (s *IntegrationDERPTestSuite) saveLog(
|
||||||
|
|
||||||
log.Printf("Saving logs for %s to %s\n", resource.Container.Name, basePath)
|
log.Printf("Saving logs for %s to %s\n", resource.Container.Name, basePath)
|
||||||
|
|
||||||
err = ioutil.WriteFile(
|
err = os.WriteFile(
|
||||||
path.Join(basePath, resource.Container.Name+".stdout.log"),
|
path.Join(basePath, resource.Container.Name+".stdout.log"),
|
||||||
[]byte(stdout.String()),
|
[]byte(stdout.String()),
|
||||||
0o644,
|
0o644,
|
||||||
|
@ -371,7 +370,7 @@ func (s *IntegrationDERPTestSuite) saveLog(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(
|
err = os.WriteFile(
|
||||||
path.Join(basePath, resource.Container.Name+".stderr.log"),
|
path.Join(basePath, resource.Container.Name+".stderr.log"),
|
||||||
[]byte(stdout.String()),
|
[]byte(stdout.String()),
|
||||||
0o644,
|
0o644,
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -124,7 +123,7 @@ func (s *IntegrationTestSuite) saveLog(
|
||||||
|
|
||||||
log.Printf("Saving logs for %s to %s\n", resource.Container.Name, basePath)
|
log.Printf("Saving logs for %s to %s\n", resource.Container.Name, basePath)
|
||||||
|
|
||||||
err = ioutil.WriteFile(
|
err = os.WriteFile(
|
||||||
path.Join(basePath, resource.Container.Name+".stdout.log"),
|
path.Join(basePath, resource.Container.Name+".stdout.log"),
|
||||||
[]byte(stdout.String()),
|
[]byte(stdout.String()),
|
||||||
0o644,
|
0o644,
|
||||||
|
@ -133,7 +132,7 @@ func (s *IntegrationTestSuite) saveLog(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(
|
err = os.WriteFile(
|
||||||
path.Join(basePath, resource.Container.Name+".stderr.log"),
|
path.Join(basePath, resource.Container.Name+".stderr.log"),
|
||||||
[]byte(stdout.String()),
|
[]byte(stdout.String()),
|
||||||
0o644,
|
0o644,
|
||||||
|
|
Loading…
Reference in a new issue