github.com/secure-build/gitlab-runner@v12.5.0+incompatible/executors/docker/internal/volumes/parser/volume_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestVolume_Definition(t *testing.T) {
    10  	testCases := map[string]struct {
    11  		volume         *Volume
    12  		expectedOutput string
    13  	}{
    14  		"only destination": {
    15  			volume:         &Volume{Destination: "destination"},
    16  			expectedOutput: "destination",
    17  		},
    18  		"source and destination": {
    19  			volume:         &Volume{Source: "source", Destination: "destination"},
    20  			expectedOutput: "source:destination",
    21  		},
    22  		"destination and mode": {
    23  			volume:         &Volume{Destination: "destination", Mode: "mode"},
    24  			expectedOutput: "destination:mode",
    25  		},
    26  		"destination and bindPropagation": {
    27  			volume:         &Volume{Destination: "destination", BindPropagation: "bindPropagation"},
    28  			expectedOutput: "destination:bindPropagation",
    29  		},
    30  		"source, destination and mode": {
    31  			volume:         &Volume{Source: "source", Destination: "destination", Mode: "mode"},
    32  			expectedOutput: "source:destination:mode",
    33  		},
    34  		"source, destination and bindPropagation": {
    35  			volume:         &Volume{Source: "source", Destination: "destination", BindPropagation: "bindPropagation"},
    36  			expectedOutput: "source:destination:bindPropagation",
    37  		},
    38  		"all values": {
    39  			volume:         &Volume{Source: "source", Destination: "destination", Mode: "mode", BindPropagation: "bindPropagation"},
    40  			expectedOutput: "source:destination:mode,bindPropagation",
    41  		},
    42  	}
    43  
    44  	for testName, testCase := range testCases {
    45  		t.Run(testName, func(t *testing.T) {
    46  			output := testCase.volume.Definition()
    47  			assert.Equal(t, testCase.expectedOutput, output)
    48  		})
    49  	}
    50  }
    51  
    52  func TestVolume_Len(t *testing.T) {
    53  	testCases := map[string]struct {
    54  		volume      *Volume
    55  		expectedLen int
    56  	}{
    57  		"empty": {
    58  			volume:      &Volume{},
    59  			expectedLen: 0,
    60  		},
    61  		"only destination": {
    62  			volume:      &Volume{Destination: "destination"},
    63  			expectedLen: 1,
    64  		},
    65  		"source and destination": {
    66  			volume:      &Volume{Source: "source", Destination: "destination"},
    67  			expectedLen: 2,
    68  		},
    69  		"destination and mode": {
    70  			volume:      &Volume{Destination: "destination", Mode: "mode"},
    71  			expectedLen: 1,
    72  		},
    73  		"all values": {
    74  			volume:      &Volume{Source: "source", Destination: "destination", Mode: "mode"},
    75  			expectedLen: 2,
    76  		},
    77  	}
    78  
    79  	for testName, testCase := range testCases {
    80  		t.Run(testName, func(t *testing.T) {
    81  			len := testCase.volume.Len()
    82  			assert.Equal(t, testCase.expectedLen, len)
    83  		})
    84  	}
    85  }