|
4 | 4 | package component_test |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "path/filepath" |
7 | 8 | "testing" |
8 | 9 |
|
9 | 10 | "github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/component" |
@@ -61,4 +62,66 @@ func TestListComponents_OneComponent(t *testing.T) { |
61 | 62 | result := results[0] |
62 | 63 | assert.Equal(t, testComponentName, result.Name) |
63 | 64 | assert.Equal(t, testSpecPath, result.Spec.Path) |
| 65 | + assert.Empty(t, result.RenderedSpecDir, "RenderedSpecDir should be empty when rendered-specs-dir is not configured") |
| 66 | +} |
| 67 | + |
| 68 | +func TestListComponents_WithRenderedSpecsDir(t *testing.T) { |
| 69 | + const ( |
| 70 | + testComponentName = "vim" |
| 71 | + testSpecPath = "/path/to/spec" |
| 72 | + testRenderedDir = "/path/to/repo/specs" |
| 73 | + ) |
| 74 | + |
| 75 | + testEnv := testutils.NewTestEnv(t) |
| 76 | + testEnv.Config.Project.RenderedSpecsDir = testRenderedDir |
| 77 | + testEnv.Config.Components[testComponentName] = projectconfig.ComponentConfig{ |
| 78 | + Name: testComponentName, |
| 79 | + Spec: projectconfig.SpecSource{ |
| 80 | + Path: testSpecPath, |
| 81 | + }, |
| 82 | + } |
| 83 | + |
| 84 | + options := component.ListComponentOptions{ |
| 85 | + ComponentFilter: components.ComponentFilter{ |
| 86 | + ComponentNamePatterns: []string{testComponentName}, |
| 87 | + }, |
| 88 | + } |
| 89 | + |
| 90 | + results, err := component.ListComponentConfigs(testEnv.Env, &options) |
| 91 | + require.NoError(t, err) |
| 92 | + require.Len(t, results, 1) |
| 93 | + |
| 94 | + result := results[0] |
| 95 | + assert.Equal(t, testComponentName, result.Name) |
| 96 | + assert.Equal(t, filepath.Join(testRenderedDir, testComponentName), result.RenderedSpecDir) |
| 97 | +} |
| 98 | + |
| 99 | +func TestListComponents_MultipleWithRenderedSpecsDir(t *testing.T) { |
| 100 | + const testRenderedDir = "/rendered/specs" |
| 101 | + |
| 102 | + testEnv := testutils.NewTestEnv(t) |
| 103 | + testEnv.Config.Project.RenderedSpecsDir = testRenderedDir |
| 104 | + |
| 105 | + testEnv.Config.Components["curl"] = projectconfig.ComponentConfig{ |
| 106 | + Name: "curl", |
| 107 | + Spec: projectconfig.SpecSource{Path: "/specs/curl.spec"}, |
| 108 | + } |
| 109 | + testEnv.Config.Components["vim"] = projectconfig.ComponentConfig{ |
| 110 | + Name: "vim", |
| 111 | + Spec: projectconfig.SpecSource{Path: "/specs/vim.spec"}, |
| 112 | + } |
| 113 | + |
| 114 | + options := component.ListComponentOptions{ |
| 115 | + ComponentFilter: components.ComponentFilter{ |
| 116 | + IncludeAllComponents: true, |
| 117 | + }, |
| 118 | + } |
| 119 | + |
| 120 | + results, err := component.ListComponentConfigs(testEnv.Env, &options) |
| 121 | + require.NoError(t, err) |
| 122 | + require.Len(t, results, 2) |
| 123 | + |
| 124 | + for _, result := range results { |
| 125 | + assert.Equal(t, filepath.Join(testRenderedDir, result.Name), result.RenderedSpecDir) |
| 126 | + } |
64 | 127 | } |
0 commit comments