Closed andreaswwilson closed 1 week ago
Thank you for your feedback and for pointing me in the correct direction. I have updated CreateUser and ModifyUser to follow the existing pattern used for groups and projects. Since i am not an administrator for any gitlab instance i have not been able to test the modified methods on a real instance.
While the PR now looks good, I do prefer this is checked/tested before we merge it. I also don't have access to a GitLab instance (believe it or not 😏), but maybe @PatrickRice-KSC or @timofurrer can help out and give it a quick check/test?
@svanharmelen - Sure, I'll give it a test! Also, do you want me to get you a contributors license for GitLab? I'm happy to help with that 😆
I created 3 different tests for this PR, testing:
All 3 tests passed properly :)
Here is the code I used:
func TestUserAvatar(t *testing.T) {
client, err := NewClient("glpat-ACCTEST1234567890123", WithBaseURL("http://localhost:8085/api/v4"))
if err != nil {
t.Fatal(err)
}
avatar, err := os.OpenFile("testdata/avatar.png", os.O_RDONLY, 0644)
if err != nil {
t.Fatal(err)
}
user, resp, err := client.Users.UploadAvatar(avatar, "avatar.png")
assert.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
assert.NotNil(t, user.AvatarURL)
}
func TestModifyUserAvatar(t *testing.T) {
client, err := NewClient("glpat-ACCTEST1234567890123", WithBaseURL("http://localhost:8085/api/v4"))
if err != nil {
t.Fatal(err)
}
avatar, err := os.OpenFile("testdata/avatar.png", os.O_RDONLY, 0644)
if err != nil {
t.Fatal(err)
}
userAvatar := &UserAvatar{
Image: avatar,
Filename: "testdata/avatar.png",
}
user, resp, err := client.Users.ModifyUser(1, &ModifyUserOptions{
Avatar: userAvatar,
})
assert.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
assert.NotNil(t, user.AvatarURL)
}
func TestCreateUserAvatar(t *testing.T) {
client, err := NewClient("glpat-ACCTEST1234567890123", WithBaseURL("http://localhost:8085/api/v4"))
if err != nil {
t.Fatal(err)
}
avatar, err := os.OpenFile("testdata/avatar.png", os.O_RDONLY, 0644)
if err != nil {
t.Fatal(err)
}
userAvatar := &UserAvatar{
Image: avatar,
Filename: "testdata/avatar.png",
}
user, resp, err := client.Users.CreateUser(&CreateUserOptions{
Email: Ptr("example@exampl.com"),
Name: Ptr("PetTheKitty"),
Username: Ptr("PetTheKitty"),
ForceRandomPassword: Ptr(true),
Avatar: userAvatar,
})
assert.Nil(t, err)
assert.Equal(t, 201, resp.StatusCode)
assert.NotNil(t, user.AvatarURL)
}
Thanks you so much for your (quick) help @PatrickRice-KSC! Really appreciated it ❤️
First time committing to external github-repo, so I hope this is the correct way. This fixes xanzy/go-gitlab#1871 I have not added feature for downloading avatar since this is not part of the gitlab api.