Skip to content

Commit

Permalink
fix: linting issues, failing unit test for spdx parser
Browse files Browse the repository at this point in the history
Signed-off-by: boranx <boran.seref@gmail.com>
  • Loading branch information
boranx committed Mar 28, 2023
1 parent 9f6c36d commit ecb2f92
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions builtins/parse_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package builtins
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/open-policy-agent/conftest/parser"
Expand Down Expand Up @@ -97,7 +97,7 @@ func parseConfigFile(bctx rego.BuiltinContext, op1 *ast.Term) (*ast.Term, error)
if err != nil {
return nil, fmt.Errorf("create config parser: %w", err)
}
contents, err := ioutil.ReadFile(filePath)
contents, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("read config file %s: %w", filePath, err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/commands/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/open-policy-agent/opa/format"
Expand Down Expand Up @@ -40,7 +39,7 @@ func NewFormatCommand() *cobra.Command {
return fmt.Errorf("stat: %w", err)
}

contents, err := ioutil.ReadFile(policy.Package.Location.File)
contents, err := os.ReadFile(policy.Package.Location.File)
if err != nil {
return fmt.Errorf("read policy: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parser
import (
"bufio"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -297,7 +297,7 @@ func parseConfigurations(paths []string, parser string) (map[string]interface{},

func getConfigurationContent(path string) ([]byte, error) {
if path == "-" {
contents, err := ioutil.ReadAll(bufio.NewReader(os.Stdin))
contents, err := io.ReadAll(bufio.NewReader(os.Stdin))
if err != nil {
return nil, fmt.Errorf("read standard in: %w", err)
}
Expand All @@ -310,7 +310,7 @@ func getConfigurationContent(path string) ([]byte, error) {
return nil, fmt.Errorf("get abs: %w", err)
}

contents, err := ioutil.ReadFile(filePath)
contents, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("open file: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions parser/spdx/spdx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Created: 2021-08-26T01:46:00Z
}

inputMap := input.(map[string]interface{})
creationInfo := inputMap["CreationInfo"].(map[string]interface{})
currentDataLicense := creationInfo["DataLicense"]
currentDataLicense := inputMap["dataLicense"]
expectedDataLicense := "conftest-demo"
if currentDataLicense != expectedDataLicense {
t.Errorf("DataLicense of the SPDX file have: %s, want: %s", currentDataLicense, expectedDataLicense)
Expand Down
3 changes: 1 addition & 2 deletions plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plugin
import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -87,7 +86,7 @@ func installFromURL(ctx context.Context, url string) error {
// Before allowing the plugin to be stored in the plugin directory,
// make sure the plugin has a valid configuration file by first downloading
// the plugin into a temporary directory and validating its configuration.
tempDirectory, err := ioutil.TempDir(CacheDirectory(), "conftest-plugin-*")
tempDirectory, err := os.MkdirTemp(CacheDirectory(), "conftest-plugin-*")
if err != nil {
return fmt.Errorf("create tmp dir: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plugin
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -52,7 +51,7 @@ func FindAll() ([]*Plugin, error) {
return []*Plugin{}, nil
}

files, err := ioutil.ReadDir(CacheDirectory())
files, err := os.ReadDir(CacheDirectory())
if err != nil {
return nil, fmt.Errorf("read plugin cache: %w", err)
}
Expand Down Expand Up @@ -155,7 +154,7 @@ func FromDirectory(directory string) (*Plugin, error) {
const configurationFileName = "plugin.yaml"

configPath := filepath.Join(directory, configurationFileName)
data, err := ioutil.ReadFile(configPath)
data, err := os.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("read config: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions plugin/xdg_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package plugin

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -151,7 +150,7 @@ func TestFind(t *testing.T) {
}

dir := filepath.ToSlash(filepath.Join(homeDir))
tmp, err := ioutil.TempDir(dir, "")
tmp, err := os.MkdirTemp(dir, "")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -191,7 +190,7 @@ func TestFind(t *testing.T) {
}

dir := filepath.ToSlash(filepath.Join(homeDir))
tmp, err := ioutil.TempDir(dir, "")
tmp, err := os.MkdirTemp(dir, "")
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions policy/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -136,7 +135,7 @@ func LoadWithData(policyPaths []string, dataPaths []string, capabilities string,

documentContents := make(map[string]string)
for _, documentPath := range allDocumentPaths {
contents, err := ioutil.ReadFile(documentPath)
contents, err := os.ReadFile(documentPath)
if err != nil {
return nil, fmt.Errorf("read file: %w", err)
}
Expand Down

0 comments on commit ecb2f92

Please sign in to comment.