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 909B

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