Skip to content

A library for doing diffs of arbitrary Golang structs.

License

Notifications You must be signed in to change notification settings

mikijov/messagediff

 
 

Repository files navigation

messagediff Build Status Coverage Status GoDoc

A library for doing diffs of arbitrary Golang structs.

If the unsafe package is available messagediff will diff unexported fields in addition to exported fields. This is primarily used for testing purposes as it allows for providing informative error messages.

Example Usage

In a normal file:

package main

import "gopkg.in/d4l3k/messagediff.v1"

type someStruct struct {
  A, b int
  C []int
}

func main() {
			a := someStruct{1, 2, []int{1}}
			b := someStruct{1, 3, []int{1, 2}}
      diff, equal := messagediff.PrettyDiff(a, b)
      /*
        diff =
          `added: .C[1] = 2
          modified: .b = 3`

        equal = false
      */
}

In a test:

import "gopkg.in/d4l3k/messagediff.v1"

...

type someStruct struct {
  A, b int
  C []int
}

func TestSomething(t *testing.T) {
  want := someStruct{1, 2, []int{1}}
  got := someStruct{1, 3, []int{1, 2}}
  if diff, equal := messagediff.PrettyDiff(want, got); !equal {
    t.Errorf("Something() = %#v\n%s", got, diff)
  }
}

See the DeepDiff function for using the diff results programmatically.

License

Copyright (c) 2015 Tristan Rice rice@fn.lc

messagediff is licensed under the MIT license. See the LICENSE file for more information.

bypass.go and bypasssafe.go are borrowed from go-spew and have a seperate copyright notice.

About

A library for doing diffs of arbitrary Golang structs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%