file_test.go 604 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package bimg
  2. import (
  3. "testing"
  4. )
  5. func TestRead(t *testing.T) {
  6. buf, err := Read("fixtures/test.jpg")
  7. if err != nil {
  8. t.Errorf("Cannot read the image: %#v", err)
  9. }
  10. if len(buf) == 0 {
  11. t.Fatal("Empty buffer")
  12. }
  13. if DetermineImageType(buf) != JPEG {
  14. t.Fatal("Image is not jpeg")
  15. }
  16. }
  17. func TestWrite(t *testing.T) {
  18. buf, err := Read("fixtures/test.jpg")
  19. if err != nil {
  20. t.Errorf("Cannot read the image: %#v", err)
  21. }
  22. if len(buf) == 0 {
  23. t.Fatal("Empty buffer")
  24. }
  25. err = Write("fixtures/test_write_out.jpg", buf)
  26. if err != nil {
  27. t.Fatalf("Cannot write the file: %#v", err)
  28. }
  29. }