本站源代码
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

48 lines
1012B

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package upload
  5. import (
  6. "bytes"
  7. "compress/gzip"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestUpload(t *testing.T) {
  12. testContent := []byte(`This is a plain text file.`)
  13. var b bytes.Buffer
  14. w := gzip.NewWriter(&b)
  15. w.Write(testContent)
  16. w.Close()
  17. kases := []struct {
  18. data []byte
  19. allowedTypes []string
  20. err error
  21. }{
  22. {
  23. data: testContent,
  24. allowedTypes: []string{"text/plain"},
  25. err: nil,
  26. },
  27. {
  28. data: testContent,
  29. allowedTypes: []string{"application/x-gzip"},
  30. err: ErrFileTypeForbidden{"text/plain; charset=utf-8"},
  31. },
  32. {
  33. data: b.Bytes(),
  34. allowedTypes: []string{"application/x-gzip"},
  35. err: nil,
  36. },
  37. }
  38. for _, kase := range kases {
  39. assert.Equal(t, kase.err, VerifyAllowedContentType(kase.data, kase.allowedTypes))
  40. }
  41. }
上海开阖软件有限公司 沪ICP备12045867号-1