diff options
Diffstat (limited to 'internal/userutil/userutil_test.go')
-rw-r--r-- | internal/userutil/userutil_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/userutil/userutil_test.go b/internal/userutil/userutil_test.go index a62363a5..e90c9235 100644 --- a/internal/userutil/userutil_test.go +++ b/internal/userutil/userutil_test.go @@ -5,11 +5,15 @@ package userutil import ( + "os" + "runtime" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "gogs.io/gogs/internal/conf" + "gogs.io/gogs/internal/osutil" "gogs.io/gogs/internal/tool" ) @@ -38,3 +42,38 @@ func TestGenerateActivateCode(t *testing.T) { got := tool.VerifyTimeLimitCode("1alice@example.comalice123456rands", conf.Auth.ActivateCodeLives, code[:tool.TIME_LIMIT_CODE_LENGTH]) assert.True(t, got) } + +func TestCustomAvatarPath(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Skipping testing on Windows") + return + } + + conf.SetMockPicture(t, + conf.PictureOpts{ + AvatarUploadPath: "data/avatars", + }, + ) + + got := CustomAvatarPath(1) + want := "data/avatars/1" + assert.Equal(t, want, got) +} + +func TestGenerateRandomAvatar(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Skipping testing on Windows") + return + } + + conf.SetMockPicture(t, + conf.PictureOpts{ + AvatarUploadPath: os.TempDir(), + }, + ) + + err := GenerateRandomAvatar(1, "alice", "alice@example.com") + require.NoError(t, err) + got := osutil.IsFile(CustomAvatarPath(1)) + assert.True(t, got) +} |