@@ -55,6 +55,11 @@ func assertEqualTexts(t testutil.TestingT, filename1, filename2, expected, out s
5555 }
5656}
5757
58+ func logDiff (t testutil.TestingT , filename1 , filename2 , expected , out string ) {
59+ diff := testutil .Diff (filename1 , filename2 , expected , out )
60+ t .Logf ("Diff:\n " + diff )
61+ }
62+
5863func RequireOutput (t testutil.TestingT , ctx context.Context , args []string , expectedFilename string ) {
5964 _ , filename , _ , _ := runtime .Caller (1 )
6065 dir := filepath .Dir (filename )
@@ -83,13 +88,26 @@ func RequireOutputJQ(t testutil.TestingT, ctx context.Context, args []string, ex
8388
8489 if out != expected {
8590 patch , err := jsondiff .CompareJSON ([]byte (expected ), []byte (out ))
91+ actual := fmt .Sprintf ("Output from %v" , args )
8692 if err != nil {
8793 t .Logf ("CompareJSON error for %s vs %s: %s (fallback to textual comparison)" , args , expectedFilename , err )
88- actual := fmt .Sprintf ("Output from %v" , args )
8994 assertEqualTexts (t , expectedFilename , actual , expected , out )
9095 } else {
96+ logDiff (t , expectedFilename , actual , expected , out )
97+ ignoredDiffs := []string {}
98+ erroredDiffs := []string {}
9199 for _ , op := range patch {
92- t .Errorf ("PATCH %s %s: %s" , args , expectedFilename , op )
100+ if matchesPrefixes (ignorePaths , op .Path ) {
101+ ignoredDiffs = append (ignoredDiffs , fmt .Sprintf ("%7s %s %v" , op .Type , op .Path , op .Value ))
102+ } else {
103+ erroredDiffs = append (erroredDiffs , fmt .Sprintf ("%7s %s %v" , op .Type , op .Path , op .Value ))
104+ }
105+ }
106+ if len (ignoredDiffs ) > 0 {
107+ t .Logf ("Ignored differences between %s and %s:\n ==> %s" , expectedFilename , args , strings .Join (ignoredDiffs , "\n ==> " ))
108+ }
109+ if len (erroredDiffs ) > 0 {
110+ t .Errorf ("Unexpected differences between %s and %s:\n ==> %s" , expectedFilename , args , strings .Join (erroredDiffs , "\n ==> " ))
93111 }
94112 }
95113
@@ -99,6 +117,18 @@ func RequireOutputJQ(t testutil.TestingT, ctx context.Context, args []string, ex
99117 }
100118}
101119
120+ func matchesPrefixes (prefixes []string , path string ) bool {
121+ for _ , p := range prefixes {
122+ if p == path {
123+ return true
124+ }
125+ if strings .HasPrefix (path , p + "/" ) {
126+ return true
127+ }
128+ }
129+ return false
130+ }
131+
102132var (
103133 uuidRegex = regexp .MustCompile (`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}` )
104134 numIdRegex = regexp .MustCompile (`[0-9]{3,}` )
@@ -158,18 +188,6 @@ func setKV(replacements *orderedmap.OrderedMap[string, string], key, value strin
158188 replacements .Set (key , value )
159189}
160190
161- /*
162- func setMissing(replacements *orderedmap.OrderedMap[string, string], key, value string) {
163- if key == "" || value == "" {
164- return
165- }
166- _, exists := replacements.Get(key)
167- if !exists {
168- replacements.Set(key, value)
169- }
170- }
171- */
172-
173191func PrepareReplacements (t testutil.TestingT , replacements * orderedmap.OrderedMap [string , string ], w * databricks.WorkspaceClient ) {
174192 // in some clouds (gcp) w.Config.Host includes "https://" prefix in others it's really just a host (azure)
175193 host := strings .TrimPrefix (strings .TrimPrefix (w .Config .Host , "http://" ), "https://" )
@@ -233,10 +251,6 @@ func PrepareReplacementsUser(t testutil.TestingT, replacements *orderedmap.Order
233251 setKV (replacements , val .Value , fmt .Sprintf ("$USER.Roles[%d]" , ind ))
234252 }
235253
236- for key , val := range replacements .AllFromFront () {
237- fmt .Printf ("REPL %v=%v\n " , key , val )
238- }
239-
240254 // Schemas []UserSchema `json:"schemas,omitempty"`
241255}
242256
0 commit comments