Skip to content

Commit

Permalink
datacenter describe regex
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Sep 30, 2024
1 parent d85521e commit 40f03d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
36 changes: 23 additions & 13 deletions test/e2e/datacenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,29 @@ func TestDatacenter(t *testing.T) {
t.Run("normal", func(t *testing.T) {
out, err := runCommand(t, "datacenter", "describe", TestDatacenterID)
require.NoError(t, err)
assert.Regexp(t, `ID:\s+[0-9]+
Name:\s+[a-z0-9\-]+
Description:\s+[a-zA-Z0-9\- ]+
Location:
+Name:\s+[a-z0-9]+
+Description:\s+[a-zA-Z0-9\- ]+
+Country:\s+[A-Z]{2}
+City:\s+[A-Za-z]+
+Latitude:\s+[0-9\.]+
+Longitude:\s+[0-9\.]+
Server Types:
(\s+- ID: [0-9]+\s+Name: [a-z0-9]+\s+Supported: (true|false)\s+Available: (true|false))+
`, out)

assert.Regexp(t,
NewRegex().Start().
Lit("ID:").Whitespace().Int().Newline().
Lit("Name:").Whitespace().Identifier().Newline().
Lit("Description:").Whitespace().AnyString().Newline().
Lit("Location:").Newline().
Lit(" Name:").Whitespace().LocationName().Newline().
Lit(" Description:").Whitespace().AnyString().Newline().
Lit(" Country:").Whitespace().CountryCode().Newline().
Lit(" City:").Whitespace().AnyString().Newline().
Lit(" Latitude:").Whitespace().Float().Newline().
Lit(" Longitude:").Whitespace().Float().Newline().
Lit("Server Types:").Newline().
AnyTimes(
NewRegex().
Lit(" - ID: ").Int().Whitespace().
Lit("Name: ").Identifier().Whitespace().
Lit("Supported: ").OneOfLit("true", "false").Whitespace().
Lit("Available: ").OneOfLit("true", "false").Newline(),
).End(),
out,
)
})
})
}
8 changes: 8 additions & 0 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ func (r RegexBuilder) Int() RegexBuilder {
return r.Raw(`[0-9]+`)
}

func (r RegexBuilder) Float() RegexBuilder {
return r.Raw(`[0-9]*\.[0-9]*`)
}

func (r RegexBuilder) LocationName() RegexBuilder {
return r.Raw(`[a-z]{3}[0-9]*`)
}

func (r RegexBuilder) CountryCode() RegexBuilder {
return r.Raw(`[A-Z]{2}`)
}

0 comments on commit 40f03d5

Please sign in to comment.