Skip to content

Commit

Permalink
add mock validator
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinForReal committed Dec 2, 2024
1 parent 272b958 commit a02b8df
Show file tree
Hide file tree
Showing 39 changed files with 905 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/azclient/accountclient/custom_test.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/accountclient/mock.go

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

15 changes: 15 additions & 0 deletions pkg/azclient/accountclient/mock_accountclient/interface.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/availabilitysetclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/blobcontainerclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/blobservicepropertiesclient/mock.go

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

26 changes: 24 additions & 2 deletions pkg/azclient/client-gen/generator/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"go/ast"
"os"
"os/exec"
"text/template"

"sigs.k8s.io/controller-tools/pkg/genall"
"sigs.k8s.io/controller-tools/pkg/loader"
Expand Down Expand Up @@ -62,7 +63,6 @@ func (generator MockGenerator) Generate(ctx *genall.GenerationContext) error {
if marker == nil {
return
}

mockFile, err := ctx.OutputRule.Open(root, "mock_"+root.Name+"/interface.go")
if err != nil {
root.AddError(err)
Expand All @@ -78,7 +78,24 @@ func (generator MockGenerator) Generate(ctx *genall.GenerationContext) error {
root.AddError(err)
return
}

mockVerifier, err := ctx.OutputRule.Open(root, "mock.go")
if err != nil {
root.AddError(err)
return
}
defer mockVerifier.Close()
var importList = make(map[string]map[string]struct{})
importList[root.ID+"/mock_"+root.Name] = make(map[string]struct{})
err = DumpHeaderToWriter(ctx, mockVerifier, generator.HeaderFile, importList, root.Name)
if err != nil {
root.AddError(err)
return
}
err = MockVerifyTemplate.Execute(mockVerifier, root.Name)
if err != nil {
root.AddError(err)
return
}
})
if err != nil {
break
Expand Down Expand Up @@ -109,3 +126,8 @@ func (MockGenerator) CheckFilter() loader.NodeFilter {
return isIface
}
}

var MockVerifyTemplate = template.Must(template.New("object-scaffolding-mock-verify").Parse(
`
var _ Interface = &mock_{{.}}.MockInterface{}
`))
24 changes: 24 additions & 0 deletions pkg/azclient/deploymentclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/diskclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/fileservicepropertiesclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/fileshareclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/identityclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/interfaceclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/ipgroupclient/mock.go

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

24 changes: 24 additions & 0 deletions pkg/azclient/loadbalancerclient/mock.go

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

Loading

0 comments on commit a02b8df

Please sign in to comment.