Skip to content

Instantly share code, notes, and snippets.

@jewzaam
Last active March 1, 2019 13:53
Show Gist options
  • Save jewzaam/336d378939189dfcdb069403003015af to your computer and use it in GitHub Desktop.
Save jewzaam/336d378939189dfcdb069403003015af to your computer and use it in GitHub Desktop.
dedicated-admin namespace regex test
$ go run test.go
2019/03/01 08:51:34 PASS: test=openshift-nmalik, expected=true, matched=true
2019/03/01 08:51:34 FAIL: test=nmalik-openshift-test, expected=false, matched=true
2019/03/01 08:51:34 PASS: test=nmalik-test, expected=false, matched=false
package main
import (
"regexp"
"log"
)
func main() {
tests := [3]string{"openshift-nmalik", "nmalik-openshift-test", "nmalik-test"}
expect := [3]bool{true,false,false}
for i, test := range tests {
matched, _ := regexp.MatchString("openshift-.*", test)
if (matched && expect[i]) || (!matched && !expect[i]) {
log.Printf("PASS: test=%s, expected=%t, matched=%t", test, expect[i], matched)
} else {
log.Printf("FAIL: test=%s, expected=%t, matched=%t", test, expect[i], matched)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment