CompareContent performs the golden file comparison
()
| 88 | |
| 89 | // CompareContent performs the golden file comparison |
| 90 | func (g *GoldenFile) CompareContent() { |
| 91 | g.t.Helper() |
| 92 | |
| 93 | if g.path == "" { |
| 94 | g.t.Fatal("golden file path not set") |
| 95 | } |
| 96 | if g.content == nil { |
| 97 | g.t.Fatal("content not set") |
| 98 | } |
| 99 | |
| 100 | // Determine the full path |
| 101 | goldenPath := g.path |
| 102 | if !filepath.IsAbs(g.path) && g.basePath != "" { |
| 103 | goldenPath = filepath.Join(g.basePath, g.path) |
| 104 | } |
| 105 | |
| 106 | // Prepare content |
| 107 | content := g.prepareContent() |
| 108 | |
| 109 | // Check update mode |
| 110 | updateMode := g.update || isUpdateMode() |
| 111 | |
| 112 | if updateMode { |
| 113 | g.updateFile(content, goldenPath) |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | // Check if file exists |
| 118 | if _, err := os.Stat(goldenPath); os.IsNotExist(err) { |
| 119 | g.t.Fatalf("golden file %q does not exist (run with -update to create)", goldenPath) |
| 120 | } |
| 121 | |
| 122 | g.compareContent(content, goldenPath) |
| 123 | } |
| 124 | |
| 125 | // Compare compares the actual content with the golden file content (legacy API) |
| 126 | // |