Skip to content

Commit

Permalink
Added ComMatrix method; Changed private func to public
Browse files Browse the repository at this point in the history
  • Loading branch information
shirmoran committed Jul 16, 2024
1 parent 85e14c5 commit 7f5e0f7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions commatrix/commatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func New(kubeconfigPath string, customEntriesPath string, customEntriesFormat st
if err != nil {
return nil, fmt.Errorf("failed adding custom entries: %s", err)
}
customComDetails, err := addFromFile(customEntriesPath, inputFormat)
customComDetails, err := AddFromFile(customEntriesPath, inputFormat)
if err != nil {
return nil, fmt.Errorf("failed adding custom entries: %s", err)
}
Expand All @@ -81,7 +81,7 @@ func New(kubeconfigPath string, customEntriesPath string, customEntriesFormat st
return &types.ComMatrix{Matrix: cleanedComDetails}, nil
}

func addFromFile(fp string, format types.Format) ([]types.ComDetails, error) {
func AddFromFile(fp string, format types.Format) ([]types.ComDetails, error) {
var res []types.ComDetails
f, err := os.Open(filepath.Clean(fp))
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,36 @@ func (m ComMatrix) Contains(cd ComDetails) bool {

return false
}

// Returns True if both ComMatrixes have exactly the same ComMatrix details

Check failure on line 164 in types/types.go

View workflow job for this annotation

GitHub Actions / unit-test

Comment should end in a period (godot)
func (m ComMatrix) Equals(other ComMatrix) bool {
// Check if all of "m" commatrix details are in "other" commartix
for _, cd1 := range m.Matrix {
found := false
for _, cd2 := range other.Matrix {
if cd1.Equals(cd2) {
found = true
break
}
}
if !found {
return false
}
}

// Check if all of "other" commatrix details are in "m" commartix
for _, cd2 := range other.Matrix {
found := false
for _, cd1 := range m.Matrix {
if cd2.Equals(cd1) {
found = true
break
}
}
if !found {
return false
}
}

return true
}

0 comments on commit 7f5e0f7

Please sign in to comment.