github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/integration/contracts_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package main 5 6 import ( 7 "io" 8 "os" 9 "path/filepath" 10 "testing" 11 12 "github.com/SAP/jenkins-library/pkg/generator/helper" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestCommandContract(t *testing.T) { 17 assert.Equal(t, "", "") 18 } 19 20 // Test provided by consumer: SAP InnerSource project 21 // Changes to the test require peer review by core-team members involved in the project. 22 func TestGenerator(t *testing.T) { 23 dir := t.TempDir() 24 25 metadata := `metadata: 26 name: test 27 description: testDescription 28 longDescription: testLongDescription 29 spec: 30 inputs: 31 secrets: 32 - name: secret 33 description: secretDescription 34 type: jenkins 35 params: 36 - name: testParam 37 aliases: 38 - name: testAlias 39 type: string 40 description: The name of the Checkmarx project to scan into 41 mandatory: true 42 scope: 43 - PARAMETERS 44 - STAGES 45 - STEPS 46 resourceRef: 47 - name: commonPipelineEnvironment 48 param: test/test 49 outputs: 50 resources: 51 - name: influx 52 type: influx 53 params: 54 - name: test_influx 55 fields: 56 - name: testfield 57 - name: commonPipelineEnvironment 58 type: piperEnvironment 59 params: 60 - name: test_cpe 61 ` 62 63 os.WriteFile(filepath.Join(dir, "test.yaml"), []byte(metadata), 0755) 64 65 openMetaFile := func(name string) (io.ReadCloser, error) { return os.Open(name) } 66 fileWriter := func(filename string, data []byte, perm os.FileMode) error { return nil } 67 68 stepHelperData := helper.StepHelperData{OpenFile: openMetaFile, WriteFile: fileWriter, ExportPrefix: "piperOsCmd"} 69 70 metadataFiles, err := helper.MetadataFiles(dir) 71 assert.NoError(t, err) 72 73 err = helper.ProcessMetaFiles(metadataFiles, "./cmd", stepHelperData) 74 assert.NoError(t, err) 75 }