docserver_test.go 891 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package docserver
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "testing"
  6. "github.com/ethereum/go-ethereum/common"
  7. "github.com/ethereum/go-ethereum/crypto"
  8. )
  9. func TestGetAuthContent(t *testing.T) {
  10. text := "test"
  11. hash := common.Hash{}
  12. copy(hash[:], crypto.Sha3([]byte(text)))
  13. ioutil.WriteFile("/tmp/test.content", []byte(text), os.ModePerm)
  14. ds, err := New("/tmp/")
  15. content, err := ds.GetAuthContent("file:///test.content", hash)
  16. if err != nil {
  17. t.Errorf("no error expected, got %v", err)
  18. }
  19. if string(content) != text {
  20. t.Errorf("incorrect content. expected %v, got %v", text, string(content))
  21. }
  22. hash = common.Hash{}
  23. content, err = ds.GetAuthContent("file:///test.content", hash)
  24. expected := "content hash mismatch"
  25. if err == nil {
  26. t.Errorf("expected error, got nothing")
  27. } else {
  28. if err.Error() != expected {
  29. t.Errorf("expected error '%s' got '%v'", expected, err)
  30. }
  31. }
  32. }