github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/program_driver_test.go (about)

     1  package test
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestBatches(t *testing.T) {
    14  	t.Parallel()
    15  	for _, n := range []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {
    16  		n := n
    17  		t.Run(fmt.Sprintf("%d", n), func(t *testing.T) {
    18  			t.Parallel()
    19  
    20  			var combined []ProgramTest
    21  			for i := 1; i <= n; i++ {
    22  				combined = append(combined, ProgramTestBatch(i, n)...)
    23  			}
    24  
    25  			assert.ElementsMatch(t, PulumiPulumiProgramTests, combined)
    26  		})
    27  	}
    28  }
    29  
    30  // Checks that all synced tests from pulumi/yaml are in test list
    31  func TestTranspiledExampleTestsCovered(t *testing.T) {
    32  	t.Parallel()
    33  	// Check that all synced tests from pulumi/yaml are in test list
    34  	syncDir := filepath.Join("testdata", transpiledExamplesDir)
    35  	untestedTranspiledExamples, err := getUntestedTranspiledExampleDirs(syncDir, PulumiPulumiYAMLProgramTests)
    36  	assert.Nil(t, err)
    37  	assert.Emptyf(t, untestedTranspiledExamples,
    38  		"Untested examples in %s: %v", syncDir, untestedTranspiledExamples)
    39  }
    40  
    41  func getUntestedTranspiledExampleDirs(baseDir string, tests []ProgramTest) ([]string, error) {
    42  	untested := make([]string, 0)
    43  	testedDirs := make(map[string]bool)
    44  	files, err := os.ReadDir(baseDir)
    45  	if err != nil {
    46  		return untested, err
    47  	}
    48  
    49  	for _, t := range tests {
    50  		if strings.HasPrefix(t.Directory, transpiledExamplesDir) {
    51  			dir := filepath.Base(t.Directory) + "-pp"
    52  			testedDirs[dir] = true
    53  		}
    54  	}
    55  	for _, f := range files {
    56  		if _, ok := testedDirs[f.Name()]; !ok && f.IsDir() {
    57  			untested = append(untested, f.Name())
    58  		}
    59  	}
    60  	return untested, nil
    61  }