Skip to content
Discussion options

You must be logged in to vote

My recommendation for such structs, where you do not actually want some fields to be Equal is to write a test helper function to define what you consider to be "equal":

func assertDBJobCloseEnough(t *testing.T, expected, actual jobs.DBJob) bool {
    t.Helper()
    return assert.Equalf(t, expected.Id, actual.Id, "Expected Id=%d but got Id=%d", expected.Id, actual.Id)
        & assert.Equalf(t, expected.Name, actual.Name, "Expected Name=%s but got Name=%s", expected.Name, actual.Name)
        & assert.Equalf(t, expected.Data, actual.Data, "Expected Data=%s but got Data=%s", expected.Data, actual.Data)
        & assert.Equalf(t, expected.State, actual.State, "Expected State=%v but got State…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@MrNemo64
Comment options

@brackendawson
Comment options

@MrNemo64
Comment options

@nchelluri
Comment options

Answer selected by MrNemo64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants