Skip to content

Commit

Permalink
chore: make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Feb 17, 2023
1 parent 33abec5 commit 2a12f0c
Show file tree
Hide file tree
Showing 36 changed files with 117 additions and 136 deletions.
3 changes: 1 addition & 2 deletions cmd/util/json-schema-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -99,7 +98,7 @@ func generate(crdFilename, dslFilename, path string, isArray bool, destination s
if err != nil {
return err
}
return ioutil.WriteFile(destination, result, 0o600)
return os.WriteFile(destination, result, 0o600)
}

func remapRef(ref string) string {
Expand Down
3 changes: 1 addition & 2 deletions cmd/util/vfs-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -144,7 +143,7 @@ limitations under the License.
var finalContent []byte
finalContent = append(finalContent, []byte(header)...)
finalContent = append(finalContent, content...)
if err := ioutil.WriteFile(resourceFile, finalContent, 0o600); err != nil {
if err := os.WriteFile(resourceFile, finalContent, 0o600); err != nil {
log.Fatalln(err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/global/common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package resources

import (
"fmt"
"io/ioutil"
"os"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestRunConfigExamples(t *testing.T) {

t.Run("Base64 compressed binary resource file", func(t *testing.T) {
// We calculate the expected content
source, err := ioutil.ReadFile("./files/resources-data.txt")
source, err := os.ReadFile("./files/resources-data.txt")
assert.Nil(t, err)
expectedBytes, err := gzip.CompressBase64([]byte(source))
assert.Nil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions e2e/global/common/traits/jvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ limitations under the License.
package traits

import (
"io/ioutil"
"os"
"testing"

. "github.com/onsi/gomega"
Expand All @@ -43,7 +43,7 @@ func TestJVMTrait(t *testing.T) {
// Store a configmap holding a jar
var cmData = make(map[string][]byte)
// We calculate the expected content
source, err := ioutil.ReadFile("./files/jvm/sample-1.0.jar")
source, err := os.ReadFile("./files/jvm/sample-1.0.jar")
assert.Nil(t, err)
cmData["sample-1.0.jar"] = source
err = CreateBinaryConfigmap(ns, "my-deps", cmData)
Expand Down
3 changes: 1 addition & 2 deletions e2e/global/common/traits/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ limitations under the License.
package traits

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -89,7 +88,7 @@ func TestOpenAPIConfigmap(t *testing.T) {
operatorID := "camel-k-trait-openapi-configmap"
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())

openapiContent, err := ioutil.ReadFile("./files/openapi/petstore-api.yaml")
openapiContent, err := os.ReadFile("./files/openapi/petstore-api.yaml")
assert.Nil(t, err)
var cmDataProps = make(map[string]string)
cmDataProps["petstore-api.yaml"] = string(openapiContent)
Expand Down
7 changes: 3 additions & 4 deletions e2e/namespace/install/cli/dev_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -123,11 +122,11 @@ func TestRunDevMode(t *testing.T) {
t.Run("Dev mode resource file generated configmap", func(t *testing.T) {
var tmpFile *os.File
var err error
if tmpFile, err = ioutil.TempFile("", "camel-k-"); err != nil {
if tmpFile, err = os.CreateTemp("", "camel-k-"); err != nil {
t.Error(err)
}
assert.Nil(t, tmpFile.Close())
assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte("Hello from test!"), 0o644))
assert.Nil(t, os.WriteFile(tmpFile.Name(), []byte("Hello from test!"), 0o644))

RegisterTestingT(t)
ctx, cancel := context.WithCancel(TestContext)
Expand Down Expand Up @@ -161,7 +160,7 @@ func TestRunDevMode(t *testing.T) {
Expect(logScanner.IsFound("Goodbye from test!")()).To(BeFalse())

// cool, now let's change the file to confirm the sync take place
assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte("Goodbye from test!"), 0o644))
assert.Nil(t, os.WriteFile(tmpFile.Name(), []byte("Goodbye from test!"), 0o644))
Eventually(logScanner.IsFound("Goodbye from test!"), TestTimeoutMedium).Should(BeTrue())

Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
Expand Down
10 changes: 5 additions & 5 deletions e2e/namespace/install/cli/offline_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ limitations under the License.
package common

import (
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -37,21 +37,21 @@ func TestKamelVersionWorksOffline(t *testing.T) {

func TestKamelHelpTraitWorksOffline(t *testing.T) {
traitCmd := Kamel("help", "trait", "--all", "--kube-config", "non-existent-kubeconfig-file")
traitCmd.SetOut(ioutil.Discard)
traitCmd.SetOut(io.Discard)
assert.Nil(t, traitCmd.Execute())
}

func TestKamelHelpOptionWorksOffline(t *testing.T) {
traitCmd := Kamel("run", "Xxx.java", "--help")
traitCmd.SetOut(ioutil.Discard)
traitCmd.SetOut(io.Discard)
assert.Nil(t, traitCmd.Execute())
}

func TestKamelCompletionWorksOffline(t *testing.T) {
bashCmd := Kamel("completion", "bash", "--kube-config", "non-existent-kubeconfig-file")
bashCmd.SetOut(ioutil.Discard)
bashCmd.SetOut(io.Discard)
zshCmd := Kamel("completion", "zsh", "--kube-config", "non-existent-kubeconfig-file")
zshCmd.SetOut(ioutil.Discard)
zshCmd.SetOut(io.Discard)
assert.Nil(t, bashCmd.Execute())
assert.Nil(t, zshCmd.Execute())
}
3 changes: 1 addition & 2 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"reflect"
Expand Down Expand Up @@ -476,7 +475,7 @@ func Logs(ns, podName string, options corev1.PodLogOptions) func() string {
}
}()

bytes, err := ioutil.ReadAll(byteReader)
bytes, err := io.ReadAll(byteReader)
if err != nil {
log.Error(err, "Error while reading container logs")
return ""
Expand Down
5 changes: 2 additions & 3 deletions pkg/builder/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.
package builder

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -88,7 +87,7 @@ func executableDockerfile(ctx *builderContext) error {
USER nonroot
`)

err := ioutil.WriteFile(filepath.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0o400)
err := os.WriteFile(filepath.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0o400)
if err != nil {
return err
}
Expand All @@ -112,7 +111,7 @@ func jvmDockerfile(ctx *builderContext) error {
USER 1000
`)

err := ioutil.WriteFile(filepath.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0o400)
err := os.WriteFile(filepath.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0o400)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/builder/s2i.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func (t *s2iTask) Do(ctx context.Context) v1.BuildStatus {
err = t.waitForS2iBuildCompletion(ctx, t.c, &s2iBuild)
if err != nil {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
// nolint: contextcheck
if err := t.cancelBuild(context.Background(), &s2iBuild); err != nil {
log.Errorf(err, "cannot cancel s2i Build: %s/%s", s2iBuild.Namespace, s2iBuild.Name)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/builder/spectrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"bufio"
"context"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -159,7 +158,7 @@ func readSpectrumLogs(newStdOut io.Reader) {
}

func MountSecret(ctx context.Context, c client.Client, namespace, name string) (string, error) {
dir, err := ioutil.TempDir("", "spectrum-secret-")
dir, err := os.MkdirTemp("", "spectrum-secret-")
if err != nil {
return "", err
}
Expand All @@ -173,7 +172,7 @@ func MountSecret(ctx context.Context, c client.Client, namespace, name string) (
}

for file, content := range secret.Data {
if err := ioutil.WriteFile(filepath.Join(dir, remap(file)), content, 0o600); err != nil {
if err := os.WriteFile(filepath.Join(dir, remap(file)), content, 0o600); err != nil {
if removeErr := os.RemoveAll(dir); removeErr != nil {
err = multierr.Append(err, removeErr)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package client

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -296,7 +295,7 @@ func shouldUseContainerMode() (bool, error) {
func getNamespaceFromKubernetesContainer() (string, error) {
var nsba []byte
var err error
if nsba, err = ioutil.ReadFile(inContainerNamespaceFile); err != nil {
if nsba, err = os.ReadFile(inContainerNamespaceFile); err != nil {
return "", err
}
return string(nsba), nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package builder
import (
"context"
"fmt"
"io/ioutil"
"math/rand"
"os"
"os/signal"
Expand Down Expand Up @@ -108,7 +107,7 @@ func exitOnError(err error, msg string) {

func writeTerminationMessage(message string) {
// #nosec G306
err := ioutil.WriteFile(terminationMessagePath, []byte(message), 0o644)
err := os.WriteFile(terminationMessagePath, []byte(message), 0o644)
if err != nil {
log.Error(err, "cannot write termination message")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/cmd/local/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"os/signal"
Expand All @@ -37,7 +36,7 @@ import (

// CreateDockerBaseWorkingDirectory creates local docker base directory.
func CreateDockerBaseWorkingDirectory() error {
temporaryDirectory, err := ioutil.TempDir(os.TempDir(), "docker-base-")
temporaryDirectory, err := os.MkdirTemp(os.TempDir(), "docker-base-")
if err != nil {
return err
}
Expand All @@ -55,7 +54,7 @@ func DeleteDockerBaseWorkingDirectory() error {

// CreateDockerWorkingDirectory creates local docker directory.
func CreateDockerWorkingDirectory() error {
temporaryDirectory, err := ioutil.TempDir(os.TempDir(), "docker-")
temporaryDirectory, err := os.MkdirTemp(os.TempDir(), "docker-")
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/cmd/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -165,7 +164,7 @@ func getTransitiveDependencies(ctx context.Context, catalog *camel.RuntimeCatalo

func getRegularFilesInDir(directory string, dirnameInPath bool) ([]string, error) {
var dirFiles []string
files, err := ioutil.ReadDir(directory)
files, err := os.ReadDir(directory)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -384,7 +383,7 @@ func UpdateIntegrationProperties(properties []string, propertyFiles []string, ha
// Output list of properties to property file if any CLI properties were given.
if len(properties) > 0 {
propertyFilePath := filepath.Join(dir, "CLI.properties")
if err := ioutil.WriteFile(propertyFilePath, []byte(strings.Join(properties, "\n")), 0o600); err != nil {
if err := os.WriteFile(propertyFilePath, []byte(strings.Join(properties, "\n")), 0o600); err != nil {
return nil, err
}
relocatedPropertyFiles = append(relocatedPropertyFiles, propertyFilePath)
Expand Down
9 changes: 4 additions & 5 deletions pkg/cmd/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.
package local

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -29,12 +28,12 @@ import (
func TestValidatePropertyFiles_ShouldSucceed(t *testing.T) {
var tmpFile1 *os.File
var err error
if tmpFile1, err = ioutil.TempFile("", "camel-k-*.properties"); err != nil {
if tmpFile1, err = os.CreateTemp("", "camel-k-*.properties"); err != nil {
t.Error(err)
}

assert.Nil(t, tmpFile1.Close())
assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte("key=value"), 0o400))
assert.Nil(t, os.WriteFile(tmpFile1.Name(), []byte("key=value"), 0o400))

inputValues := []string{tmpFile1.Name()}
err = ValidatePropertyFiles(inputValues)
Expand All @@ -45,12 +44,12 @@ func TestValidatePropertyFiles_ShouldSucceed(t *testing.T) {
func TestValidatePropertyFiles_ShouldFailNotAPropertiesFile(t *testing.T) {
var tmpFile1 *os.File
var err error
if tmpFile1, err = ioutil.TempFile("", "camel-k-"); err != nil {
if tmpFile1, err = os.CreateTemp("", "camel-k-"); err != nil {
t.Error(err)
}

assert.Nil(t, tmpFile1.Close())
assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte("key=value"), 0o400))
assert.Nil(t, os.WriteFile(tmpFile1.Name(), []byte("key=value"), 0o400))

inputValues := []string{tmpFile1.Name()}
err = ValidatePropertyFiles(inputValues)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/local/workdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.
package local

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -33,7 +32,7 @@ var MavenWorkingDirectory = ""

// CreateMavenWorkingDirectory creates local Maven working directory.
func CreateMavenWorkingDirectory() error {
temporaryDirectory, err := ioutil.TempDir(os.TempDir(), "maven-")
temporaryDirectory, err := os.MkdirTemp(os.TempDir(), "maven-")
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 2a12f0c

Please sign in to comment.