github.com/containerd/nerdctl@v1.7.7/pkg/infoutil/infoutil_test.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package infoutil 18 19 import ( 20 "testing" 21 22 "github.com/containerd/nerdctl/pkg/inspecttypes/dockercompat" 23 "gotest.tools/v3/assert" 24 ) 25 26 func TestParseBuildctlVersion(t *testing.T) { 27 testCases := map[string]*dockercompat.ComponentVersion{ 28 "buildctl github.com/moby/buildkit v0.10.3 c8d25d9a103b70dc300a4fd55e7e576472284e31": { 29 Name: "buildctl", 30 Version: "v0.10.3", 31 Details: map[string]string{ 32 "GitCommit": "c8d25d9a103b70dc300a4fd55e7e576472284e31", 33 }, 34 }, 35 "buildctl github.com/moby/buildkit v0.10.0-380-g874eef9b 874eef9b70dbaf4f074d2bc8f4dc64237f8e83a0": { 36 Name: "buildctl", 37 Version: "v0.10.0-380-g874eef9b", 38 Details: map[string]string{ 39 "GitCommit": "874eef9b70dbaf4f074d2bc8f4dc64237f8e83a0", 40 }, 41 }, 42 "buildctl github.com/moby/buildkit 0.0.0+unknown": { 43 Name: "buildctl", 44 Version: "0.0.0+unknown", 45 }, 46 "foo bar baz": nil, 47 } 48 49 for s, expected := range testCases { 50 got, err := parseBuildctlVersion([]byte(s)) 51 if expected != nil { 52 assert.NilError(t, err) 53 assert.DeepEqual(t, expected, got) 54 } else { 55 assert.Assert(t, err != nil) 56 } 57 } 58 } 59 60 func TestParseRuncVersion(t *testing.T) { 61 testCases := map[string]*dockercompat.ComponentVersion{ 62 `runc version 1.1.2 63 commit: v1.1.2-0-ga916309f 64 spec: 1.0.2-dev 65 go: go1.18.3 66 libseccomp: 2.5.1`: { 67 Name: "runc", 68 Version: "1.1.2", 69 Details: map[string]string{ 70 "GitCommit": "v1.1.2-0-ga916309f", 71 }, 72 }, 73 } 74 75 for s, expected := range testCases { 76 got, err := parseRuncVersion([]byte(s)) 77 if expected != nil { 78 assert.NilError(t, err) 79 assert.DeepEqual(t, expected, got) 80 } else { 81 assert.Assert(t, err != nil) 82 } 83 } 84 }