MCPcopy
hub / github.com/AlistGo/alist / TestEncodeToken

Function TestEncodeToken

server/webdav/internal/xml/marshal_test.go:1789–1825  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1787}}
1788
1789func TestEncodeToken(t *testing.T) {
1790loop:
1791 for i, tt := range encodeTokenTests {
1792 var buf bytes.Buffer
1793 enc := NewEncoder(&buf)
1794 var err error
1795 for j, tok := range tt.toks {
1796 err = enc.EncodeToken(tok)
1797 if err != nil && j < len(tt.toks)-1 {
1798 t.Errorf("#%d %s token #%d: %v", i, tt.desc, j, err)
1799 continue loop
1800 }
1801 }
1802 errorf := func(f string, a ...interface{}) {
1803 t.Errorf("#%d %s token #%d:%s", i, tt.desc, len(tt.toks)-1, fmt.Sprintf(f, a...))
1804 }
1805 switch {
1806 case tt.err != "" && err == nil:
1807 errorf(" expected error; got none")
1808 continue
1809 case tt.err == "" && err != nil:
1810 errorf(" got error: %v", err)
1811 continue
1812 case tt.err != "" && err != nil && tt.err != err.Error():
1813 errorf(" error mismatch; got %v, want %v", err, tt.err)
1814 continue
1815 }
1816 if err := enc.Flush(); err != nil {
1817 errorf(" %v", err)
1818 continue
1819 }
1820 if got := buf.String(); got != tt.want {
1821 errorf("\ngot %v\nwant %v", got, tt.want)
1822 continue
1823 }
1824 }
1825}
1826
1827func TestProcInstEncodeToken(t *testing.T) {
1828 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 5

EncodeTokenMethod · 0.95
FlushMethod · 0.95
NewEncoderFunction · 0.85
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected