Skip to content

Commit

Permalink
Order test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Mar 31, 2020
1 parent df27f36 commit 8599859
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions metricbeat/module/jolokia/jmx/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,32 @@ func TestBuildJolokiaGETUri(t *testing.T) {

func TestParseMBean(t *testing.T) {

cases := []struct {
cases := map[string]struct {
mbean string
expected *MBeanName
ok bool
}{
{
"empty": {
mbean: ``,
ok: false,
},
{
"no domain": {
mbean: `type=Runtime`,
ok: false,
},
{
"no properties": {
mbean: `java.lang`,
ok: false,
},
{
"no properties, with colon": {
mbean: `java.lang:`,
ok: false,
},
{
"property without value": {
mbean: `java.lang:type=Runtime,name`,
ok: false,
},
{
"single property": {
mbean: `java.lang:type=Runtime`,
expected: &MBeanName{
Domain: `java.lang`,
Expand All @@ -110,18 +110,17 @@ func TestParseMBean(t *testing.T) {
},
ok: true,
},
{
mbean: `java.lang:name=Foo,type=Runtime`,
"other single property": {
mbean: `java.lang:type=Memory`,
expected: &MBeanName{
Domain: `java.lang`,
Properties: map[string]string{
"name": "Foo",
"type": "Runtime",
"type": "Memory",
},
},
ok: true,
},
{
"multiple properties": {
mbean: `java.lang:name=Foo,type=Runtime`,
expected: &MBeanName{
Domain: `java.lang`,
Expand All @@ -132,7 +131,7 @@ func TestParseMBean(t *testing.T) {
},
ok: true,
},
{
"property with wildcard": {
mbean: `java.lang:type=Runtime,name=Foo*`,
expected: &MBeanName{
Domain: `java.lang`,
Expand All @@ -143,7 +142,7 @@ func TestParseMBean(t *testing.T) {
},
ok: true,
},
{
"property with wildcard as value": {
mbean: `java.lang:type=Runtime,name=*`,
expected: &MBeanName{
Domain: `java.lang`,
Expand All @@ -154,7 +153,7 @@ func TestParseMBean(t *testing.T) {
},
ok: true,
},
{
"quoted property": {
mbean: `java.lang:name="foo,bar",type=Runtime`,
expected: &MBeanName{
Domain: `java.lang`,
Expand All @@ -165,28 +164,30 @@ func TestParseMBean(t *testing.T) {
},
ok: true,
},
{
mbean: `java.lang:name="foo,\"bar\"",type=Runtime`,
"multiple quoted properties": {
mbean: `java.lang:name="foo",othername="bar",type=Runtime`,
expected: &MBeanName{
Domain: `java.lang`,
Properties: map[string]string{
"name": `"foo,\"bar\""`,
"type": "Runtime",
"name": `"foo"`,
"othername": `"bar"`,
"type": "Runtime",
},
},
ok: true,
},
{
mbean: `java.lang:type=Memory`,
"escaped quote in quoted property": {
mbean: `java.lang:name="foo,\"bar\"",type=Runtime`,
expected: &MBeanName{
Domain: `java.lang`,
Properties: map[string]string{
"type": "Memory",
"name": `"foo,\"bar\""`,
"type": "Runtime",
},
},
ok: true,
},
{
"real catalina mbean": {
mbean: `Catalina:name=HttpRequest1,type=RequestProcessor,worker="http-nio-8080"`,
expected: &MBeanName{
Domain: `Catalina`,
Expand All @@ -198,7 +199,7 @@ func TestParseMBean(t *testing.T) {
},
ok: true,
},
{
"real activemq artemis mbean": {
mbean: `org.apache.activemq.artemis:broker="0.0.0.0",component=addresses,address="helloworld",subcomponent=queues,routing-type="anycast",queue="helloworld"`,
expected: &MBeanName{
Domain: `org.apache.activemq.artemis`,
Expand All @@ -215,17 +216,19 @@ func TestParseMBean(t *testing.T) {
},
}

for _, c := range cases {
beanObj, err := ParseMBeanName(c.mbean)

if c.ok {
if assert.NoError(t, err, "failed parsing for: "+c.mbean) {
t.Log("Canonicalized mbean: ", beanObj.Canonicalize(true))
for title, c := range cases {
t.Run(title, func(t *testing.T) {
beanObj, err := ParseMBeanName(c.mbean)

if c.ok {
if assert.NoError(t, err, "failed parsing for: "+c.mbean) {
t.Log("Canonicalized mbean: ", beanObj.Canonicalize(true))
}
assert.Equal(t, c.expected, beanObj, "mbean: "+c.mbean)
} else {
assert.Error(t, err, "should have failed for: "+c.mbean)
}
assert.Equal(t, c.expected, beanObj, "mbean: "+c.mbean)
} else {
assert.Error(t, err, "should have failed for: "+c.mbean)
}
})
}

}
Expand Down

0 comments on commit 8599859

Please sign in to comment.