From 395392c6f0a4b504a8d27378f442f66109817051 Mon Sep 17 00:00:00 2001 From: Best Olunusi Date: Tue, 20 Aug 2024 21:58:58 -0500 Subject: [PATCH 01/17] feat: add support for pkl files --- .github/workflows/golangci-lint.yml | 2 +- README.md | 5 +++-- cmd/validator/validator.go | 2 +- go.mod | 7 +++++-- go.sum | 8 ++++++++ index.md | 5 +++-- pkg/filetype/file_type.go | 9 ++++++++ pkg/validator/pkl.go | 32 +++++++++++++++++++++++++++++ pkg/validator/validator_test.go | 2 ++ test/fixtures/good.pkl | 7 +++++++ test/fixtures/subdir2/bad.pkl | 1 + 11 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 pkg/validator/pkl.go create mode 100644 test/fixtures/good.pkl create mode 100644 test/fixtures/subdir2/bad.pkl diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 203e826b..bcedc8e1 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -15,7 +15,7 @@ jobs: golangci: strategy: matrix: - go: ['1.21'] + go: ['1.22'] os: [ubuntu-latest, macos-latest, windows-latest] permissions: # Optional: Allow write access to checks to allow the action to annotate code in the PR. diff --git a/README.md b/README.md index 7d1fbeed..26a11d1f 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ * INI * JSON * Properties +* PKL * TOML * XML * YAML @@ -136,7 +137,7 @@ validator --exclude-dirs=/path/to/search/tests /path/to/search ![Exclude Dirs Run](./img/exclude_dirs.png) #### Exclude file types -Exclude file types in the search path. Available file types are `csv`, `env`, `hcl`, `hocon`, `ini`, `json`, `plist`, `properties`, `toml`, `xml`, `yaml`, and `yml` +Exclude file types in the search path. Available file types are `csv`, `env`, `hcl`, `hocon`, `ini`, `json`, `plist`, `properties`, `pkl`, `toml`, `xml`, `yaml`, and `yml` ``` validator --exclude-file-types=json /path/to/search @@ -200,7 +201,7 @@ docker run -it --rm -v /path/to/config/files:/test config-file-validator:1.6.0 / ![Docker Standard Run](./img/docker_run.png) ## Build -The project can be downloaded and built from source using an environment with Go 1.21+ installed. After a successful build, the binary can be moved to a location on your operating system PATH. +The project can be downloaded and built from source using an environment with Go 1.22.1+ installed. After a successful build, the binary can be moved to a location on your operating system PATH. ### macOS #### Build diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index 63fceebc..36692f1b 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -2,7 +2,7 @@ Validator recursively scans a directory to search for configuration files and validates them using the go package for each configuration type. -Currently Apple PList XML, CSV, HCL, HOCON, INI, JSON, Properties, TOML, XML, and YAML. +Currently Apple PList XML, PKL, CSV, HCL, HOCON, INI, JSON, Properties, TOML, XML, and YAML. configuration file types are supported. Usage: validator [OPTIONS] [...] diff --git a/go.mod b/go.mod index 8d4165c0..6e762247 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Boeing/config-file-validator -go 1.21 +go 1.22.1 require ( github.com/fatih/color v1.13.0 @@ -8,7 +8,7 @@ require ( github.com/hashicorp/hcl/v2 v2.18.1 github.com/magiconair/properties v1.8.7 github.com/pelletier/go-toml/v2 v2.0.6 - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.9.0 gopkg.in/ini.v1 v1.67.0 gopkg.in/yaml.v3 v3.0.1 howett.net/plist v1.0.0 @@ -18,6 +18,7 @@ require ( github.com/agext/levenshtein v1.2.1 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/apple/pkl-go v0.8.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/editorconfig/editorconfig-core-go/v2 v2.6.2 // indirect github.com/google/go-cmp v0.6.0 // indirect @@ -26,6 +27,8 @@ require ( github.com/mattn/go-isatty v0.0.14 // indirect github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect + github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.13.0 // indirect golang.org/x/mod v0.16.0 // indirect golang.org/x/sync v0.2.0 // indirect diff --git a/go.sum b/go.sum index d15544fc..e18f6e10 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6 github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/apple/pkl-go v0.8.0 h1:GRcBvFWeXjT9rc7A5gHK89qrel2wGZ3/a7ge4rPlT5M= +github.com/apple/pkl-go v0.8.0/go.mod h1:5Hwil5tyZGrOekh7JXLZJvIAcGHb4gT19lnv4WEiKeI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -49,6 +51,12 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= +github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= +github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= +github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/zclconf/go-cty v1.13.0 h1:It5dfKTTZHe9aeppbNOda3mN7Ag7sg6QkBNm6TkyFa0= github.com/zclconf/go-cty v1.13.0/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= diff --git a/index.md b/index.md index 2c740ee1..4551e851 100644 --- a/index.md +++ b/index.md @@ -60,6 +60,7 @@ * INI * JSON * Properties +* PKL * TOML * XML * YAML @@ -150,7 +151,7 @@ validator --exclude-dirs=/path/to/search/tests /path/to/search ![Exclude Dirs Run](./img/exclude_dirs.png) #### Exclude file types -Exclude file types in the search path. Available file types are `csv`, `env`, `hcl`, `hocon`, `ini`, `json`, `plist`, `properties`, `toml`, `xml`, `yaml`, and `yml` +Exclude file types in the search path. Available file types are `csv`, `env`, `hcl`, `hocon`, `ini`, `json`, `plist`, `properties`, `pkl`, `toml`, `xml`, `yaml`, and `yml` ``` validator --exclude-file-types=json /path/to/search @@ -214,7 +215,7 @@ docker run -it --rm -v /path/to/config/files:/test config-file-validator:1.6.0 / ![Docker Standard Run](./img/docker_run.png) ## Build -The project can be downloaded and built from source using an environment with Go 1.21+ installed. After a successful build, the binary can be moved to a location on your operating system PATH. +The project can be downloaded and built from source using an environment with Go 1.22.1+ installed. After a successful build, the binary can be moved to a location on your operating system PATH. ### macOS #### Build diff --git a/pkg/filetype/file_type.go b/pkg/filetype/file_type.go index 97f4c7bc..bd9fed4b 100644 --- a/pkg/filetype/file_type.go +++ b/pkg/filetype/file_type.go @@ -63,6 +63,14 @@ var PropFileType = FileType{ validator.PropValidator{}, } +// Instance of the FileType object to +// represent a Pkl file +var PklFileType = FileType{ + "pkl", + misc.ArrToMap("pkl"), + validator.PklValidator{}, +} + // Instance of the FileType object to // represent a HCL file var HclFileType = FileType{ @@ -120,6 +128,7 @@ var FileTypes = []FileType{ TomlFileType, IniFileType, PropFileType, + PklFileType, HclFileType, PlistFileType, CsvFileType, diff --git a/pkg/validator/pkl.go b/pkg/validator/pkl.go new file mode 100644 index 00000000..48b65007 --- /dev/null +++ b/pkg/validator/pkl.go @@ -0,0 +1,32 @@ +package validator + +import ( + "context" + "fmt" + + "github.com/apple/pkl-go/pkl" +) + +// PklValidator is used to validate a byte slice that is intended to represent a +// PKL file. +type PklValidator struct{} + +// Validate attempts to evaluate the provided byte slice as a PKL file. +func (PklValidator) Validate(b []byte) (bool, error) { + ctx := context.Background() + + // Convert the byte slice to a ModuleSource using TextSource + source := pkl.TextSource(string(b)) + + evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) + if err != nil { + return false, fmt.Errorf("failed to create evaluator: %w", err) + } + + _, err = evaluator.EvaluateExpressionRaw(ctx, source, "") + if err != nil { + return false, fmt.Errorf("failed to evaluate module: %w", err) + } + + return true, nil +} diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index 210af41d..93b43d40 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -55,6 +55,8 @@ var testData = []struct { {"invalidIni", []byte(`\nCatalog hidden\n`), false, IniValidator{}}, {"validProperties", []byte("key=value\nkey2=${key}"), true, PropValidator{}}, {"invalidProperties", []byte("key=${key}"), false, PropValidator{}}, + {"validPkl", []byte(`name = "Swallow"`), true, PklValidator{}}, + {"invalidPkl", []byte(`"name" = "Swallow"`), false, PklValidator{}}, {"validHcl", []byte(`key = "value"`), true, HclValidator{}}, {"invalidHcl", []byte(`"key" = "value"`), false, HclValidator{}}, {"multipleInvalidHcl", []byte(`"key1" = "value1"\n"key2"="value2"`), false, HclValidator{}}, diff --git a/test/fixtures/good.pkl b/test/fixtures/good.pkl new file mode 100644 index 00000000..9d4c336a --- /dev/null +++ b/test/fixtures/good.pkl @@ -0,0 +1,7 @@ +name = "Swallow" + +job { + title = "Sr. Nest Maker" + company = "Nests R Us" + yearsOfExperience = 2 +} diff --git a/test/fixtures/subdir2/bad.pkl b/test/fixtures/subdir2/bad.pkl new file mode 100644 index 00000000..50a269a4 --- /dev/null +++ b/test/fixtures/subdir2/bad.pkl @@ -0,0 +1 @@ +"invalid" From b706fe9005e74fbd706b88c10ecc40ff85d0111f Mon Sep 17 00:00:00 2001 From: Best Olunusi Date: Sun, 1 Sep 2024 19:52:50 -0500 Subject: [PATCH 02/17] feat: skip pkl files when binary isn't in PATH --- .github/workflows/go.yml | 5 +++++ README.md | 2 +- index.md | 2 +- pkg/cli/cli.go | 15 +++++++++++++++ pkg/cli/cli_test.go | 27 +++++++++++++++++++++++++++ pkg/validator/validator_test.go | 13 +++++++++++++ 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index edabd2ff..82421109 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -97,6 +97,11 @@ jobs: with: go-version: '1.22' + - name: Set up pkl + uses: pkl-community/setup-pkl@5bb6ac805eb51c448837ec34e9957a18adab927d # main + with: + pkl-version: '0.26.3' + - name: Unit test run: go test -v -cover -coverprofile coverage.out ./... diff --git a/README.md b/README.md index 26a11d1f..5e765f49 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ * INI * JSON * Properties -* PKL +* PKL _(requires that the `pkl` binary is installed; `.pkl` files will be ignored if the binary is not installed)_ * TOML * XML * YAML diff --git a/index.md b/index.md index 4551e851..306c5c38 100644 --- a/index.md +++ b/index.md @@ -60,7 +60,7 @@ * INI * JSON * Properties -* PKL +* PKL _(requires that the `pkl` binary is installed; `.pkl` files will be ignored if the binary is not installed)_ * TOML * XML * YAML diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 3a702074..30aac387 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -3,6 +3,7 @@ package cli import ( "fmt" "os" + "os/exec" "github.com/Boeing/config-file-validator/pkg/finder" "github.com/Boeing/config-file-validator/pkg/reporter" @@ -73,6 +74,12 @@ func Init(opts ...Option) *CLI { return cli } +// Check if the 'pkl' binary is present in the PATH +var isPklBinaryPresent = func() bool { + _, err := exec.LookPath("pkl") + return err == nil +} + // The Run method performs the following actions: // - Finds the calls the Find method from the Finder interface to // return a list of files @@ -88,6 +95,14 @@ func (c CLI) Run() (int, error) { } for _, fileToValidate := range foundFiles { + // Pkl validation requires the 'pkl' binary to be present + if fileToValidate.FileType.Name == "pkl" { + if !isPklBinaryPresent() { + fmt.Printf("Warning: 'pkl' binary not found, file %s will be ignored.\n", fileToValidate.Path) + continue + } + } + // read it fileContent, err := os.ReadFile(fileToValidate.Path) if err != nil { diff --git a/pkg/cli/cli_test.go b/pkg/cli/cli_test.go index 87a1fdfb..4257fc7a 100644 --- a/pkg/cli/cli_test.go +++ b/pkg/cli/cli_test.go @@ -121,3 +121,30 @@ func Test_CLIRepoertErr(t *testing.T) { t.Errorf("should return err status code: %d", exitStatus) } } + +func Test_CLI_IgnoreBadPklFileWhenBinaryNotFound(t *testing.T) { + // Save the original function before mocking and restore it after the test + originalIsPklBinaryPresent := isPklBinaryPresent + isPklBinaryPresent = func() bool { + return false + } + defer func() { isPklBinaryPresent = originalIsPklBinaryPresent }() + + searchPath := "../../test/fixtures/subdir2/bad.pkl" + fsFinder := finder.FileSystemFinderInit( + finder.WithPathRoots(searchPath), + ) + cli := Init( + WithFinder(fsFinder), + ) + exitStatus, err := cli.Run() + if err != nil { + t.Errorf("An error was returned: %v", err) + } + + // Since the pkl binary is not found, the bad pkl file should be ignored + // So the exit status should be 0 + if exitStatus != 0 { + t.Errorf("Expected exit status 0, but got: %d", exitStatus) + } +} diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index 93b43d40..28767b2f 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -2,6 +2,7 @@ package validator import ( _ "embed" + "os/exec" "testing" ) @@ -72,6 +73,11 @@ var testData = []struct { {"invalidEditorConfig", []byte("[*.md\nworking=false"), false, EditorConfigValidator{}}, } +func isPklBinaryPresent() bool { + _, err := exec.LookPath("pkl") + return err == nil +} + func Test_ValidationInput(t *testing.T) { t.Parallel() @@ -81,6 +87,13 @@ func Test_ValidationInput(t *testing.T) { t.Run(tcase.name, func(t *testing.T) { t.Parallel() + // Skip PklValidator tests if the pkl binary is not present + if _, ok := tcase.validator.(PklValidator); ok { + if !isPklBinaryPresent() { + t.Skip("Skipping test: 'pkl' binary not found.") + } + } + valid, err := tcase.validator.Validate(tcase.testInput) if valid != tcase.expectedResult { t.Errorf("incorrect result: expected %v, got %v", tcase.expectedResult, valid) From 1fb119bacd1157138863b12e94007fd447860210 Mon Sep 17 00:00:00 2001 From: Best Olunusi Date: Mon, 2 Sep 2024 16:16:38 -0500 Subject: [PATCH 03/17] chore: use the new action tag in ref comment --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 82421109..a533a2b9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -98,7 +98,7 @@ jobs: go-version: '1.22' - name: Set up pkl - uses: pkl-community/setup-pkl@5bb6ac805eb51c448837ec34e9957a18adab927d # main + uses: pkl-community/setup-pkl@5bb6ac805eb51c448837ec34e9957a18adab927d # v0.0.5 with: pkl-version: '0.26.3' From 2e01953467504ddec4c581463a6eaafc9135111d Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Tue, 7 Oct 2025 12:04:12 +0530 Subject: [PATCH 04/17] fix(test): resolve data race in pkl validation test The existing test for ignoring PKL files when the binary is missing was not safe for parallel execution, as it modified a global function variable, creating a data race condition. This commit resolves the issue by refactoring the validation logic: 1. The responsibility for checking for the pkl binary is moved from the CLI into the `PklValidator`. 2. The validator now returns a specific `ErrSkipped` error if the binary is not found. 3. A thread-safe `SetPklBinaryChecker` function is introduced, allowing tests to safely mock the check. 4. The test is updated to use this new thread-safe mechanism. --- pkg/cli/cli.go | 22 +++++++--------------- pkg/cli/cli_test.go | 10 +++++----- pkg/validator/pkl.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 30aac387..fb3bda23 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -1,12 +1,13 @@ package cli import ( + "errors" "fmt" "os" - "os/exec" "github.com/Boeing/config-file-validator/pkg/finder" "github.com/Boeing/config-file-validator/pkg/reporter" + "github.com/Boeing/config-file-validator/pkg/validator" ) // GroupOutput is a global variable that is used to @@ -74,12 +75,6 @@ func Init(opts ...Option) *CLI { return cli } -// Check if the 'pkl' binary is present in the PATH -var isPklBinaryPresent = func() bool { - _, err := exec.LookPath("pkl") - return err == nil -} - // The Run method performs the following actions: // - Finds the calls the Find method from the Finder interface to // return a list of files @@ -95,14 +90,6 @@ func (c CLI) Run() (int, error) { } for _, fileToValidate := range foundFiles { - // Pkl validation requires the 'pkl' binary to be present - if fileToValidate.FileType.Name == "pkl" { - if !isPklBinaryPresent() { - fmt.Printf("Warning: 'pkl' binary not found, file %s will be ignored.\n", fileToValidate.Path) - continue - } - } - // read it fileContent, err := os.ReadFile(fileToValidate.Path) if err != nil { @@ -110,6 +97,11 @@ func (c CLI) Run() (int, error) { } isValid, err := fileToValidate.FileType.Validator.Validate(fileContent) + if errors.Is(err, validator.ErrSkipped) { + fmt.Printf("Warning: 'pkl' binary not found, file %s will be ignored.\n", fileToValidate.Path) + continue + } + if !isValid { errorFound = true } diff --git a/pkg/cli/cli_test.go b/pkg/cli/cli_test.go index 4257fc7a..508e03ee 100644 --- a/pkg/cli/cli_test.go +++ b/pkg/cli/cli_test.go @@ -5,6 +5,7 @@ import ( "github.com/Boeing/config-file-validator/pkg/finder" "github.com/Boeing/config-file-validator/pkg/reporter" + "github.com/Boeing/config-file-validator/pkg/validator" ) func Test_CLI(t *testing.T) { @@ -123,12 +124,11 @@ func Test_CLIRepoertErr(t *testing.T) { } func Test_CLI_IgnoreBadPklFileWhenBinaryNotFound(t *testing.T) { - // Save the original function before mocking and restore it after the test - originalIsPklBinaryPresent := isPklBinaryPresent - isPklBinaryPresent = func() bool { + // Override the binary checker for this test and restore it afterward + previousChecker := validator.SetPklBinaryChecker(func() bool { return false - } - defer func() { isPklBinaryPresent = originalIsPklBinaryPresent }() + }) + defer validator.SetPklBinaryChecker(previousChecker) searchPath := "../../test/fixtures/subdir2/bad.pkl" fsFinder := finder.FileSystemFinderInit( diff --git a/pkg/validator/pkl.go b/pkg/validator/pkl.go index 48b65007..344815e5 100644 --- a/pkg/validator/pkl.go +++ b/pkg/validator/pkl.go @@ -2,17 +2,51 @@ package validator import ( "context" + "errors" "fmt" + "os/exec" + "sync" "github.com/apple/pkl-go/pkl" ) +var ( + // ErrSkipped is returned when a validation is skipped due to a missing dependency. + ErrSkipped = errors.New("validation skipped") + + isPklBinaryPresent = func() bool { + _, err := exec.LookPath("pkl") + return err == nil + } + // mutex for thread-safe modification of the checker function + mu sync.Mutex +) + +// SetPklBinaryChecker allows overriding the default pkl binary check for testing. +// It returns the previous checker function so it can be restored later. +func SetPklBinaryChecker(checker func() bool) func() bool { + mu.Lock() + defer mu.Unlock() + previous := isPklBinaryPresent + isPklBinaryPresent = checker + return previous +} + // PklValidator is used to validate a byte slice that is intended to represent a // PKL file. type PklValidator struct{} // Validate attempts to evaluate the provided byte slice as a PKL file. +// If the 'pkl' binary is not found, it returns ErrSkipped. func (PklValidator) Validate(b []byte) (bool, error) { + mu.Lock() + checker := isPklBinaryPresent + mu.Unlock() + + if !checker() { + return false, ErrSkipped + } + ctx := context.Background() // Convert the byte slice to a ModuleSource using TextSource From df3e3ded3ac7172f6f7af39c08327c5d9d77c160 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Tue, 7 Oct 2025 12:17:15 +0530 Subject: [PATCH 05/17] fix: move PKL to alphabetically correct spot in list of supported config filetypes --- cmd/validator/validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index 36692f1b..6cace43d 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -2,7 +2,7 @@ Validator recursively scans a directory to search for configuration files and validates them using the go package for each configuration type. -Currently Apple PList XML, PKL, CSV, HCL, HOCON, INI, JSON, Properties, TOML, XML, and YAML. +Currently Apple PList XML, CSV, HCL, HOCON, INI, JSON, PKL, Properties, TOML, XML, and YAML. configuration file types are supported. Usage: validator [OPTIONS] [...] From e33c52259f605aa03eb3ae6ba478d0e96f18595d Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Tue, 7 Oct 2025 12:24:39 +0530 Subject: [PATCH 06/17] test: add fleshed out example for good.pkl --- test/fixtures/good.pkl | 53 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/test/fixtures/good.pkl b/test/fixtures/good.pkl index 9d4c336a..c2ef92d1 100644 --- a/test/fixtures/good.pkl +++ b/test/fixtures/good.pkl @@ -1,7 +1,50 @@ -name = "Swallow" +amends "pkl:Project" -job { - title = "Sr. Nest Maker" - company = "Nests R Us" - yearsOfExperience = 2 +name = "PhoenixWebApp" + +package { + name = "phoenix" + version = "2.1.0" + authors = ["Phoenix Engineering "] +} + +database { + host = "db.phoenix.internal" + port = 5432 + username = "phoenix_user" + poolSize = 20 + sslMode = "require" +} + +server { + host = "0.0.0.0" + port = 8080 + logLevel = "info" // "debug", "info", "warn", "error" + corsOrigins = List("https://phoenix.example", "https://app.phoenix.example") } + +features { + newSignupFlow = true + apiRateLimiting = true + dashboardAnalytics = false +} + +// --- Service Replica Configuration --- +class Replica { + region: "us-east-1" | "us-west-2" | "eu-central-1" + instanceType: String + count: Int +} + +replicas: List = List( + new { + region = "us-east-1" + instanceType = "t3.medium" + count = 3 + }, + new { + region = "us-west-2" + instanceType = "t3.medium" + count = 2 + } +) From a3f1ca6757fc817ce88f336072c9b3ed2d18a1ff Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Tue, 7 Oct 2025 12:56:12 +0530 Subject: [PATCH 07/17] fix(test): repair test suite after pkl validator refactor - Removes a redeclared isPklBinaryPresent function that was causing a build failure. - Updates the test logic to check for the new ErrSkipped sentinel error, aligning it with the recent refactoring. - Removes an unused import. --- pkg/validator/validator_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index 28767b2f..4053ee10 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -2,7 +2,7 @@ package validator import ( _ "embed" - "os/exec" + "errors" "testing" ) @@ -73,11 +73,6 @@ var testData = []struct { {"invalidEditorConfig", []byte("[*.md\nworking=false"), false, EditorConfigValidator{}}, } -func isPklBinaryPresent() bool { - _, err := exec.LookPath("pkl") - return err == nil -} - func Test_ValidationInput(t *testing.T) { t.Parallel() @@ -87,14 +82,15 @@ func Test_ValidationInput(t *testing.T) { t.Run(tcase.name, func(t *testing.T) { t.Parallel() - // Skip PklValidator tests if the pkl binary is not present + valid, err := tcase.validator.Validate(tcase.testInput) + + // If the validator is PklValidator and it returns ErrSkipped, skip the test. if _, ok := tcase.validator.(PklValidator); ok { - if !isPklBinaryPresent() { + if errors.Is(err, ErrSkipped) { t.Skip("Skipping test: 'pkl' binary not found.") } } - valid, err := tcase.validator.Validate(tcase.testInput) if valid != tcase.expectedResult { t.Errorf("incorrect result: expected %v, got %v", tcase.expectedResult, valid) } From 1b7e7cdf87069fb38b69d7e0eb516afe1661e957 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Tue, 7 Oct 2025 13:07:42 +0530 Subject: [PATCH 08/17] fix: correct build and pkl test fixture - Fixes a build failure in the filetype package by using the correct `tools` import. - Updates the `good.pkl` test fixture with valid syntax so that tests pass when the pkl binary is installed. --- pkg/filetype/file_type.go | 2 +- test/fixtures/good.pkl | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/filetype/file_type.go b/pkg/filetype/file_type.go index 82c2943a..877ab4ac 100644 --- a/pkg/filetype/file_type.go +++ b/pkg/filetype/file_type.go @@ -67,7 +67,7 @@ var PropFileType = FileType{ // represent a Pkl file var PklFileType = FileType{ "pkl", - misc.ArrToMap("pkl"), + tools.ArrToMap("pkl"), validator.PklValidator{}, } diff --git a/test/fixtures/good.pkl b/test/fixtures/good.pkl index c2ef92d1..5f72357d 100644 --- a/test/fixtures/good.pkl +++ b/test/fixtures/good.pkl @@ -1,11 +1,11 @@ -amends "pkl:Project" + name = "PhoenixWebApp" package { name = "phoenix" version = "2.1.0" - authors = ["Phoenix Engineering "] + authors = List("Phoenix Engineering ") } database { @@ -30,19 +30,19 @@ features { } // --- Service Replica Configuration --- -class Replica { +local class Replica { region: "us-east-1" | "us-west-2" | "eu-central-1" instanceType: String count: Int } -replicas: List = List( - new { +replicas = List( + new Replica { region = "us-east-1" instanceType = "t3.medium" count = 3 }, - new { + new Replica { region = "us-west-2" instanceType = "t3.medium" count = 2 From e59a61c136db28b56dba91dd36c96cec9a268942 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Wed, 8 Oct 2025 16:24:10 +0530 Subject: [PATCH 09/17] fix: remove whitespace in workflow file --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index dfde1116..092290bd 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -96,7 +96,7 @@ jobs: uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version: "1.25" - + - name: Set up pkl uses: pkl-community/setup-pkl@5bb6ac805eb51c448837ec34e9957a18adab927d # v0.0.5 with: From 309847e67e4fb15a6e429976e6b16f5ca333da81 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Wed, 8 Oct 2025 16:57:48 +0530 Subject: [PATCH 10/17] feat(pkl): Improve test coverage for pkl validator Refactors the pkl validator to improve testability and adds tests for uncovered code paths. - Modifies the `PklValidator` to allow injecting an evaluator factory, making it easier to test error conditions. - Adds a test to verify that `ErrSkipped` is returned when the `pkl` binary is not found. - Adds a test to verify that an error is returned when the pkl evaluator fails to be created. --- pkg/validator/pkl.go | 13 +++++++--- pkg/validator/validator_test.go | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/pkg/validator/pkl.go b/pkg/validator/pkl.go index 344815e5..017afa1f 100644 --- a/pkg/validator/pkl.go +++ b/pkg/validator/pkl.go @@ -34,11 +34,13 @@ func SetPklBinaryChecker(checker func() bool) func() bool { // PklValidator is used to validate a byte slice that is intended to represent a // PKL file. -type PklValidator struct{} +type PklValidator struct { + evaluatorFactory func(context.Context, ...func(*pkl.EvaluatorOptions)) (pkl.Evaluator, error) +} // Validate attempts to evaluate the provided byte slice as a PKL file. // If the 'pkl' binary is not found, it returns ErrSkipped. -func (PklValidator) Validate(b []byte) (bool, error) { +func (v PklValidator) Validate(b []byte) (bool, error) { mu.Lock() checker := isPklBinaryPresent mu.Unlock() @@ -52,7 +54,12 @@ func (PklValidator) Validate(b []byte) (bool, error) { // Convert the byte slice to a ModuleSource using TextSource source := pkl.TextSource(string(b)) - evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) + evaluatorFactory := v.evaluatorFactory + if evaluatorFactory == nil { + evaluatorFactory = pkl.NewEvaluator + } + + evaluator, err := evaluatorFactory(ctx, pkl.PreconfiguredOptions) if err != nil { return false, fmt.Errorf("failed to create evaluator: %w", err) } diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index 4053ee10..48737bb0 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -1,9 +1,13 @@ package validator import ( + "context" _ "embed" "errors" + "strings" "testing" + + "github.com/apple/pkl-go/pkl" ) var ( @@ -105,3 +109,43 @@ func Test_ValidationInput(t *testing.T) { }) } } + +func TestPklValidator_BinaryMissing(t *testing.T) { + t.Parallel() + + // Override the binary checker to simulate the 'pkl' binary being absent. + previousChecker := SetPklBinaryChecker(func() bool { + return false + }) + // Restore the original checker after the test. + defer SetPklBinaryChecker(previousChecker) + + validator := PklValidator{} + _, err := validator.Validate([]byte(`name = "test"`)) + + if !errors.Is(err, ErrSkipped) { + t.Errorf("expected ErrSkipped, got %v", err) + } +} + +func TestPklValidator_EvaluatorCreationError(t *testing.T) { + t.Parallel() + + expectedErr := errors.New("evaluator creation failed") + + validator := PklValidator{ + evaluatorFactory: func(_ context.Context, _ ...func(options *pkl.EvaluatorOptions)) (pkl.Evaluator, error) { + return nil, expectedErr + }, + } + + _, err := validator.Validate([]byte(`name = "test"`)) + + if !strings.Contains(err.Error(), "failed to create evaluator") { + t.Errorf("expected error to contain 'failed to create evaluator', got %v", err) + } + + if !errors.Is(err, expectedErr) { + t.Errorf("expected error to wrap %v, got %v", expectedErr, err) + } +} From 8ffa41d34a1e1e957a37a45aaba6243495f7bee7 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Wed, 8 Oct 2025 18:58:16 +0530 Subject: [PATCH 11/17] fix(test): Prevent race conditions in pkl validator tests Removes `t.Parallel()` from tests that modify the global `isPklBinaryPresent` variable. This prevents potential race conditions between tests that rely on the state of this variable. --- pkg/validator/validator_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index 48737bb0..c6c25c66 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -111,7 +111,6 @@ func Test_ValidationInput(t *testing.T) { } func TestPklValidator_BinaryMissing(t *testing.T) { - t.Parallel() // Override the binary checker to simulate the 'pkl' binary being absent. previousChecker := SetPklBinaryChecker(func() bool { @@ -129,7 +128,10 @@ func TestPklValidator_BinaryMissing(t *testing.T) { } func TestPklValidator_EvaluatorCreationError(t *testing.T) { - t.Parallel() + + // Ensure the binary check passes for this test. + previousChecker := SetPklBinaryChecker(func() bool { return true }) + defer SetPklBinaryChecker(previousChecker) expectedErr := errors.New("evaluator creation failed") From 158c3c6bb3a5bae18d5b7b6a1b1800891c52e710 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Thu, 9 Oct 2025 13:58:52 +0530 Subject: [PATCH 12/17] refactor: rename ErrSkipped to ErrPklSkipped --- pkg/cli/cli.go | 2 +- pkg/validator/pkl.go | 6 +++--- pkg/validator/validator_test.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index fcd94b18..7d904c5b 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -97,7 +97,7 @@ func (c CLI) Run() (int, error) { } isValid, err := fileToValidate.FileType.Validator.Validate(fileContent) - if errors.Is(err, validator.ErrSkipped) { + if errors.Is(err, validator.ErrPklSkipped) { fmt.Printf("Warning: 'pkl' binary not found, file %s will be ignored.\n", fileToValidate.Path) continue } diff --git a/pkg/validator/pkl.go b/pkg/validator/pkl.go index 017afa1f..f4075ef0 100644 --- a/pkg/validator/pkl.go +++ b/pkg/validator/pkl.go @@ -11,8 +11,8 @@ import ( ) var ( - // ErrSkipped is returned when a validation is skipped due to a missing dependency. - ErrSkipped = errors.New("validation skipped") + // ErrPklSkipped is returned when a validation is skipped due to a missing dependency. + ErrPklSkipped = errors.New("validation skipped") isPklBinaryPresent = func() bool { _, err := exec.LookPath("pkl") @@ -46,7 +46,7 @@ func (v PklValidator) Validate(b []byte) (bool, error) { mu.Unlock() if !checker() { - return false, ErrSkipped + return false, ErrPklSkipped } ctx := context.Background() diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index c6c25c66..8a054bd2 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -90,7 +90,7 @@ func Test_ValidationInput(t *testing.T) { // If the validator is PklValidator and it returns ErrSkipped, skip the test. if _, ok := tcase.validator.(PklValidator); ok { - if errors.Is(err, ErrSkipped) { + if errors.Is(err, ErrPklSkipped) { t.Skip("Skipping test: 'pkl' binary not found.") } } @@ -122,7 +122,7 @@ func TestPklValidator_BinaryMissing(t *testing.T) { validator := PklValidator{} _, err := validator.Validate([]byte(`name = "test"`)) - if !errors.Is(err, ErrSkipped) { + if !errors.Is(err, ErrPklSkipped) { t.Errorf("expected ErrSkipped, got %v", err) } } From 7fe75c1ff345d35191b54c01a1490cbe5ca99278 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Thu, 9 Oct 2025 14:15:35 +0530 Subject: [PATCH 13/17] refactor: improve pkl binary detection --- .gitignore | 1 - pkg/cli/cli_test.go | 26 +------------------------- pkg/validator/pkl.go | 33 ++++++--------------------------- pkg/validator/validator_test.go | 22 +++++++--------------- 4 files changed, 14 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index e07ff4d9..eba42acd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ *.so *.dylib cmd/validator/validator -validator bin/ # Test binary, built with `go test -c` diff --git a/pkg/cli/cli_test.go b/pkg/cli/cli_test.go index f12fb274..2006cc3d 100644 --- a/pkg/cli/cli_test.go +++ b/pkg/cli/cli_test.go @@ -8,7 +8,7 @@ import ( "github.com/Boeing/config-file-validator/pkg/finder" "github.com/Boeing/config-file-validator/pkg/reporter" - "github.com/Boeing/config-file-validator/pkg/validator" + ) func Test_CLI(t *testing.T) { @@ -158,28 +158,4 @@ func Test_CLIReportErr(t *testing.T) { } } -func Test_CLI_IgnoreBadPklFileWhenBinaryNotFound(t *testing.T) { - // Override the binary checker for this test and restore it afterward - previousChecker := validator.SetPklBinaryChecker(func() bool { - return false - }) - defer validator.SetPklBinaryChecker(previousChecker) - searchPath := "../../test/fixtures/subdir2/bad.pkl" - fsFinder := finder.FileSystemFinderInit( - finder.WithPathRoots(searchPath), - ) - cli := Init( - WithFinder(fsFinder), - ) - exitStatus, err := cli.Run() - if err != nil { - t.Errorf("An error was returned: %v", err) - } - - // Since the pkl binary is not found, the bad pkl file should be ignored - // So the exit status should be 0 - if exitStatus != 0 { - t.Errorf("Expected exit status 0, but got: %d", exitStatus) - } -} diff --git a/pkg/validator/pkl.go b/pkg/validator/pkl.go index f4075ef0..141fbd39 100644 --- a/pkg/validator/pkl.go +++ b/pkg/validator/pkl.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" "os/exec" - "sync" + "github.com/apple/pkl-go/pkl" ) @@ -13,25 +13,7 @@ import ( var ( // ErrPklSkipped is returned when a validation is skipped due to a missing dependency. ErrPklSkipped = errors.New("validation skipped") - - isPklBinaryPresent = func() bool { - _, err := exec.LookPath("pkl") - return err == nil - } - // mutex for thread-safe modification of the checker function - mu sync.Mutex ) - -// SetPklBinaryChecker allows overriding the default pkl binary check for testing. -// It returns the previous checker function so it can be restored later. -func SetPklBinaryChecker(checker func() bool) func() bool { - mu.Lock() - defer mu.Unlock() - previous := isPklBinaryPresent - isPklBinaryPresent = checker - return previous -} - // PklValidator is used to validate a byte slice that is intended to represent a // PKL file. type PklValidator struct { @@ -41,14 +23,6 @@ type PklValidator struct { // Validate attempts to evaluate the provided byte slice as a PKL file. // If the 'pkl' binary is not found, it returns ErrSkipped. func (v PklValidator) Validate(b []byte) (bool, error) { - mu.Lock() - checker := isPklBinaryPresent - mu.Unlock() - - if !checker() { - return false, ErrPklSkipped - } - ctx := context.Background() // Convert the byte slice to a ModuleSource using TextSource @@ -61,6 +35,11 @@ func (v PklValidator) Validate(b []byte) (bool, error) { evaluator, err := evaluatorFactory(ctx, pkl.PreconfiguredOptions) if err != nil { + // If the error is that the pkl binary was not found, return ErrPklSkipped. + var execErr *exec.Error + if errors.As(err, &execErr) && execErr.Err == exec.ErrNotFound { + return false, ErrPklSkipped + } return false, fmt.Errorf("failed to create evaluator: %w", err) } diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index 8a054bd2..ea9c935f 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -4,6 +4,7 @@ import ( "context" _ "embed" "errors" + "os/exec" "strings" "testing" @@ -111,28 +112,19 @@ func Test_ValidationInput(t *testing.T) { } func TestPklValidator_BinaryMissing(t *testing.T) { - - // Override the binary checker to simulate the 'pkl' binary being absent. - previousChecker := SetPklBinaryChecker(func() bool { - return false - }) - // Restore the original checker after the test. - defer SetPklBinaryChecker(previousChecker) - - validator := PklValidator{} + validator := PklValidator{ + evaluatorFactory: func(ctx context.Context, options ...func(options *pkl.EvaluatorOptions)) (pkl.Evaluator, error) { + return nil, &exec.Error{Err: exec.ErrNotFound} + }, + } _, err := validator.Validate([]byte(`name = "test"`)) if !errors.Is(err, ErrPklSkipped) { - t.Errorf("expected ErrSkipped, got %v", err) + t.Errorf("expected ErrPklSkipped, got %v", err) } } func TestPklValidator_EvaluatorCreationError(t *testing.T) { - - // Ensure the binary check passes for this test. - previousChecker := SetPklBinaryChecker(func() bool { return true }) - defer SetPklBinaryChecker(previousChecker) - expectedErr := errors.New("evaluator creation failed") validator := PklValidator{ From 5a7e6c04be317bd4a9395aa90ce8ce785ddc8541 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed Date: Thu, 9 Oct 2025 14:21:13 +0530 Subject: [PATCH 14/17] revert: add back validator to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index eba42acd..e07ff4d9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.so *.dylib cmd/validator/validator +validator bin/ # Test binary, built with `go test -c` From 29461bc5909f7b1fae0d154c9068ac4560b79dd5 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed <63901133+akhil-rasheed@users.noreply.github.com> Date: Thu, 9 Oct 2025 21:15:36 +0530 Subject: [PATCH 15/17] fix: remove whitespace --- pkg/cli/cli_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/cli/cli_test.go b/pkg/cli/cli_test.go index 2006cc3d..b5db7a7b 100644 --- a/pkg/cli/cli_test.go +++ b/pkg/cli/cli_test.go @@ -8,7 +8,6 @@ import ( "github.com/Boeing/config-file-validator/pkg/finder" "github.com/Boeing/config-file-validator/pkg/reporter" - ) func Test_CLI(t *testing.T) { @@ -157,5 +156,3 @@ func Test_CLIReportErr(t *testing.T) { t.Errorf("should return err status code: %d", exitStatus) } } - - From 83989854110091959b699dffba3c2c5e668ec0d2 Mon Sep 17 00:00:00 2001 From: Akhil Rasheed <63901133+akhil-rasheed@users.noreply.github.com> Date: Thu, 9 Oct 2025 21:16:26 +0530 Subject: [PATCH 16/17] fix: remove whitespace --- pkg/validator/pkl.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/validator/pkl.go b/pkg/validator/pkl.go index 141fbd39..ffa37cba 100644 --- a/pkg/validator/pkl.go +++ b/pkg/validator/pkl.go @@ -6,7 +6,6 @@ import ( "fmt" "os/exec" - "github.com/apple/pkl-go/pkl" ) From 306e19060c770ac493bd1ac61764178010719b1d Mon Sep 17 00:00:00 2001 From: Akhil Rasheed <63901133+akhil-rasheed@users.noreply.github.com> Date: Sat, 11 Oct 2025 12:54:32 +0530 Subject: [PATCH 17/17] refactor(suggestion): mark unused parameters Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- pkg/validator/validator_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index ea9c935f..9e1237f3 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -113,7 +113,7 @@ func Test_ValidationInput(t *testing.T) { func TestPklValidator_BinaryMissing(t *testing.T) { validator := PklValidator{ - evaluatorFactory: func(ctx context.Context, options ...func(options *pkl.EvaluatorOptions)) (pkl.Evaluator, error) { + evaluatorFactory: func(_ context.Context, _ ...func(*pkl.EvaluatorOptions)) (pkl.Evaluator, error) { return nil, &exec.Error{Err: exec.ErrNotFound} }, } @@ -128,7 +128,7 @@ func TestPklValidator_EvaluatorCreationError(t *testing.T) { expectedErr := errors.New("evaluator creation failed") validator := PklValidator{ - evaluatorFactory: func(_ context.Context, _ ...func(options *pkl.EvaluatorOptions)) (pkl.Evaluator, error) { + evaluatorFactory: func(_ context.Context, _ ...func(*pkl.EvaluatorOptions)) (pkl.Evaluator, error) { return nil, expectedErr }, }