Skip to content

Commit

Permalink
fix error-code (#1646)
Browse files Browse the repository at this point in the history
* fix error-code

* add test

* fix test

* change output to int

* fix test
  • Loading branch information
sunkickr authored May 10, 2024
1 parent 76cc36b commit 3483791
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions airflow/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,9 @@ func (d *DockerCompose) UpgradeTest(newAirflowVersion, deploymentID, newImageNam
return err
}
}
var errorCode int
if dagTest {
err := d.dagTest(testHomeDirectory, newAirflowVersion, newDockerFile, customImage, buildSecretString)
errorCode, err = d.dagTest(testHomeDirectory, newAirflowVersion, newDockerFile, customImage, buildSecretString)
if err != nil {
return err
}
Expand All @@ -616,6 +617,9 @@ func (d *DockerCompose) UpgradeTest(newAirflowVersion, deploymentID, newImageNam
if dagTest {
fmt.Printf("\tDAG Parse Test HTML Report: %s\n", "dag-test-report.html")
}
if errorCode == 1 {
return errors.New("one of the tests run above failed")
}

return nil
}
Expand Down Expand Up @@ -703,13 +707,13 @@ func (d *DockerCompose) versionTest(testHomeDirectory, currentAirflowVersion, de
return nil
}

func (d *DockerCompose) dagTest(testHomeDirectory, newAirflowVersion, newDockerFile, customImage, buildSecretString string) error {
func (d *DockerCompose) dagTest(testHomeDirectory, newAirflowVersion, newDockerFile, customImage, buildSecretString string) (int, error) {
fmt.Printf("\nChecking the DAGs in this project for errors against the new Airflow version %s\n", newAirflowVersion)

// build image with the new runtime version
err := upgradeDockerfile(d.dockerfile, newDockerFile, newAirflowVersion, customImage)
if err != nil {
return err
return 1, err
}

// add pytest-html to the requirements
Expand All @@ -726,19 +730,18 @@ func (d *DockerCompose) dagTest(testHomeDirectory, newAirflowVersion, newDockerF
fmt.Printf("Removing package 'pytest-html' from requirements.txt unsuccessful: %s\n", err.Error())
}
if imageBuildErr != nil {
return imageBuildErr
return 1, imageBuildErr
}
// check for file
path := d.airflowHome + "/" + DefaultTestPath

fileExist, err := util.Exists(path)
if err != nil {
return err
return 1, err
}
if !fileExist {
fmt.Println("\nThe file " + path + " which is needed for the parse test does not exist. Please run `astro dev init` to create it")

return err
return 1, err
}
// run parse test
pytestFile := DefaultTestPath
Expand All @@ -750,13 +753,14 @@ func (d *DockerCompose) dagTest(testHomeDirectory, newAirflowVersion, newDockerF
if err != nil {
if strings.Contains(exitCode, "1") { // exit code is 1 meaning tests failed
fmt.Println("See above for errors detected in your DAGs")
return 1, nil
} else {
return errors.Wrap(err, "something went wrong while parsing your DAGs")
return 1, errors.Wrap(err, "something went wrong while parsing your DAGs")
}
} else {
fmt.Println("\n" + ansi.Green("✔") + " no errors detected in your DAGs ")
}
return nil
return 0, nil
}

func upgradeDockerfile(oldDockerfilePath, newDockerfilePath, newTag, newImage string) error { //nolint:gocognit
Expand Down
2 changes: 1 addition & 1 deletion airflow/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ func TestDockerComposedUpgradeTest(t *testing.T) {
imageHandler.On("ConflictTest", mock.Anything, mock.Anything, airflowTypes.ImageBuildConfig{Path: mockDockerCompose.airflowHome, Output: true, NoCache: false}).Return("", nil).Once()
imageHandler.On("CreatePipFreeze", mock.Anything, cwd+"/"+pipFreeze).Return(nil).Once()
imageHandler.On("CreatePipFreeze", mock.Anything, cwd+"/"+pipFreeze2).Return(nil).Once()
imageHandler.On("Pytest", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, airflowTypes.ImageBuildConfig{Path: mockDockerCompose.airflowHome, Output: true, NoCache: false}).Return("0", errMockDocker).Once()
imageHandler.On("Pytest", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, airflowTypes.ImageBuildConfig{Path: mockDockerCompose.airflowHome, Output: true, NoCache: false}).Return("1", errMockDocker).Once()

mockDockerCompose.imageHandler = imageHandler

Expand Down

0 comments on commit 3483791

Please sign in to comment.