Skip to content

Commit

Permalink
Merge pull request #654 from uber/config_file_path
Browse files Browse the repository at this point in the history
Make config file a parameter for mocks. 

For mocks generation, the config file was always configured to be test.yaml. This has now been updated to provide a custom config path (yaml or JSON) as required by the gateway service.
  • Loading branch information
tejaswiagarwal committed Oct 7, 2019
2 parents 6662cd7 + c9829f0 commit f018151
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion codegen/module_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func NewDefaultModuleSystemWithMockHook(
clientsMock bool,
workflowMock bool,
serviceMock bool,
configFile string,
hooks ...PostGenHook,
) (*ModuleSystem, error) {
t, err := NewDefaultTemplate()
Expand All @@ -255,7 +256,7 @@ func NewDefaultModuleSystemWithMockHook(
}

if serviceMock {
serviceMockGenHook = ServiceMockGenHook(h, t)
serviceMockGenHook = ServiceMockGenHook(h, t, configFile)
hooks = append(hooks, serviceMockGenHook)
}

Expand Down
8 changes: 4 additions & 4 deletions codegen/post_gen_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func ClientMockGenHook(h *PackageHelper, t *Template) (PostGenHook, error) {
}

// ServiceMockGenHook returns a PostGenHook to generate service mocks
func ServiceMockGenHook(h *PackageHelper, t *Template) PostGenHook {
func ServiceMockGenHook(h *PackageHelper, t *Template, configFile string) PostGenHook {
return func(instances map[string][]*ModuleInstance) error {
mockCount := len(instances["service"])
fmt.Printf("Generating %d service mocks:\n", mockCount)
Expand All @@ -250,7 +250,7 @@ func ServiceMockGenHook(h *PackageHelper, t *Template) PostGenHook {
}
files.Store(filepath.Join(genDir, "mock_init.go"), mockInit)

mockService, err := generateServiceMock(instance, h, t)
mockService, err := generateServiceMock(instance, h, t, configFile)
if err != nil {
ec <- errors.Wrapf(
err,
Expand Down Expand Up @@ -314,8 +314,8 @@ func generateMockInitializer(instance *ModuleInstance, h *PackageHelper, t *Temp
}

// generateServiceMock generates mock service
func generateServiceMock(instance *ModuleInstance, h *PackageHelper, t *Template) ([]byte, error) {
configPath := path.Join(strings.Replace(instance.Directory, "services", "config", 1), "test.yaml")
func generateServiceMock(instance *ModuleInstance, h *PackageHelper, t *Template, configFile string) ([]byte, error) {
configPath := path.Join(strings.Replace(instance.Directory, "services", "config", 1), configFile)
if _, err := os.Stat(filepath.Join(h.ConfigRoot(), configPath)); err != nil {
if os.IsNotExist(err) {
configPath = "config/test.yaml"
Expand Down
2 changes: 1 addition & 1 deletion codegen/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func main() {
}
var moduleSystem *codegen.ModuleSystem
if genMock {
moduleSystem, err = codegen.NewDefaultModuleSystemWithMockHook(packageHelper, true, true, true)
moduleSystem, err = codegen.NewDefaultModuleSystemWithMockHook(packageHelper, true, true, true, "test.json")
} else {
moduleSystem, err = codegen.NewDefaultModuleSystem(packageHelper)
}
Expand Down

0 comments on commit f018151

Please sign in to comment.