mirror of
https://tvoygit.ru/Djam/artmigrator.git
synced 2025-02-23 10:22:45 +00:00
47 lines
1.3 KiB
Go
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)
|
|
}
|