ERBS41132YUGCITY1KKT Check and Correct TestEran_Port function used for port() testing…
- User
ERBS_41132_YUGCITY_1_KKT Check and Correct TestEran_Port function used for port() testing
func - Assistant
The TestEran_Port function appears to be testing the port() method of the EranConnection struct. Here are the corrections and improvements that can be made:
-
In the EranConnection struct, the "Nodes" field should be of type "map[string]map[string]map[string]map[string]string" instead of "Nodes". So change
Nodestomap[string]map[string]map[string]map[string]string.
-
- User
Do not change port() method
- Assistant
Understood. In that case, here are the corrections and improvements for the TestEran_Port function:
- Import the "testing" package at the beginning of the file:
goimport ( "testing" "fmt" "strings" )- The struct
TN_PORTis not defined in the given code, so I assume it is a constant with the predefined TN port values. Add the definition ofTN_PORTabove the TestEran_Port function:
gotype TN_PORT string const ( TN_IDL_C TN_PORT = "TN_IDL_C" TN_IDL_D TN_PORT = "TN_IDL_D" TN_A TN_PORT = "TN_A" TN_B TN_PORT = "TN_B" )- In the test cases, the expected values for and are empty strings when not explicitly specified. Update the struct fields in the test cases to be instead of to allow for empty values:
- User
See Count() method package model
import ( validation "github.com/go-ozzo/ozzo-validation/v4" )
// Node is custom type that represents *model.ENodeB and *model.EUtranCellData // of cosite Node for Elastic Ran type Node struct { ENodeB
json:"ENodeB"EUtranCellDatajson:"EUtranCellData"}// Nodes is custom type that represents map of *model.Node type Nodes map[string]*Node
// ValidateEach validates each node in Nodes func (nodes Nodes) ValidateEach() error { return validation.Validate( nodes, validation.Required.Error("Cosite nodes cannot be blank"), ) }
// CleanEmpty deletes Cosite node if lte cell datya is empty func (nodes *Nodes) CleanEmpty() { for name, node := range *nodes { if len(node.EUtranCellData.CellsGroups) == 0 { delete(*nodes, name) } } }
// Count counts number of Cosite nodes func (nodes *Nodes) Count() int { count := 0 for _, node := range *nodes { if len(node.EUtranCellData.CellsGroups) > 0 { count++ } } return count }
// Count counts number of Cosite nodes func (nodes *Nodes) Names() []string { names := make([]string, len(*nodes)) i := 0 for node := range *nodes { names[i] = node i++ } return names }
- Assistant
Thank you for providing the code for the Count and Names methods. Here's how you can incorporate these methods into the TestEran_Port function without changing the port() method:
- Add the import statement for the "model" package at the beginning of the file:
goimport ( "testing" "fmt" "strings" "github.com/path/to/model" // Replace with the actual import path )- Use the
nodes.Count()method andnodes.Names()method in the TestEran_Port function:
go