Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

38 lines
1.2KB

  1. package main
  2. import (
  3. "encoding/json"
  4. "os"
  5. "testing"
  6. "time"
  7. )
  8. func TestCRMAttachFile(t *testing.T) {
  9. path1 := "media_for_test/200x200.png"
  10. path2 := "/tmp/wechat_hitxy_测试_" + time.Now().Format("2006-Jan-02-05-04-05")
  11. r, e := crmCreateAttachment("media_for_test/200x200.png")
  12. AssertEqual(t, e, nil, "should be no error when create attachment")
  13. AssertEqual(t, r.ID != "", true, "ID should not be empty ")
  14. //
  15. crmDownloadAttachmentAs(r.ID, path2)
  16. AssertEqual(t, md5CompFile(path1, path2), true, "attachment should be downloade as same file ")
  17. delete, e := crmDeleteEntity("Attachment", r.ID)
  18. AssertEqual(t, delete, true, "temp attachment should have been deleted")
  19. os.Remove(path2)
  20. }
  21. func TestDecodeJsonResponse(t *testing.T) {
  22. msg := `
  23. {"id":"591e55398345683ee","name":"static_qr_code_without_logo.png","deleted":false,"type":"image\/png"
  24. ,"size":509,"sourceId":null,"createdAt":"2017-05-19 02:15:21","role":"Attachment","storage":null,"storageFilePath"
  25. :null,"global":false,"parentId":null,"parentType":null,"relatedId":null,"relatedType":null,"createdById"
  26. :"1","createdByName":"Admin"} `
  27. info := crmdAttachment{}
  28. err := json.Unmarshal([]byte(msg), &info)
  29. AssertEqual(t, err, nil, "json decode shold be correct")
  30. }