| 1 |
package approvaltests_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"io/ioutil" |
| 6 |
"log" |
| 7 |
"strings" |
| 8 |
) |
| 9 |
|
| 10 |
var ( |
| 11 |
// this is a mock testing.T for documentation purposes |
| 12 |
t = &failing{} |
| 13 |
) |
| 14 |
|
| 15 |
// failing is a mock struct that is only there for documentation conveniance, |
| 16 |
// showing the developer how they would be passing a *testing.T pointer in their |
| 17 |
// normal tests. |
| 18 |
type failing struct{} |
| 19 |
|
| 20 |
// Fail implements approvaltest.Fail |
| 21 |
func (f *failing) Fail() {} |
| 22 |
|
| 23 |
// documentation helper just for the example |
| 24 |
func printFileContent(path string) { |
| 25 |
approvedPath := strings.Replace(path, ".received.", ".approved.", 1) |
| 26 |
content, err := ioutil.ReadFile(approvedPath) |
| 27 |
if err != nil { |
| 28 |
log.Fatal(err) |
| 29 |
} |
| 30 |
fmt.Printf("This produced the file %s\n", path) |
| 31 |
fmt.Printf("It will be compared against the %s file\n", approvedPath) |
| 32 |
fmt.Println("and contains the text:") |
| 33 |
fmt.Println() |
| 34 |
// sad sad hack because go examples trim blank middle lines |
| 35 |
fmt.Println(strings.Replace(string(content), "\n\n", "\n", -1)) |
| 36 |
} |