Skip to content

Commit 124732f

Browse files
cleanup/refactory: Implement and refactor e2e tests for 'alpha generate' command
- Added comprehensive end-to-end tests for the 'generate' command. - Ensured proper validation of the 'PROJECT' file after project initialization and regeneration. - Verified correct handling of multigroup layouts, Grafana, and DeployImage plugins. - Refactored the test structure to align with existing patterns used in other tests. - Improved maintainability and test coverage to support future growth and more scenarios. - Improve coverage to ensure more case scenarios
1 parent 5950493 commit 124732f

File tree

8 files changed

+307
-290
lines changed

8 files changed

+307
-290
lines changed

pkg/config/v3/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ func (c Cfg) ResourcesLength() int {
160160

161161
// HasResource implements config.Config
162162
func (c Cfg) HasResource(gvk resource.GVK) bool {
163+
found := false
163164
for _, res := range c.Resources {
164165
if gvk.IsEqualTo(res.GVK) {
165-
return true
166+
found = true
167+
break
166168
}
167169
}
168170

169-
return false
171+
return found
170172
}
171173

172174
// GetResource implements config.Config

pkg/plugin/util/util.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,3 @@ func ReplaceRegexInFile(path, match, replace string) error {
295295
}
296296
return nil
297297
}
298-
299-
// HasFileContentWith check if given `text` can be found in file
300-
func HasFileContentWith(path, text string) (bool, error) {
301-
// nolint:gosec
302-
contents, err := os.ReadFile(path)
303-
if err != nil {
304-
return false, err
305-
}
306-
307-
return strings.Contains(string(contents), text), nil
308-
}

test/e2e/alphagenerate/generate_test.go

Lines changed: 0 additions & 270 deletions
This file was deleted.

test/e2e/externalplugin/generate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func GenerateProject(kbc *utils.TestContext) {
6767
ExpectWithOffset(1, err).NotTo(HaveOccurred())
6868

6969
var initFileContentsTmpl = "A simple text file created with the `init` subcommand\nDOMAIN: sample.domain.com"
70-
initFileContainsExpr, err := pluginutil.HasFileContentWith(
70+
initFileContainsExpr, err := pluginutil.HasFragment(
7171
filepath.Join(kbc.Dir, "initFile.txt"), initFileContentsTmpl)
7272
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Check initFile.txt should return no error.")
7373
ExpectWithOffset(1, initFileContainsExpr).To(BeTrue(), "The init file does not contain the expected expression.")
@@ -83,7 +83,7 @@ func GenerateProject(kbc *utils.TestContext) {
8383
ExpectWithOffset(1, err).NotTo(HaveOccurred())
8484

8585
var apiFileContentsTmpl = "A simple text file created with the `create api` subcommand\nNUMBER: 2"
86-
apiFileContainsExpr, err := pluginutil.HasFileContentWith(
86+
apiFileContainsExpr, err := pluginutil.HasFragment(
8787
filepath.Join(kbc.Dir, "apiFile.txt"), apiFileContentsTmpl)
8888
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Check apiFile.txt should return no error.")
8989
ExpectWithOffset(1, apiFileContainsExpr).To(BeTrue(), "The api file does not contain the expected expression.")
@@ -99,7 +99,7 @@ func GenerateProject(kbc *utils.TestContext) {
9999
ExpectWithOffset(1, err).NotTo(HaveOccurred())
100100

101101
var webhookFileContentsTmpl = "A simple text file created with the `create webhook` subcommand\nHOOKED!"
102-
webhookFileContainsExpr, err := pluginutil.HasFileContentWith(
102+
webhookFileContainsExpr, err := pluginutil.HasFragment(
103103
filepath.Join(kbc.Dir, "webhookFile.txt"), webhookFileContentsTmpl)
104104
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Check webhookFile.txt should return no error.")
105105
ExpectWithOffset(1, webhookFileContainsExpr).To(BeTrue(), "The webhook file does not contain the expected expression.")

test/e2e/alphagenerate/e2e_suite_test.go renamed to test/e2e/generate/e2e_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package alphagenerate
17+
package generate
1818

1919
import (
2020
"fmt"

0 commit comments

Comments
 (0)