2016-01-12 21:01:04 +03:00
|
|
|
package aaparser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type versionExpected struct {
|
2016-02-14 10:04:16 +03:00
|
|
|
output string
|
|
|
|
version int
|
2016-01-12 21:01:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVersion(t *testing.T) {
|
|
|
|
versions := []versionExpected{
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.10
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
2016-02-14 10:04:16 +03:00
|
|
|
version: 210000,
|
2016-01-12 21:01:04 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.8
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
2016-02-14 10:04:16 +03:00
|
|
|
version: 208000,
|
2016-01-12 21:01:04 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.20
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
2016-02-14 10:04:16 +03:00
|
|
|
version: 220000,
|
2016-01-12 21:01:04 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.05
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
2016-02-14 10:04:16 +03:00
|
|
|
version: 205000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.9.95
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
|
|
|
version: 209095,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 3.14.159
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
|
|
|
version: 314159,
|
2016-01-12 21:01:04 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range versions {
|
2016-02-14 10:04:16 +03:00
|
|
|
version, err := parseVersion(v.output)
|
2016-01-12 21:01:04 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("expected error to be nil for %#v, got: %v", v, err)
|
|
|
|
}
|
2016-02-14 10:04:16 +03:00
|
|
|
if version != v.version {
|
|
|
|
t.Fatalf("expected version to be %d, was %d, for: %#v\n", v.version, version, v)
|
2016-01-12 21:01:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|