You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

identicon_test.go 876B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2021 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. //go:build test_avatar_identicon
  5. package identicon
  6. import (
  7. "image/color"
  8. "image/png"
  9. "os"
  10. "strconv"
  11. "testing"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestGenerate(t *testing.T) {
  15. dir, _ := os.Getwd()
  16. dir = dir + "/testdata"
  17. if st, err := os.Stat(dir); err != nil || !st.IsDir() {
  18. t.Errorf("can not save generated images to %s", dir)
  19. }
  20. backColor := color.White
  21. imgMaker, err := New(64, backColor, DarkColors...)
  22. assert.NoError(t, err)
  23. for i := 0; i < 100; i++ {
  24. s := strconv.Itoa(i)
  25. img := imgMaker.Make([]byte(s))
  26. f, err := os.Create(dir + "/" + s + ".png")
  27. if !assert.NoError(t, err) {
  28. continue
  29. }
  30. defer f.Close()
  31. err = png.Encode(f, img)
  32. assert.NoError(t, err)
  33. }
  34. }