1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

refactor(artifactory): we don't do anything with the response json (#1753)

* fix: ignore EOF on artifactory

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: dont even need to read that

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: remove artifactoryResponse

* refactor: remove artifactoryChecksums

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2020-09-06 11:03:17 -03:00 committed by GitHub
parent c4dfc3a1e7
commit 88db1d0bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 88 deletions

View File

@ -12,28 +12,6 @@ import (
"github.com/goreleaser/goreleaser/pkg/context"
)
// artifactoryResponse reflects the response after an upload request
// to Artifactory.
type artifactoryResponse struct {
Repo string `json:"repo,omitempty"`
Path string `json:"path,omitempty"`
Created string `json:"created,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
DownloadURI string `json:"downloadUri,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Size string `json:"size,omitempty"`
Checksums artifactoryChecksums `json:"checksums,omitempty"`
OriginalChecksums artifactoryChecksums `json:"originalChecksums,omitempty"`
URI string `json:"uri,omitempty"`
}
// artifactoryChecksums reflects the checksums generated by Artifactory.
type artifactoryChecksums struct {
SHA1 string `json:"sha1,omitempty"`
MD5 string `json:"md5,omitempty"`
SHA256 string `json:"sha256,omitempty"`
}
// Pipe for Artifactory.
type Pipe struct{}
@ -68,14 +46,7 @@ func (Pipe) Publish(ctx *context.Context) error {
}
}
return http.Upload(ctx, ctx.Config.Artifactories, "artifactory", func(res *h.Response) error {
if err := checkResponse(res); err != nil {
return err
}
var r artifactoryResponse
err := json.NewDecoder(res.Body).Decode(&r)
return err
})
return http.Upload(ctx, ctx.Config.Artifactories, "artifactory", checkResponse)
}
// An ErrorResponse reports one or more errors caused by an API request.
@ -103,6 +74,7 @@ type Error struct {
// body, or a JSON response body that maps to ErrorResponse. Any other
// response body will be silently ignored.
func checkResponse(r *h.Response) error {
defer r.Body.Close()
if c := r.StatusCode; 200 <= c && c <= 299 {
return nil
}

View File

@ -507,64 +507,6 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
assert.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: invalid character '.' looking for beginning of value`)
}
func TestRunPipe_UnparsableResponse(t *testing.T) {
setup()
defer teardown()
folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(t, err)
var dist = filepath.Join(folder, "dist")
assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin")
d1 := []byte("hello\ngo\n")
err = ioutil.WriteFile(binPath, d1, 0666)
assert.NoError(t, err)
// Dummy artifactory with invalid JSON
mux.HandleFunc("/example-repo-local/mybin/darwin/amd64/mybin", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
testHeader(t, r, "Content-Length", "9")
// Basic auth of user "deployuser" with secret "deployuser-secret"
testHeader(t, r, "Authorization", "Basic ZGVwbG95dXNlcjpkZXBsb3l1c2VyLXNlY3JldA==")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `invalid-json{
"repo" : "example-repo-local",
...
}`)
})
var ctx = context.New(config.Project{
ProjectName: "mybin",
Dist: dist,
Artifactories: []config.Upload{
{
Name: "production",
Mode: "binary",
Target: fmt.Sprintf("%s/example-repo-local/{{ .ProjectName }}/{{ .Os }}/{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}", server.URL),
Username: "deployuser",
},
},
Archives: []config.Archive{
{},
},
})
ctx.Env = map[string]string{
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
}
ctx.Artifacts.Add(&artifact.Artifact{
Name: "mybin",
Path: binPath,
Goarch: "amd64",
Goos: "darwin",
Type: artifact.UploadableBinary,
})
assert.NoError(t, Pipe{}.Default(ctx))
assert.EqualError(t, Pipe{}.Publish(ctx), `artifactory: upload failed: invalid character 'i' looking for beginning of value`)
}
func TestRunPipe_FileNotFound(t *testing.T) {
var ctx = context.New(config.Project{
ProjectName: "mybin",