Skip to content

Commit

Permalink
Fixed a bug in tarball handling (#1068)
Browse files Browse the repository at this point in the history
* Fixed a bug in tarball handling

* Fixed the tests failing due to error message changes.
  • Loading branch information
Ark-kun authored Mar 30, 2019
1 parent f8b0f5b commit fa8299d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions backend/src/apiserver/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ func DecompressPipelineTarball(compressedFile []byte) ([]byte, error) {
return nil, util.NewInvalidInputErrorWithDetails(err, "Error extracting pipeline from the tarball file. Not a valid tarball file.")
}
tarReader = tar.NewReader(gzipReader)
header, err := tarReader.Next()
if err != nil {
return nil, util.NewInvalidInputErrorWithDetails(err, "Error extracting pipeline from the tarball file. Not a valid tarball file.")
}
if !isYamlFile(header.Name) {
return nil, util.NewInvalidInputError("Error extracting pipeline from the tarball file. Expecting a pipeline.yaml file inside the tarball. Got: %v", header.Name)
}
}

header, err := tarReader.Next()
if err != nil {
return nil, util.NewInvalidInputErrorWithDetails(err, "Error extracting pipeline from the tarball file. Not a valid tarball file.")
}
if !isYamlFile(header.Name) {
return nil, util.NewInvalidInputError("Error extracting pipeline from the tarball file. Expecting a pipeline.yaml file inside the tarball. Got: %v", header.Name)
}
decompressedFile, err := ioutil.ReadAll(tarReader)
if err != nil {
return nil, util.NewInvalidInputErrorWithDetails(err, "Error reading pipeline YAML from the tarball file.")
Expand Down
4 changes: 2 additions & 2 deletions backend/src/apiserver/server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestDecompressPipelineTarball_NonYamlTarball(t *testing.T) {
tarballByte, _ := ioutil.ReadFile("test/non_yaml_tarball/non_yaml_tarball.tar.gz")
_, err := DecompressPipelineTarball(tarballByte)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Expecting a YAML file inside the tarball")
assert.Contains(t, err.Error(), "Expecting a pipeline.yaml file inside the tarball")
}

func TestDecompressPipelineTarball_EmptyTarball(t *testing.T) {
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestDecompressPipelineZip_NonYamlZip(t *testing.T) {
zipByte, _ := ioutil.ReadFile("test/non_yaml_zip/non_yaml_file.zip")
_, err := DecompressPipelineZip(zipByte)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Expecting a YAML file inside the zip")
assert.Contains(t, err.Error(), "Expecting a pipeline.yaml file inside the zip")
}

func TestDecompressPipelineZip_EmptyZip(t *testing.T) {
Expand Down

0 comments on commit fa8299d

Please sign in to comment.