github.com/rumpl/bof@v23.0.0-rc.2+incompatible/daemon/info_unix_test.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package daemon // import "github.com/docker/docker/daemon"
     5  
     6  import (
     7  	"testing"
     8  
     9  	"gotest.tools/v3/assert"
    10  	is "gotest.tools/v3/assert/cmp"
    11  )
    12  
    13  func TestParseInitVersion(t *testing.T) {
    14  	tests := []struct {
    15  		output  string
    16  		version string
    17  		commit  string
    18  		invalid bool
    19  	}{
    20  		{
    21  			output:  "tini version 0.13.0 - git.949e6fa",
    22  			version: "0.13.0",
    23  			commit:  "949e6fa",
    24  		}, {
    25  			output:  "tini version 0.13.0\n",
    26  			version: "0.13.0",
    27  		}, {
    28  			output:  "tini version 0.13.2",
    29  			version: "0.13.2",
    30  		}, {
    31  			output:  "tini version 0.13.2 - ",
    32  			version: "0.13.2",
    33  		}, {
    34  			output: " - git.949e6fa",
    35  			commit: "949e6fa",
    36  		}, {
    37  			output:  "tini version0.13.2",
    38  			invalid: true,
    39  		}, {
    40  			output:  "version 0.13.0",
    41  			invalid: true,
    42  		}, {
    43  			output:  "",
    44  			invalid: true,
    45  		}, {
    46  			output:  " - ",
    47  			invalid: true,
    48  		}, {
    49  			output:  "hello world",
    50  			invalid: true,
    51  		},
    52  	}
    53  
    54  	for _, test := range tests {
    55  		test := test
    56  		t.Run(test.output, func(t *testing.T) {
    57  			version, commit, err := parseInitVersion(test.output)
    58  			if test.invalid {
    59  				assert.Check(t, is.ErrorContains(err, ""))
    60  			} else {
    61  				assert.Check(t, err)
    62  			}
    63  			assert.Equal(t, test.version, version)
    64  			assert.Equal(t, test.commit, commit)
    65  		})
    66  	}
    67  }
    68  
    69  func TestParseRuntimeVersion(t *testing.T) {
    70  	tests := []struct {
    71  		output  string
    72  		runtime string
    73  		version string
    74  		commit  string
    75  		invalid bool
    76  	}{
    77  		{
    78  			output: `
    79  runc version 1.0.0-rc5+dev
    80  commit: 69663f0bd4b60df09991c08812a60108003fa340
    81  spec: 1.0.0
    82  `,
    83  			runtime: "runc",
    84  			version: "1.0.0-rc5+dev",
    85  			commit:  "69663f0bd4b60df09991c08812a60108003fa340",
    86  		},
    87  		{
    88  			output: `
    89  runc version 1.0.0-rc5+dev
    90  spec: 1.0.0
    91  `,
    92  			runtime: "runc",
    93  			version: "1.0.0-rc5+dev",
    94  		},
    95  		{
    96  			output: `
    97  commit: 69663f0bd4b60df09991c08812a60108003fa340
    98  spec: 1.0.0
    99  `,
   100  			commit: "69663f0bd4b60df09991c08812a60108003fa340",
   101  		},
   102  		{
   103  			output: `
   104  crun version 0.7
   105  spec: 1.0.0
   106  +SYSTEMD +SELINUX +CAP +SECCOMP +EBPF +YAJL
   107  `,
   108  			runtime: "crun",
   109  			version: "0.7",
   110  		},
   111  		{
   112  			output:  "",
   113  			invalid: true,
   114  		},
   115  		{
   116  			output:  "hello world",
   117  			invalid: true,
   118  		},
   119  	}
   120  
   121  	for _, test := range tests {
   122  		runtime, version, commit, err := parseRuntimeVersion(test.output)
   123  		if test.invalid {
   124  			assert.Check(t, is.ErrorContains(err, ""))
   125  		} else {
   126  			assert.Check(t, err)
   127  		}
   128  		assert.Equal(t, test.runtime, runtime)
   129  		assert.Equal(t, test.version, version)
   130  		assert.Equal(t, test.commit, commit)
   131  	}
   132  }