2018-02-05 16:05:59 -05:00
|
|
|
package aaparser // import "github.com/docker/docker/pkg/aaparser"
|
2016-01-12 13:01:04 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type versionExpected struct {
|
2016-02-14 02:04:16 -05:00
|
|
|
output string
|
|
|
|
version int
|
2016-01-12 13:01:04 -05: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 02:04:16 -05:00
|
|
|
version: 210000,
|
2016-01-12 13:01:04 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.8
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
2016-02-14 02:04:16 -05:00
|
|
|
version: 208000,
|
2016-01-12 13:01:04 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.20
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
2016-02-14 02:04:16 -05:00
|
|
|
version: 220000,
|
2016-01-12 13:01:04 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.05
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
2016-02-14 02:04:16 -05:00
|
|
|
version: 205000,
|
|
|
|
},
|
2020-10-08 18:39:52 -04:00
|
|
|
{
|
|
|
|
output: `AppArmor parser version 2.2.0~rc2
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2012 Canonical Ltd.
|
|
|
|
|
|
|
|
`,
|
|
|
|
version: 202000,
|
|
|
|
},
|
2016-02-14 02:04:16 -05:00
|
|
|
{
|
|
|
|
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 13:01:04 -05:00
|
|
|
},
|
2020-10-02 04:33:52 -04:00
|
|
|
{
|
|
|
|
output: `AppArmor parser version 3.0.0-beta1
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2018 Canonical Ltd.
|
|
|
|
`,
|
|
|
|
version: 300000,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
output: `AppArmor parser version 3.0.0-beta1-foo-bar
|
|
|
|
Copyright (C) 1999-2008 Novell Inc.
|
|
|
|
Copyright 2009-2018 Canonical Ltd.
|
|
|
|
`,
|
|
|
|
version: 300000,
|
|
|
|
},
|
2016-01-12 13:01:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range versions {
|
2016-02-14 02:04:16 -05:00
|
|
|
version, err := parseVersion(v.output)
|
2016-01-12 13:01:04 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("expected error to be nil for %#v, got: %v", v, err)
|
|
|
|
}
|
2016-02-14 02:04:16 -05:00
|
|
|
if version != v.version {
|
|
|
|
t.Fatalf("expected version to be %d, was %d, for: %#v\n", v.version, version, v)
|
2016-01-12 13:01:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|