Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selector comparison not working #72

Open
jorgemarey opened this issue Jul 17, 2024 · 0 comments
Open

Selector comparison not working #72

jorgemarey opened this issue Jul 17, 2024 · 0 comments

Comments

@jorgemarey
Copy link

jorgemarey commented Jul 17, 2024

Hi,

Using two selectors in comparison expression doesn't seem to work.

This works:

"value.nomad == test and value.consul == test",

This doesn't:

"value.nomad == value.consul",

The following code shows the problem:

package main

import (
	"fmt"
	"os"

	"github.com/hashicorp/go-bexpr"
	"github.com/hashicorp/go-bexpr/grammar"
)

type Example struct {
	Nomad  string `bexpr:"nomad"`
	Consul string `bexpr:"consul"`
}

func main() {
	value := map[string]Example{
		"value": {Nomad: "prueba", Consul: "prueba"},
	}

	expressions := []string{
		"value.nomad == prueba and value.consul == prueba",
		"value.nomad == value.consul",
	}

	for _, expression := range expressions {
		eval, err := bexpr.CreateEvaluator(expression)

		if err != nil {
			fmt.Printf("Failed to create evaluator for expression %q: %v\n", expression, err)
			continue
		}

		result, err := eval.Evaluate(value)
		if err != nil {
			fmt.Printf("Failed to run evaluation of expression %q: %v\n", expression, err)
			continue
		}

		fmt.Printf("Result of expression %q evaluation: %t\n", expression, result)
	}
}

I guess this is not implemented. Is there any way I can get this working? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant