Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(graphql): fix broken tests for chaoscenter/graphql/server and integrate mockery to generate mocks #4372

Merged
merged 9 commits into from
Jan 12, 2024
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ To submit any kinds of improvements, please consider the following:

If you are new to Go, consider reading [Effective Go](https://golang.org/doc/effective_go.html) and [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments) for guidance on writing idiomatic Go code.

### Generating/Updating Mocks for `chaoscenter/graphql/server`

To generate new mocks or update existing mocks:

- Follow the instructions to install [mockery](https://vektra.github.io/mockery/latest/installation/).
- If generating mocks for existing interface simply run `mockery`.
- If generating mocks for new interface update [`.mockery.yaml`](././chaoscenter/graphql/server/.mockery.yaml) and run `mockery`.

---

## Pull Request Checklist :
Expand Down
20 changes: 20 additions & 0 deletions chaoscenter/graphql/server/.mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
with-expecter: true
packages:
github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaos_experiment/ops:
interfaces:
Service:
# Modify package-level config for this specific interface (if applicable)
config:
dir: "pkg/chaos_experiment/model/mocks"
filename: "service.go"
mockname: ChaosExperimentService
outpkg: mocks
github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaos_experiment_run:
interfaces:
Service:
# Modify package-level config for this specific interface (if applicable)
config:
dir: "pkg/chaos_experiment_run/model/mocks"
filename: "service.go"
mockname: ChaosExperimentRunService
outpkg: mocks
320 changes: 140 additions & 180 deletions chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler_test.go

Large diffs are not rendered by default.

335 changes: 317 additions & 18 deletions chaoscenter/graphql/server/pkg/chaos_experiment/model/mocks/service.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ func TestGetChartsData(t *testing.T) {
RepoURL: "https://github.com/litmuschaos/chaos-charts",
RepoBranch: "master",
IsPrivate: false,
IsDefault: false,
},
isError: false,
},
Expand All @@ -296,6 +297,7 @@ func TestGetChartsData(t *testing.T) {
RepoURL: "invalid url",
RepoBranch: "master",
IsPrivate: false,
IsDefault: true,
},
isError: true,
},
Expand All @@ -304,7 +306,7 @@ func TestGetChartsData(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
if tc.isError {
// when
chartsPath := handler.GetChartsPath(tc.repoData, tc.projectID, false)
chartsPath := handler.GetChartsPath(tc.repoData, tc.projectID, tc.repoData.IsDefault)
_, err := handler.GetChartsData(chartsPath)
// then
assert.Error(t, err)
Expand All @@ -314,7 +316,7 @@ func TestGetChartsData(t *testing.T) {

err := chaosHubOps.GitClone(tc.repoData, tc.projectID)
assert.NoError(t, err)
chartsPath := handler.GetChartsPath(tc.repoData, tc.projectID, true)
chartsPath := handler.GetChartsPath(tc.repoData, tc.projectID, tc.repoData.IsDefault)
// when
_, err = handler.GetChartsData(chartsPath)
// then
Expand Down Expand Up @@ -386,11 +388,13 @@ func TestListPredefinedWorkflowDetails(t *testing.T) {
hubName string
isError bool
}{
{
name: "success: list predefined workflows",
projectID: succeedProjectID,
hubName: succeedName,
},
// Workflows were removed in v3.0.0
// TODO: Cleanup ListPredefinedWorkflowDetails if not needed
// {
// name: "success: list predefined workflows",
// projectID: succeedProjectID,
// hubName: succeedName,
// },
{
name: "failure: Not defined workflows",
projectID: uuid.New().String(),
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/graphql/server/pkg/chaoshub/ops/gitops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestGetClonePath(t *testing.T) {
// when
path := chaosHubOps.GetClonePath(chaosHubConfig)
// then
assert.Equal(t, "/tmp/version/"+projectID+"/test", path)
assert.Equal(t, "/tmp/"+projectID+"/test", path)
}

// TestGitConfigConstruct is used to test the GitConfigConstruct function
Expand Down
Loading