github.com/rhatdan/docker@v0.7.7-0.20180119204836-47a0dcbcd20a/daemon/info_unix_test.go (about)

     1  // +build !windows
     2  
     3  package daemon
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/docker/docker/api/types"
     9  	"github.com/docker/docker/dockerversion"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestParseInitVersion(t *testing.T) {
    14  	tests := []struct {
    15  		version string
    16  		result  types.Commit
    17  		invalid bool
    18  	}{
    19  		{
    20  			version: "tini version 0.13.0 - git.949e6fa",
    21  			result:  types.Commit{ID: "949e6fa", Expected: dockerversion.InitCommitID[0:7]},
    22  		}, {
    23  			version: "tini version 0.13.0\n",
    24  			result:  types.Commit{ID: "v0.13.0", Expected: dockerversion.InitCommitID},
    25  		}, {
    26  			version: "tini version 0.13.2",
    27  			result:  types.Commit{ID: "v0.13.2", Expected: dockerversion.InitCommitID},
    28  		}, {
    29  			version: "tini version0.13.2",
    30  			result:  types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
    31  			invalid: true,
    32  		}, {
    33  			version: "",
    34  			result:  types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
    35  			invalid: true,
    36  		}, {
    37  			version: "hello world",
    38  			result:  types.Commit{ID: "N/A", Expected: dockerversion.InitCommitID},
    39  			invalid: true,
    40  		},
    41  	}
    42  
    43  	for _, test := range tests {
    44  		ver, err := parseInitVersion(string(test.version))
    45  		if test.invalid {
    46  			assert.Error(t, err)
    47  		} else {
    48  			assert.NoError(t, err)
    49  		}
    50  		assert.Equal(t, test.result, ver)
    51  	}
    52  }