Skip to content

Commit

Permalink
Added TestFormatter_FailureContext (#418)
Browse files Browse the repository at this point in the history
Co-authored-by: Abhishek <abhishek.keshari@tanla.com>
  • Loading branch information
vasundhara785 and Abhishek committed Oct 1, 2023
1 parent 8d90e3b commit c126d8b
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,79 @@ func TestFormatter_FailureReference(t *testing.T) {
})
}
}
func TestFormatter_FailureContext(t *testing.T) {
cases := []struct {
name string
assertionType AssertionType
testName string
requestName string
path []string
aliasedPath []string
}{
{
name: "Assert Equal",
assertionType: AssertEqual,
testName: t.Name(),
requestName: "RequestName",
path: []string{"GET"},
aliasedPath: []string{"ALIASGET"},
},
{
name: "Assert DisableNames",
assertionType: AssertEqual,
path: []string{"GET"},
aliasedPath: []string{"ALIASGET"},
},
{
name: "Assert DisablePaths",
assertionType: AssertEqual,
testName: t.Name(),
requestName: "RequestName",
},
{
name: "Assert DisableAliases",
assertionType: AssertEqual,
testName: t.Name(),
requestName: "RequestName",
path: []string{"GET"},
aliasedPath: []string{"ALIASGET"},
},
}

ctx := &AssertionContext{
TestName: t.Name(),
RequestName: "RequestName",
Path: []string{"GET"},
AliasedPath: []string{"ALIASGET"},
}
var fd *FormatData
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
fl := &AssertionFailure{
Type: tc.assertionType,
}
if tc.name == "Assert Equal" {
df := &DefaultFormatter{}
fd = df.buildFormatData(ctx, fl)
assert.Equal(t, tc.aliasedPath, fd.AssertPath)
} else if tc.name == "Assert DisableNames" {
df := &DefaultFormatter{DisableNames: true}
fd = df.buildFormatData(ctx, fl)
assert.Equal(t, tc.aliasedPath, fd.AssertPath)
} else if tc.name == "Assert DisablePaths" {
df := &DefaultFormatter{DisablePaths: true}
fd = df.buildFormatData(ctx, fl)
assert.Equal(t, tc.path, fd.AssertPath)
} else if tc.name == "Assert DisableAliases" {
df := &DefaultFormatter{DisableAliases: true}
fd = df.buildFormatData(ctx, fl)
assert.Equal(t, tc.path, fd.AssertPath)
}
assert.Equal(t, tc.requestName, fd.RequestName)
assert.Equal(t, tc.testName, fd.TestName)
})
}
}

func TestFormatter_FailureDelta(t *testing.T) {
cases := []struct {
Expand Down

0 comments on commit c126d8b

Please sign in to comment.