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

fix(services/scaffolder): add no-message parameter for checkComponentCreated method #1459

Merged
merged 5 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions integration/cmd_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func TestCreateMapWithStargate(t *testing.T) {
)),
))

env.Must(env.Exec("create a message and a map with no-message flag to check conflicts",
step.NewSteps(step.New(
step.Exec("starport", "s", "message", "create-scavenge", "description"),
step.Exec("starport", "s", "map", "scavenge", "description", "--no-message"),
step.Workdir(path),
)),
))

env.Must(env.Exec("should prevent creating a map with duplicated indexes",
step.NewSteps(step.New(
step.Exec("starport", "s", "map", "map_with_duplicated_index", "email", "--index", "foo,foo"),
Expand Down
19 changes: 11 additions & 8 deletions starport/services/scaffolder/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func isMsgServerDefined(appPath, moduleName string) (bool, error) {
}

// checkComponentValidity performs various checks common to all components to verify if it can be scaffolded
func checkComponentValidity(appPath, moduleName string, compName multiformatname.Name) error {
func checkComponentValidity(appPath, moduleName string, compName multiformatname.Name, noMessage bool) error {
ok, err := moduleExists(appPath, moduleName)
if err != nil {
return err
Expand All @@ -71,7 +71,7 @@ func checkComponentValidity(appPath, moduleName string, compName multiformatname
}

// Check component name is not already used
return checkComponentCreated(appPath, moduleName, compName)
return checkComponentCreated(appPath, moduleName, compName, noMessage)
}

// checkForbiddenComponentName returns true if the name is forbidden as a component name
Expand Down Expand Up @@ -144,25 +144,28 @@ func checkGoReservedWord(name string) error {
}

// checkComponentCreated checks if the component has been already created with Starport in the project
func checkComponentCreated(appPath, moduleName string, compName multiformatname.Name) (err error) {
func checkComponentCreated(appPath, moduleName string, compName multiformatname.Name, noMessage bool) (err error) {

// associate the type to check with the component that scaffold this type
typesToCheck := map[string]string{
compName.UpperCamel: componentType,
"MsgCreate" + compName.UpperCamel: componentType,
"MsgUpdate" + compName.UpperCamel: componentType,
"MsgDelete" + compName.UpperCamel: componentType,
"QueryAll" + compName.UpperCamel + "Request": componentType,
"QueryAll" + compName.UpperCamel + "Response": componentType,
"QueryGet" + compName.UpperCamel + "Request": componentType,
"QueryGet" + compName.UpperCamel + "Response": componentType,
"Msg" + compName.UpperCamel: componentMessage,
"Query" + compName.UpperCamel + "Request": componentQuery,
"Query" + compName.UpperCamel + "Response": componentQuery,
"MsgSend" + compName.UpperCamel: componentPacket,
compName.UpperCamel + "PacketData": componentPacket,
}

if !noMessage {
typesToCheck["MsgCreate"+compName.UpperCamel] = componentType
typesToCheck["MsgUpdate"+compName.UpperCamel] = componentType
typesToCheck["MsgDelete"+compName.UpperCamel] = componentType
typesToCheck["Msg"+compName.UpperCamel] = componentMessage
typesToCheck["MsgSend"+compName.UpperCamel] = componentPacket
}

absPath, err := filepath.Abs(filepath.Join(appPath, "x", moduleName, "types"))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion starport/services/scaffolder/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *Scaffolder) AddMessage(
return sm, err
}

if err := checkComponentValidity(s.path, moduleName, name); err != nil {
if err := checkComponentValidity(s.path, moduleName, name, false); err != nil {
return sm, err
}

Expand Down
2 changes: 1 addition & 1 deletion starport/services/scaffolder/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *Scaffolder) AddOracle(
return sm, err
}

if err := checkComponentValidity(s.path, moduleName, name); err != nil {
if err := checkComponentValidity(s.path, moduleName, name, false); err != nil {
return sm, err
}

Expand Down
2 changes: 1 addition & 1 deletion starport/services/scaffolder/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *Scaffolder) AddPacket(
return sm, err
}

if err := checkComponentValidity(s.path, moduleName, name); err != nil {
if err := checkComponentValidity(s.path, moduleName, name, noMessage); err != nil {
return sm, err
}

Expand Down
2 changes: 1 addition & 1 deletion starport/services/scaffolder/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Scaffolder) AddQuery(
return sm, err
}

if err := checkComponentValidity(s.path, moduleName, name); err != nil {
if err := checkComponentValidity(s.path, moduleName, name, true); err != nil {
return sm, err
}

Expand Down
2 changes: 1 addition & 1 deletion starport/services/scaffolder/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (s *Scaffolder) AddType(
return sm, err
}

if err := checkComponentValidity(s.path, moduleName, name); err != nil {
if err := checkComponentValidity(s.path, moduleName, name, o.withoutMessage); err != nil {
return sm, err
}

Expand Down