Skip to content

Commit

Permalink
cleanup/refactory: Implement and refactor e2e tests for 'alpha genera…
Browse files Browse the repository at this point in the history
…te' 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
  • Loading branch information
camilamacedo86 committed Sep 23, 2024
1 parent 5950493 commit 124732f
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 290 deletions.
6 changes: 4 additions & 2 deletions pkg/config/v3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ func (c Cfg) ResourcesLength() int {

// HasResource implements config.Config
func (c Cfg) HasResource(gvk resource.GVK) bool {
found := false
for _, res := range c.Resources {
if gvk.IsEqualTo(res.GVK) {
return true
found = true
break
}
}

return false
return found
}

// GetResource implements config.Config
Expand Down
11 changes: 0 additions & 11 deletions pkg/plugin/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,3 @@ func ReplaceRegexInFile(path, match, replace string) error {
}
return nil
}

// HasFileContentWith check if given `text` can be found in file
func HasFileContentWith(path, text string) (bool, error) {
// nolint:gosec
contents, err := os.ReadFile(path)
if err != nil {
return false, err
}

return strings.Contains(string(contents), text), nil
}
270 changes: 0 additions & 270 deletions test/e2e/alphagenerate/generate_test.go

This file was deleted.

6 changes: 3 additions & 3 deletions test/e2e/externalplugin/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func GenerateProject(kbc *utils.TestContext) {
ExpectWithOffset(1, err).NotTo(HaveOccurred())

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

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

var webhookFileContentsTmpl = "A simple text file created with the `create webhook` subcommand\nHOOKED!"
webhookFileContainsExpr, err := pluginutil.HasFileContentWith(
webhookFileContainsExpr, err := pluginutil.HasFragment(
filepath.Join(kbc.Dir, "webhookFile.txt"), webhookFileContentsTmpl)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Check webhookFile.txt should return no error.")
ExpectWithOffset(1, webhookFileContainsExpr).To(BeTrue(), "The webhook file does not contain the expected expression.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package alphagenerate
package generate

import (
"fmt"
Expand Down
Loading

0 comments on commit 124732f

Please sign in to comment.