artmigrator/repository/gitea/gitea_test.go
2024-11-19 23:13:06 +03:00

47 lines
1.3 KiB
Go

// gitea_test.go
package gitea
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestArtifactExists(t *testing.T) {
mockClient := &MockClient{}
defer mockClient.AssertExpectations(t)
mockClient.On("ArtifactExists", "owner", "repo", "test-artifact").Return(false, nil)
client := mockClient
exists, err := client.ArtifactExists("owner", "repo", "test-artifact")
assert.NoError(t, err)
assert.Equal(t, false, exists)
}
func TestArtifactExists_Error(t *testing.T) {
mockClient := &MockClient{}
defer mockClient.AssertExpectations(t)
mockClient.On("ArtifactExists", "owner", "repo", "test-artifact").Return(false, assert.AnError)
client := mockClient
exists, err := client.ArtifactExists("owner", "repo", "test-artifact")
assert.Error(t, err)
assert.Equal(t, false, exists)
}
func TestArtifactExists_ServerError(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}))
defer ts.Close()
client := NewClient(ts.URL, "token")
exists, err := client.ArtifactExists("owner", "repo", "test-artifact")
assert.Error(t, err)
assert.Equal(t, false, exists)
}