example_test.go 644 B

12345678910111213141516171819202122232425262728293031
  1. // go-qrcode
  2. // Copyright 2014 Tom Harwood
  3. /*
  4. Amendments Thu, 2017-December-14:
  5. - test integration (go test -v)
  6. - idiomatic go code
  7. */
  8. package qrcode
  9. import (
  10. "fmt"
  11. "os"
  12. "testing"
  13. )
  14. func TestExampleEncode(t *testing.T) {
  15. if png, err := Encode("https://example.org", Medium, 256); err != nil {
  16. t.Errorf("Error: %s", err.Error())
  17. } else {
  18. fmt.Printf("PNG is %d bytes long", len(png))
  19. }
  20. }
  21. func TestExampleWriteFile(t *testing.T) {
  22. filename := "example.png"
  23. if err := WriteFile("https://example.org", Medium, 256, filename); err != nil {
  24. if err = os.Remove(filename); err != nil {
  25. t.Errorf("Error: %s", err.Error())
  26. }
  27. }
  28. }