-
Notifications
You must be signed in to change notification settings - Fork 57
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
Define dyn.Mapping
to represent maps
#1301
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package dynassert | ||
|
||
import ( | ||
"github.com/databricks/cli/libs/dyn" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Equal(t assert.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { | ||
ev, eok := expected.(dyn.Value) | ||
av, aok := actual.(dyn.Value) | ||
if eok && aok && ev.IsValid() && av.IsValid() { | ||
if !assert.Equal(t, ev.AsAny(), av.AsAny(), msgAndArgs...) { | ||
return false | ||
} | ||
|
||
// The values are equal on contents. Now compare the locations. | ||
if !assert.Equal(t, ev.Location(), av.Location(), msgAndArgs...) { | ||
return false | ||
} | ||
|
||
// Walk ev and av and compare the locations of each element. | ||
_, err := dyn.Walk(ev, func(p dyn.Path, evv dyn.Value) (dyn.Value, error) { | ||
avv, err := dyn.GetByPath(av, p) | ||
if assert.NoError(t, err, "unable to get value from actual value at path %v", p.String()) { | ||
assert.Equal(t, evv.Location(), avv.Location()) | ||
} | ||
return evv, nil | ||
}) | ||
return assert.NoError(t, err) | ||
} | ||
|
||
return assert.Equal(t, expected, actual, msgAndArgs...) | ||
} | ||
|
||
func EqualValues(t assert.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { | ||
return assert.EqualValues(t, expected, actual, msgAndArgs...) | ||
} | ||
|
||
func NotEqual(t assert.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { | ||
return assert.NotEqual(t, expected, actual, msgAndArgs...) | ||
} | ||
|
||
func Len(t assert.TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool { | ||
return assert.Len(t, object, length, msgAndArgs...) | ||
} | ||
|
||
func Empty(t assert.TestingT, object interface{}, msgAndArgs ...interface{}) bool { | ||
return assert.Empty(t, object, msgAndArgs...) | ||
} | ||
|
||
func Nil(t assert.TestingT, object interface{}, msgAndArgs ...interface{}) bool { | ||
return assert.Nil(t, object, msgAndArgs...) | ||
} | ||
|
||
func NotNil(t assert.TestingT, object interface{}, msgAndArgs ...interface{}) bool { | ||
return assert.NotNil(t, object, msgAndArgs...) | ||
} | ||
|
||
func NoError(t assert.TestingT, err error, msgAndArgs ...interface{}) bool { | ||
return assert.NoError(t, err, msgAndArgs...) | ||
} | ||
|
||
func Error(t assert.TestingT, err error, msgAndArgs ...interface{}) bool { | ||
return assert.Error(t, err, msgAndArgs...) | ||
} | ||
|
||
func EqualError(t assert.TestingT, theError error, errString string, msgAndArgs ...interface{}) bool { | ||
return assert.EqualError(t, theError, errString, msgAndArgs...) | ||
} | ||
|
||
func ErrorContains(t assert.TestingT, theError error, contains string, msgAndArgs ...interface{}) bool { | ||
return assert.ErrorContains(t, theError, contains, msgAndArgs...) | ||
} | ||
|
||
func ErrorIs(t assert.TestingT, theError, target error, msgAndArgs ...interface{}) bool { | ||
return assert.ErrorIs(t, theError, target, msgAndArgs...) | ||
} | ||
|
||
func True(t assert.TestingT, value bool, msgAndArgs ...interface{}) bool { | ||
return assert.True(t, value, msgAndArgs...) | ||
} | ||
|
||
func False(t assert.TestingT, value bool, msgAndArgs ...interface{}) bool { | ||
return assert.False(t, value, msgAndArgs...) | ||
} | ||
|
||
func Contains(t assert.TestingT, list interface{}, element interface{}, msgAndArgs ...interface{}) bool { | ||
return assert.Contains(t, list, element, msgAndArgs...) | ||
} | ||
|
||
func NotContains(t assert.TestingT, list interface{}, element interface{}, msgAndArgs ...interface{}) bool { | ||
return assert.NotContains(t, list, element, msgAndArgs...) | ||
} | ||
|
||
func ElementsMatch(t assert.TestingT, listA, listB interface{}, msgAndArgs ...interface{}) bool { | ||
return assert.ElementsMatch(t, listA, listB, msgAndArgs...) | ||
} | ||
|
||
func Panics(t assert.TestingT, f func(), msgAndArgs ...interface{}) bool { | ||
return assert.Panics(t, f, msgAndArgs...) | ||
} | ||
|
||
func PanicsWithValue(t assert.TestingT, expected interface{}, f func(), msgAndArgs ...interface{}) bool { | ||
return assert.PanicsWithValue(t, expected, f, msgAndArgs...) | ||
} | ||
|
||
func PanicsWithError(t assert.TestingT, errString string, f func(), msgAndArgs ...interface{}) bool { | ||
return assert.PanicsWithError(t, errString, f, msgAndArgs...) | ||
} | ||
|
||
func NotPanics(t assert.TestingT, f func(), msgAndArgs ...interface{}) bool { | ||
return assert.NotPanics(t, f, msgAndArgs...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dynassert | ||
|
||
import ( | ||
"go/parser" | ||
"go/token" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestThatThisTestPackageIsUsedWhereNecessary(t *testing.T) { | ||
var base = ".." | ||
var files []string | ||
err := fs.WalkDir(os.DirFS(base), ".", func(path string, d fs.DirEntry, err error) error { | ||
if d.IsDir() { | ||
// Filter this directory. | ||
if filepath.Base(path) == "dynassert" { | ||
return fs.SkipDir | ||
} | ||
} | ||
if ok, _ := filepath.Match("*_test.go", d.Name()); ok { | ||
files = append(files, filepath.Join(base, path)) | ||
} | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
|
||
// Check that all test files import this package. | ||
fset := token.NewFileSet() | ||
for _, file := range files { | ||
f, err := parser.ParseFile(fset, file, nil, parser.ParseComments) | ||
require.NoError(t, err) | ||
|
||
for _, imp := range f.Imports { | ||
if strings.Contains(imp.Path.Value, `github.com/stretchr/testify/assert`) { | ||
t.Errorf("File %s should not import github.com/stretchr/testify/assert", file) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This previously pointed to the location of the parent map value. Now it points to the unknown key.