| 1 |
package reply_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"io/ioutil" |
| 6 |
"os" |
| 7 |
"path/filepath" |
| 8 |
"strings" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"code.forgejo.org/forgejo/reply" |
| 12 |
) |
| 13 |
|
| 14 |
func TestText(t *testing.T) { |
| 15 |
|
| 16 |
var skipped []string |
| 17 |
|
| 18 |
err := filepath.Walk("testdata/emails", func(path string, info os.FileInfo, err error) error { |
| 19 |
if err != nil { |
| 20 |
return err |
| 21 |
} |
| 22 |
|
| 23 |
if info.IsDir() { |
| 24 |
return nil |
| 25 |
} |
| 26 |
|
| 27 |
if filepath.Ext(path) == ".txt" { |
| 28 |
t.Run(path, func(t *testing.T) { |
| 29 |
for _, filename := range skipped { |
| 30 |
if filename == filepath.Base(path) { |
| 31 |
t.Skipf("%s is not implemented", filename) |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
in, err := os.Open(path) |
| 36 |
if err != nil { |
| 37 |
t.Fatalf("unexpected error: %s", err) |
| 38 |
} |
| 39 |
|
| 40 |
expected, err := ioutil.ReadFile(fmt.Sprintf("testdata/reply/%s", filepath.Base(path))) |
| 41 |
if err != nil { |
| 42 |
t.Fatalf("unexpected error: %s", err) |
| 43 |
} |
| 44 |
|
| 45 |
replyText, err := reply.FromReader(in) |
| 46 |
if err != nil { |
| 47 |
t.Fatalf("unexpected error: %s", err) |
| 48 |
} |
| 49 |
|
| 50 |
if strings.TrimSpace(replyText) != strings.TrimSpace(string(expected)) { |
| 51 |
t.Errorf("\nexpected:\n%s\n\ngot:\n%s", string(expected), replyText) |
| 52 |
} |
| 53 |
}) |
| 54 |
} |
| 55 |
|
| 56 |
return nil |
| 57 |
}) |
| 58 |
|
| 59 |
if err != nil { |
| 60 |
t.Errorf("unexpected error: %s", err) |
| 61 |
} |
| 62 |
} |