|
6 | 6 | "io" |
7 | 7 | "os" |
8 | 8 | "path" |
| 9 | + "path/filepath" |
9 | 10 | "testing" |
10 | 11 |
|
11 | 12 | "github.com/stretchr/testify/require" |
@@ -210,6 +211,38 @@ func TestBasicBuilder(t *testing.T) { |
210 | 211 | "basic template configuration is invalid: basic template config must have a non-empty input (templateDefinition.config.input),basic template config must have a non-empty output (templateDefinition.config.output)") |
211 | 212 | }, |
212 | 213 | }, |
| 214 | + { |
| 215 | + name: "successful basic build yaml output using contribution cwd to find inputs", |
| 216 | + validate: true, |
| 217 | + basicBuilder: NewBasicBuilder(BuilderConfig{ |
| 218 | + WorkingDir: testDir, |
| 219 | + OutputType: "yaml", |
| 220 | + ContributionPath: filepath.Join(testDir, "components"), |
| 221 | + }), |
| 222 | + templateDefinition: TemplateDefinition{ |
| 223 | + Schema: BasicBuilderSchema, |
| 224 | + Config: []byte(fmt.Sprintf(validConfigTemplate, "basic.yaml", "catalog.yaml")), |
| 225 | + }, |
| 226 | + files: map[string]string{ |
| 227 | + "components/basic.yaml": basicYaml, |
| 228 | + }, |
| 229 | + buildAssertions: func(t *testing.T, dir string, buildErr error) { |
| 230 | + require.NoError(t, buildErr) |
| 231 | + // check if the catalog.yaml file exists in the correct place |
| 232 | + filePath := path.Join(dir, "catalog.yaml") |
| 233 | + _, err := os.Stat(filePath) |
| 234 | + require.NoError(t, err) |
| 235 | + file, err := os.Open(filePath) |
| 236 | + require.NoError(t, err) |
| 237 | + defer file.Close() |
| 238 | + fileData, err := io.ReadAll(file) |
| 239 | + require.NoError(t, err) |
| 240 | + require.Equal(t, string(fileData), basicBuiltFbcYaml) |
| 241 | + }, |
| 242 | + validateAssertions: func(t *testing.T, validateErr error) { |
| 243 | + require.NoError(t, validateErr) |
| 244 | + }, |
| 245 | + }, |
213 | 246 | } |
214 | 247 |
|
215 | 248 | for i, tc := range testCases { |
@@ -673,6 +706,38 @@ func TestSemverBuilder(t *testing.T) { |
673 | 706 | ) |
674 | 707 | }, |
675 | 708 | }, |
| 709 | + { |
| 710 | + name: "successful semver build json output using contribution cwd to find inputs", |
| 711 | + validate: true, |
| 712 | + semverBuilder: NewSemverBuilder(BuilderConfig{ |
| 713 | + WorkingDir: testDir, |
| 714 | + OutputType: "json", |
| 715 | + ContributionPath: filepath.Join(testDir, "components"), |
| 716 | + }), |
| 717 | + templateDefinition: TemplateDefinition{ |
| 718 | + Schema: SemverBuilderSchema, |
| 719 | + Config: []byte(fmt.Sprintf(validConfigTemplate, "semver.yaml", "catalog.json")), |
| 720 | + }, |
| 721 | + files: map[string]string{ |
| 722 | + "components/semver.yaml": semverYaml, |
| 723 | + }, |
| 724 | + buildAssertions: func(t *testing.T, dir string, buildErr error) { |
| 725 | + require.NoError(t, buildErr) |
| 726 | + // check if the catalog.yaml file exists in the correct place |
| 727 | + filePath := path.Join(dir, "catalog.json") |
| 728 | + _, err := os.Stat(filePath) |
| 729 | + require.NoError(t, err) |
| 730 | + file, err := os.Open(filePath) |
| 731 | + require.NoError(t, err) |
| 732 | + defer file.Close() |
| 733 | + fileData, err := io.ReadAll(file) |
| 734 | + require.NoError(t, err) |
| 735 | + require.Equal(t, semverBuiltFbcJson, string(fileData)) |
| 736 | + }, |
| 737 | + validateAssertions: func(t *testing.T, validateErr error) { |
| 738 | + require.NoError(t, validateErr) |
| 739 | + }, |
| 740 | + }, |
676 | 741 | } |
677 | 742 |
|
678 | 743 | for i, tc := range testCases { |
@@ -1144,6 +1209,38 @@ func TestRawBuilder(t *testing.T) { |
1144 | 1209 | "raw template configuration is invalid: raw template config must have a non-empty input (templateDefinition.config.input),raw template config must have a non-empty output (templateDefinition.config.output)") |
1145 | 1210 | }, |
1146 | 1211 | }, |
| 1212 | + { |
| 1213 | + name: "successful raw build json output using contribution cwd to find inputs", |
| 1214 | + validate: true, |
| 1215 | + rawBuilder: NewRawBuilder(BuilderConfig{ |
| 1216 | + WorkingDir: testDir, |
| 1217 | + OutputType: "json", |
| 1218 | + ContributionPath: filepath.Join(testDir, "components"), |
| 1219 | + }), |
| 1220 | + templateDefinition: TemplateDefinition{ |
| 1221 | + Schema: RawBuilderSchema, |
| 1222 | + Config: []byte(fmt.Sprintf(validConfigTemplate, "raw.yaml", "catalog.json")), |
| 1223 | + }, |
| 1224 | + files: map[string]string{ |
| 1225 | + "components/raw.yaml": rawYaml, |
| 1226 | + }, |
| 1227 | + buildAssertions: func(t *testing.T, dir string, buildErr error) { |
| 1228 | + require.NoError(t, buildErr) |
| 1229 | + // check if the catalog.yaml file exists in the correct place |
| 1230 | + filePath := path.Join(dir, "catalog.json") |
| 1231 | + _, err := os.Stat(filePath) |
| 1232 | + require.NoError(t, err) |
| 1233 | + file, err := os.Open(filePath) |
| 1234 | + require.NoError(t, err) |
| 1235 | + defer file.Close() |
| 1236 | + fileData, err := io.ReadAll(file) |
| 1237 | + require.NoError(t, err) |
| 1238 | + require.Equal(t, string(fileData), rawBuiltFbcJson) |
| 1239 | + }, |
| 1240 | + validateAssertions: func(t *testing.T, validateErr error) { |
| 1241 | + require.NoError(t, validateErr) |
| 1242 | + }, |
| 1243 | + }, |
1147 | 1244 | } |
1148 | 1245 |
|
1149 | 1246 | for i, tc := range testCases { |
|
0 commit comments