@@ -39,6 +39,14 @@ type TestCase struct {
3939 GenPath string
4040}
4141
42+ type IntegrationGenOpts struct {
43+ BinaryPath string
44+ SpecPath string
45+ TargetDir string
46+ IsCrd bool
47+ ModelPackage string
48+ }
49+
4250func InitTestDirs (projectRoot string , buildBinary bool ) error {
4351 // calculate root dir of project/testdata/examples
4452 ProjectRoot = projectRoot
@@ -80,7 +88,7 @@ func InitTestDirs(projectRoot string, buildBinary bool) error {
8088 return nil
8189}
8290
83- func DoTestDirs (t * testing.T , dirs []string , convertFunc func (binaryPath , specPath , targetDir string , isCrd bool ) error , crd bool ) {
91+ func DoTestDirs (t * testing.T , dirs []string , convertFunc func (opts IntegrationGenOpts ) error , crd bool ) {
8492 for _ , dir := range dirs {
8593 testCases , err := FindCases (dir )
8694 if err != nil {
@@ -97,23 +105,26 @@ func DoTestDirs(t *testing.T, dirs []string, convertFunc func(binaryPath, specPa
97105 }
98106}
99107
100- func DoTestConvert (testDir string , tCase TestCase , convertFunc func (binaryPath , specPath , targetDir string , isCrd bool ) error , crd bool ) error {
108+ func DoTestConvert (testDir string , tCase TestCase , convertFunc func (opts IntegrationGenOpts ) error , crd bool ) error {
101109 var tmpPrefix string
110+ var modelPackage string
102111 if crd {
103112 tmpPrefix = tmpCrdGen
113+ modelPackage = "crd_models"
104114 } else {
105115 tmpPrefix = tmpOaiGen
116+ modelPackage = "models"
106117 }
107118 tmpDir , err := os .MkdirTemp (testDir , fmt .Sprintf ("%s_%s" , tmpPrefix , tCase .Name ))
108119 if err != nil {
109120 return fmt .Errorf ("creat temp output dir failed: %v" , err )
110121 }
111- err = convertFunc (BinaryPath , tCase .SpecPath , tmpDir , crd )
122+ err = convertFunc (IntegrationGenOpts { BinaryPath : BinaryPath , SpecPath : tCase .SpecPath , TargetDir : tmpDir , IsCrd : crd , ModelPackage : modelPackage } )
112123 if err != nil {
113124 return err
114125 }
115126 // compare two dir
116- err = CompareDir (filepath .Join (tCase .GenPath , "models" ), filepath .Join (tmpDir , "models" ))
127+ err = CompareDir (filepath .Join (tCase .GenPath , "models" ), filepath .Join (tmpDir , modelPackage ))
117128 if err != nil {
118129 return err
119130 }
@@ -218,15 +229,18 @@ func readLines(path string) ([]string, error) {
218229 return lines , scanner .Err ()
219230}
220231
221- func BinaryConvertModel (binaryPath string , sourceSpec string , outputDir string , crd bool ) error {
232+ func BinaryConvertModel (integrationGenOpts IntegrationGenOpts ) error {
222233 convertArgs := []string {
223234 "generate" , "model" , "-f" ,
224235 }
225- convertArgs = append (convertArgs , sourceSpec , "-t" , outputDir )
226- if crd {
236+ convertArgs = append (convertArgs , integrationGenOpts .SpecPath , "-t" , integrationGenOpts .TargetDir )
237+ if integrationGenOpts .ModelPackage != "models" {
238+ convertArgs = append (convertArgs , "-m" , integrationGenOpts .ModelPackage )
239+ }
240+ if integrationGenOpts .IsCrd {
227241 convertArgs = append (convertArgs , "--skip-validation" , "--crd" )
228242 }
229- cmd := exec .Command (binaryPath , convertArgs ... )
243+ cmd := exec .Command (integrationGenOpts . BinaryPath , convertArgs ... )
230244 cmd .Env = os .Environ ()
231245 var stdout , stderr bytes.Buffer
232246 cmd .Stdout = & stdout
0 commit comments