2019-08-26 09:31:38 +02:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2020-10-06 14:48:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-08-26 09:31:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClientEmpty(t *testing.T) {
|
|
|
|
ctx := &context.Context{}
|
|
|
|
client, err := New(ctx)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Nil(t, client)
|
|
|
|
require.NoError(t, err)
|
2019-08-26 09:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientNewGitea(t *testing.T) {
|
|
|
|
ctx := &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
GiteaURLs: config.GiteaURLs{
|
2020-11-21 15:36:29 +02:00
|
|
|
// TODO: use a mocked http server to cover version api
|
|
|
|
API: "https://gitea.com/api/v1",
|
|
|
|
Download: "https://gitea.com",
|
2019-08-26 09:31:38 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
TokenType: context.TokenTypeGitea,
|
|
|
|
Token: "giteatoken",
|
|
|
|
}
|
|
|
|
client, err := New(ctx)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2019-08-26 09:31:38 +02:00
|
|
|
_, ok := client.(*giteaClient)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.True(t, ok)
|
2019-08-26 09:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientNewGiteaInvalidURL(t *testing.T) {
|
|
|
|
ctx := &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
GiteaURLs: config.GiteaURLs{
|
2020-11-21 15:36:29 +02:00
|
|
|
API: "://gitea.com/api/v1",
|
2019-08-26 09:31:38 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
TokenType: context.TokenTypeGitea,
|
|
|
|
Token: "giteatoken",
|
|
|
|
}
|
|
|
|
client, err := New(ctx)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, client)
|
2019-08-26 09:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientNewGitLab(t *testing.T) {
|
|
|
|
ctx := &context.Context{
|
|
|
|
TokenType: context.TokenTypeGitLab,
|
|
|
|
Token: "gitlabtoken",
|
|
|
|
}
|
|
|
|
client, err := New(ctx)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2019-08-26 09:31:38 +02:00
|
|
|
_, ok := client.(*gitlabClient)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.True(t, ok)
|
2019-08-26 09:31:38 +02:00
|
|
|
}
|