mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-03 13:11:48 +02:00
test: increase github client test coverage (#1179)
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
423308443c
commit
622254a7df
71
internal/client/github_test.go
Normal file
71
internal/client/github_test.go
Normal file
@ -0,0 +1,71 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewGitHubClient(t *testing.T) {
|
||||
t.Run("good urls", func(t *testing.T) {
|
||||
_, err := NewGitHub(context.New(config.Project{
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
API: "https://github.mycompany.com/api",
|
||||
Upload: "https://github.mycompany.com/upload",
|
||||
},
|
||||
}))
|
||||
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("bad api url", func(t *testing.T) {
|
||||
_, err := NewGitHub(context.New(config.Project{
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
API: "://github.mycompany.com/api",
|
||||
Upload: "https://github.mycompany.com/upload",
|
||||
},
|
||||
}))
|
||||
|
||||
require.EqualError(t, err, "parse ://github.mycompany.com/api: missing protocol scheme")
|
||||
})
|
||||
|
||||
t.Run("bad upload url", func(t *testing.T) {
|
||||
_, err := NewGitHub(context.New(config.Project{
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
API: "https://github.mycompany.com/api",
|
||||
Upload: "not a url:4994",
|
||||
},
|
||||
}))
|
||||
|
||||
require.EqualError(t, err, "parse not a url:4994: first path segment in URL cannot contain colon")
|
||||
})
|
||||
}
|
||||
|
||||
func TestGitHubUploadReleaseIDNotInt(t *testing.T) {
|
||||
var ctx = context.New(config.Project{})
|
||||
client, err := NewGitHub(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.EqualError(
|
||||
t,
|
||||
client.Upload(ctx, "blah", &artifact.Artifact{}, nil),
|
||||
`strconv.ParseInt: parsing "blah": invalid syntax`,
|
||||
)
|
||||
}
|
||||
|
||||
func TestGitHubCreateReleaseWrongNameTemplate(t *testing.T) {
|
||||
var ctx = context.New(config.Project{
|
||||
Release: config.Release{
|
||||
NameTemplate: "{{.dddddddddd",
|
||||
},
|
||||
})
|
||||
client, err := NewGitHub(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
str, err := client.CreateRelease(ctx, "")
|
||||
require.Empty(t, str)
|
||||
require.EqualError(t, err, `template: tmpl:1: unclosed action`)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user