File: api_test.go

package info (click to toggle)
golang-forgejo-forgejo-reply 1.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 604 kB
  • sloc: makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package reply_test

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"testing"

	"code.forgejo.org/forgejo/reply"
)

func TestText(t *testing.T) {
	// Add files to be skipped.
	var skipped []string

	err := filepath.Walk("testdata/emails", func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}

		if info.IsDir() {
			return nil
		}

		if filepath.Ext(path) == ".txt" {
			t.Run(path, func(t *testing.T) {
				for _, filename := range skipped {
					if filename == filepath.Base(path) {
						t.Skipf("%s is not implemented", filename)
					}
				}

				in, err := os.Open(path)
				if err != nil {
					t.Fatalf("unexpected error: %s", err)
				}

				expected, err := ioutil.ReadFile(fmt.Sprintf("testdata/reply/%s", filepath.Base(path)))
				if err != nil {
					t.Fatalf("unexpected error: %s", err)
				}

				replyText, err := reply.FromReader(in)
				if err != nil {
					t.Fatalf("unexpected error: %s", err)
				}

				if strings.TrimSpace(replyText) != strings.TrimSpace(string(expected)) {
					t.Errorf("\nexpected:\n%s\n\ngot:\n%s", string(expected), replyText)
				}
			})
		}

		return nil
	})

	if err != nil {
		t.Errorf("unexpected error: %s", err)
	}
}