github.com/reds/docker@v1.11.2-rc1/pkg/aaparser/aaparser_test.go (about) 1 package aaparser 2 3 import ( 4 "testing" 5 ) 6 7 type versionExpected struct { 8 output string 9 version int 10 } 11 12 func TestParseVersion(t *testing.T) { 13 versions := []versionExpected{ 14 { 15 output: `AppArmor parser version 2.10 16 Copyright (C) 1999-2008 Novell Inc. 17 Copyright 2009-2012 Canonical Ltd. 18 19 `, 20 version: 210000, 21 }, 22 { 23 output: `AppArmor parser version 2.8 24 Copyright (C) 1999-2008 Novell Inc. 25 Copyright 2009-2012 Canonical Ltd. 26 27 `, 28 version: 208000, 29 }, 30 { 31 output: `AppArmor parser version 2.20 32 Copyright (C) 1999-2008 Novell Inc. 33 Copyright 2009-2012 Canonical Ltd. 34 35 `, 36 version: 220000, 37 }, 38 { 39 output: `AppArmor parser version 2.05 40 Copyright (C) 1999-2008 Novell Inc. 41 Copyright 2009-2012 Canonical Ltd. 42 43 `, 44 version: 205000, 45 }, 46 { 47 output: `AppArmor parser version 2.9.95 48 Copyright (C) 1999-2008 Novell Inc. 49 Copyright 2009-2012 Canonical Ltd. 50 51 `, 52 version: 209095, 53 }, 54 { 55 output: `AppArmor parser version 3.14.159 56 Copyright (C) 1999-2008 Novell Inc. 57 Copyright 2009-2012 Canonical Ltd. 58 59 `, 60 version: 314159, 61 }, 62 } 63 64 for _, v := range versions { 65 version, err := parseVersion(v.output) 66 if err != nil { 67 t.Fatalf("expected error to be nil for %#v, got: %v", v, err) 68 } 69 if version != v.version { 70 t.Fatalf("expected version to be %d, was %d, for: %#v\n", v.version, version, v) 71 } 72 } 73 }