github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/avatar/identicon/identicon_test.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 //go:build test_avatar_identicon 7 8 package identicon 9 10 import ( 11 "image/color" 12 "image/png" 13 "os" 14 "strconv" 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 ) 19 20 func TestGenerate(t *testing.T) { 21 dir, _ := os.Getwd() 22 dir = dir + "/testdata" 23 if st, err := os.Stat(dir); err != nil || !st.IsDir() { 24 t.Errorf("can not save generated images to %s", dir) 25 } 26 27 backColor := color.White 28 imgMaker, err := New(64, backColor, DarkColors...) 29 assert.NoError(t, err) 30 for i := 0; i < 100; i++ { 31 s := strconv.Itoa(i) 32 img := imgMaker.Make([]byte(s)) 33 34 f, err := os.Create(dir + "/" + s + ".png") 35 if !assert.NoError(t, err) { 36 continue 37 } 38 defer f.Close() 39 err = png.Encode(f, img) 40 assert.NoError(t, err) 41 } 42 }