|
4 | 4 | "os" |
5 | 5 | "testing" |
6 | 6 |
|
7 | | - "github.com/stretchr/testify/mock" |
8 | 7 | "gopkg.in/yaml.v2" |
9 | 8 |
|
10 | 9 | plural "github.com/pluralsh/plural/cmd/plural" |
@@ -76,93 +75,3 @@ func TestBuildContext(t *testing.T) { |
76 | 75 | }) |
77 | 76 | } |
78 | 77 | } |
79 | | - |
80 | | -func TestValidate(t *testing.T) { |
81 | | - tests := []struct { |
82 | | - name string |
83 | | - args []string |
84 | | - installations []*api.Installation |
85 | | - charts []*api.ChartInstallation |
86 | | - tfs []*api.TerraformInstallation |
87 | | - pm manifest.ProjectManifest |
88 | | - ctx manifest.Context |
89 | | - expectedResponse string |
90 | | - }{ |
91 | | - { |
92 | | - name: `test "validate"`, |
93 | | - args: []string{plural.ApplicationName, "validate"}, |
94 | | - installations: []*api.Installation{{ |
95 | | - Id: "abc", |
96 | | - Repository: &api.Repository{ |
97 | | - Id: "abc", |
98 | | - Name: "abc", |
99 | | - }, |
100 | | - }, |
101 | | - { |
102 | | - Id: "cde", |
103 | | - Repository: &api.Repository{ |
104 | | - Id: "cde", |
105 | | - Name: "cde", |
106 | | - }, |
107 | | - }, |
108 | | - }, |
109 | | - pm: manifest.ProjectManifest{ |
110 | | - Cluster: "test", |
111 | | - Bucket: "test", |
112 | | - Project: "test", |
113 | | - Provider: "kind", |
114 | | - Region: "test", |
115 | | - }, |
116 | | - ctx: manifest.Context{ |
117 | | - Bundles: []*manifest.Bundle{ |
118 | | - { |
119 | | - Repository: "cde", |
120 | | - Name: "cde", |
121 | | - }, |
122 | | - { |
123 | | - Repository: "abc", |
124 | | - Name: "abc", |
125 | | - }, |
126 | | - }, |
127 | | - }, |
128 | | - tfs: []*api.TerraformInstallation{}, |
129 | | - charts: []*api.ChartInstallation{}, |
130 | | - }, |
131 | | - } |
132 | | - for _, test := range tests { |
133 | | - t.Run(test.name, func(t *testing.T) { |
134 | | - // create temp environment |
135 | | - currentDir, err := os.Getwd() |
136 | | - assert.NoError(t, err) |
137 | | - dir, err := os.MkdirTemp("", "config") |
138 | | - assert.NoError(t, err) |
139 | | - defer func(path, currentDir string) { |
140 | | - _ = os.RemoveAll(path) |
141 | | - _ = os.Chdir(currentDir) |
142 | | - }(dir, currentDir) |
143 | | - |
144 | | - err = os.Chdir(dir) |
145 | | - assert.NoError(t, err) |
146 | | - |
147 | | - data, err := yaml.Marshal(test.pm) |
148 | | - assert.NoError(t, err) |
149 | | - err = os.WriteFile("workspace.yaml", data, os.FileMode(0755)) |
150 | | - assert.NoError(t, err) |
151 | | - |
152 | | - data, err = yaml.Marshal(test.ctx) |
153 | | - assert.NoError(t, err) |
154 | | - err = os.WriteFile("context.yaml", data, os.FileMode(0755)) |
155 | | - assert.NoError(t, err) |
156 | | - |
157 | | - client := mocks.NewClient(t) |
158 | | - client.On("GetInstallations").Return(test.installations, nil) |
159 | | - client.On("GetPackageInstallations", mock.AnythingOfType("string")).Return(test.charts, test.tfs, nil) |
160 | | - app := plural.CreateNewApp(&plural.Plural{Client: client}) |
161 | | - app.HelpName = plural.ApplicationName |
162 | | - os.Args = test.args |
163 | | - resp, err := captureStdout(app, os.Args) |
164 | | - assert.NoError(t, err) |
165 | | - assert.Equal(t, test.expectedResponse, resp) |
166 | | - }) |
167 | | - } |
168 | | -} |
0 commit comments