github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/test/diff_test.go (about)

     1  // Copyright (c) 2015 Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  package test
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestDiff(t *testing.T) {
    12  	saved := prettyPrintDepth
    13  	prettyPrintDepth = 4
    14  	testcases := getDeepEqualTests(t)
    15  
    16  	for _, test := range testcases {
    17  		diff := Diff(test.a, test.b)
    18  		if test.diff != diff {
    19  			t.Errorf("Diff returned different diff\n"+
    20  				"Diff    : %q\nExpected: %q\nFor %#v == %#v",
    21  				diff, test.diff, test.a, test.b)
    22  		}
    23  	}
    24  	prettyPrintDepth = saved
    25  }
    26  
    27  var benchEqual = map[string]interface{}{
    28  	"foo": "bar",
    29  	"bar": map[string]interface{}{
    30  		"foo": "bar",
    31  		"bar": map[string]interface{}{
    32  			"foo": "bar",
    33  		},
    34  		"foo2": []uint32{1, 2, 5, 78, 23, 236, 346, 3456},
    35  	},
    36  }
    37  
    38  var benchDiff = map[string]interface{}{
    39  	"foo": "bar",
    40  	"bar": map[string]interface{}{
    41  		"foo": "bar",
    42  		"bar": map[string]interface{}{
    43  			"foo": "bar",
    44  		},
    45  		"foo2": []uint32{1, 2, 5, 78, 23, 236, 346, 3457},
    46  	},
    47  }
    48  
    49  func BenchmarkEqualDeepEqual(b *testing.B) {
    50  	for i := 0; i < b.N; i++ {
    51  		DeepEqual(benchEqual, benchEqual)
    52  	}
    53  }
    54  
    55  func BenchmarkEqualDiff(b *testing.B) {
    56  	for i := 0; i < b.N; i++ {
    57  		Diff(benchEqual, benchEqual)
    58  	}
    59  }
    60  
    61  func BenchmarkDiffDeepEqual(b *testing.B) {
    62  	for i := 0; i < b.N; i++ {
    63  		DeepEqual(benchEqual, benchDiff)
    64  	}
    65  }
    66  
    67  func BenchmarkDiffDiff(b *testing.B) {
    68  	for i := 0; i < b.N; i++ {
    69  		Diff(benchEqual, benchDiff)
    70  	}
    71  }