mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-16 12:08:04 +00:00
List check utils.
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StringsIsSubset checks that subset is strict subset of full, and returns
|
||||||
|
// error formatted with errorFmt otherwise
|
||||||
|
func StringsIsSubset(subset []string, full []string, errorFmt string) error {
|
||||||
|
for checked := range subset {
|
||||||
|
found := false
|
||||||
|
for s := range full {
|
||||||
|
if checked == s {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return fmt.Errorf(errorFmt, checked, full)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "launchpad.net/gocheck"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListSuite struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ListSuite) TestStringsIsSubset(c *C) {
|
||||||
|
err := StringsIsSubset([]string{"a", "b"}, []string{"a", "b", "c"}, "[%s]")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
err = StringsIsSubset([]string{"b", "a"}, []string{"b", "c"}, "[%s]")
|
||||||
|
c.Assert(err, ErrorMatches, "[a]")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user