Skip to content

Commit

Permalink
Conditionally print dir/zip contents
Browse files Browse the repository at this point in the history
  • Loading branch information
jongio committed Sep 16, 2024
1 parent 6d8333c commit a3aa556
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions cli/azd/test/functional/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) {
ctx, cancel := newTestContext(t)
defer cancel()

// Set this to true if you want to print the directory and zip contents for debugging
printDebug := false

// Create a temporary directory for the project
dir := tempDirWithDiagnostics(t)

Expand All @@ -180,9 +183,11 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) {
err := copySample(dir, "dotignore")
require.NoError(t, err, "failed expanding sample")

// Print directory contents for debugging
printDirContents(t, "service1", filepath.Join(dir, "src", "service1"))
printDirContents(t, "service2", filepath.Join(dir, "src", "service2"))
// Print directory contents for debugging if printDebug is true
if printDebug {
printDirContents(t, "service1", filepath.Join(dir, "src", "service1"))
printDirContents(t, "service2", filepath.Join(dir, "src", "service2"))
}

// Run the init command to initialize the project
_, err = cli.RunCommandWithStdIn(
Expand Down Expand Up @@ -319,8 +324,10 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) {
require.NoError(t, err)
}

// Print directory contents after writing .zipignore
printDirContents(t, "service1", filepath.Join(dir, "src", "service1"))
// Print directory contents after writing .zipignore if printDebug is true
if printDebug {
printDirContents(t, "service1", filepath.Join(dir, "src", "service1"))
}

// Run the package command and specify an output path
outputDir := filepath.Join(dir, "dist_"+strings.ReplaceAll(scenario.name, " ", "_"))
Expand All @@ -330,19 +337,21 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) {
_, err = cli.RunCommand(ctx, "package", "--output-path", outputDir)
require.NoError(t, err)

// Print directory contents of the output directory
printDirContents(t, scenario.name+" output", outputDir)
// Print directory contents of the output directory if printDebug is true
if printDebug {
printDirContents(t, scenario.name+" output", outputDir)
}

// Verify that the package was created and the output directory exists
files, err := os.ReadDir(outputDir)
require.NoError(t, err)
require.Len(t, files, 2)

// Check contents of Service1 package
checkServicePackage(t, outputDir, "service1", scenario.expectedFiles["service1"])
checkServicePackage(t, outputDir, "service1", scenario.expectedFiles["service1"], printDebug)

// Check contents of Service2 package
checkServicePackage(t, outputDir, "service2", scenario.expectedFiles["service2"])
checkServicePackage(t, outputDir, "service2", scenario.expectedFiles["service2"], printDebug)

// Clean up .zipignore files and generated zip files
os.RemoveAll(outputDir)
Expand All @@ -353,9 +362,11 @@ func Test_CLI_Package_ZipIgnore(t *testing.T) {
}

// Helper function to check service package contents
func checkServicePackage(t *testing.T, distPath, serviceName string, expectedFiles map[string]bool) {
func checkServicePackage(t *testing.T, distPath, serviceName string, expectedFiles map[string]bool, printDebug bool) {
zipFilePath := findServiceZipFile(t, distPath, serviceName)
printZipContents(t, serviceName, zipFilePath) // Print the contents of the zip file
if printDebug {
printZipContents(t, serviceName, zipFilePath) // Print the contents of the zip file if printDebug is true
}
zipReader, err := zip.OpenReader(zipFilePath)
require.NoError(t, err)
defer zipReader.Close()
Expand Down

0 comments on commit a3aa556

Please sign in to comment.