-
-
Notifications
You must be signed in to change notification settings - Fork 445
Ignoring fields with struct tag expr:"-" and make "in" return false for unexported fields #806
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
401009f
6bd3eb5
56d0528
eecf371
1089aa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"fmt" | ||
"os" | ||
"reflect" | ||
"strings" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
@@ -139,7 +140,86 @@ func ExampleEnv_tagged_field_names() { | |
|
||
fmt.Printf("%v", output) | ||
|
||
// Output : Hello World | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unrelated but I realized that this example test was not being run because there is a space between |
||
// Output: Hello World | ||
} | ||
|
||
func ExampleEnv_hidden_tagged_field_names() { | ||
type Internal struct { | ||
Visible string | ||
Hidden string `expr:"-"` | ||
} | ||
type environment struct { | ||
Visible string | ||
Hidden string `expr:"-"` | ||
HiddenInternal Internal `expr:"-"` | ||
VisibleInternal Internal | ||
} | ||
|
||
env := environment{ | ||
Hidden: "First level secret", | ||
HiddenInternal: Internal{ | ||
Visible: "Second level secret", | ||
Hidden: "Also hidden", | ||
}, | ||
VisibleInternal: Internal{ | ||
Visible: "Not a secret", | ||
Hidden: "Hidden too", | ||
}, | ||
} | ||
|
||
hiddenValues := []string{ | ||
`Hidden`, | ||
`HiddenInternal`, | ||
`HiddenInternal.Visible`, | ||
`HiddenInternal.Hidden`, | ||
`VisibleInternal["Hidden"]`, | ||
} | ||
for _, expression := range hiddenValues { | ||
output, err := expr.Eval(expression, env) | ||
if err == nil || !strings.Contains(err.Error(), "cannot fetch") { | ||
fmt.Printf("unexpected output: %v; err: %v\n", output, err) | ||
return | ||
} | ||
fmt.Printf("%q is hidden as expected\n", expression) | ||
} | ||
|
||
visibleValues := []string{ | ||
`Visible`, | ||
`VisibleInternal`, | ||
`VisibleInternal["Visible"]`, | ||
} | ||
for _, expression := range visibleValues { | ||
_, err := expr.Eval(expression, env) | ||
if err != nil { | ||
fmt.Printf("unexpected error: %v\n", err) | ||
return | ||
} | ||
fmt.Printf("%q is visible as expected\n", expression) | ||
} | ||
|
||
testWithIn := []string{ | ||
`not ("Hidden" in $env)`, | ||
`"Visible" in $env`, | ||
`not ("Hidden" in VisibleInternal)`, | ||
`"Visible" in VisibleInternal`, | ||
} | ||
for _, expression := range testWithIn { | ||
val, err := expr.Eval(expression, env) | ||
shouldBeTrue, ok := val.(bool) | ||
if err != nil || !ok || !shouldBeTrue { | ||
fmt.Printf("unexpected result; value: %v; error: %v\n", val, err) | ||
return | ||
} | ||
} | ||
|
||
// Output: "Hidden" is hidden as expected | ||
// "HiddenInternal" is hidden as expected | ||
// "HiddenInternal.Visible" is hidden as expected | ||
// "HiddenInternal.Hidden" is hidden as expected | ||
// "VisibleInternal[\"Hidden\"]" is hidden as expected | ||
// "Visible" is visible as expected | ||
// "VisibleInternal" is visible as expected | ||
// "VisibleInternal[\"Visible\"]" is visible as expected | ||
} | ||
|
||
func ExampleAsKind() { | ||
|
@@ -529,7 +609,7 @@ func ExamplePatch() { | |
} | ||
fmt.Printf("%v", output) | ||
|
||
// Output : Hello, you, world! | ||
// Output: Hello, you, world! | ||
Comment on lines
-532
to
+612
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above: this is unrelated but I realized that this example test was not being run because there is a space between |
||
} | ||
|
||
func ExampleWithContext() { | ||
|
Uh oh!
There was an error while loading. Please reload this page.