gitlab.com/jfprevost/gitlab-runner-notlscheck@v11.11.4+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  		"all values": {
    27  			volume:         &Volume{Source: "source", Destination: "destination", Mode: "mode"},
    28  			expectedOutput: "source:destination:mode",
    29  		},
    30  	}
    31  
    32  	for testName, testCase := range testCases {
    33  		t.Run(testName, func(t *testing.T) {
    34  			output := testCase.volume.Definition()
    35  			assert.Equal(t, testCase.expectedOutput, output)
    36  		})
    37  	}
    38  }
    39  
    40  func TestVolume_Len(t *testing.T) {
    41  	testCases := map[string]struct {
    42  		volume      *Volume
    43  		expectedLen int
    44  	}{
    45  		"empty": {
    46  			volume:      &Volume{},
    47  			expectedLen: 0,
    48  		},
    49  		"only destination": {
    50  			volume:      &Volume{Destination: "destination"},
    51  			expectedLen: 1,
    52  		},
    53  		"source and destination": {
    54  			volume:      &Volume{Source: "source", Destination: "destination"},
    55  			expectedLen: 2,
    56  		},
    57  		"destination and mode": {
    58  			volume:      &Volume{Destination: "destination", Mode: "mode"},
    59  			expectedLen: 1,
    60  		},
    61  		"all values": {
    62  			volume:      &Volume{Source: "source", Destination: "destination", Mode: "mode"},
    63  			expectedLen: 2,
    64  		},
    65  	}
    66  
    67  	for testName, testCase := range testCases {
    68  		t.Run(testName, func(t *testing.T) {
    69  			len := testCase.volume.Len()
    70  			assert.Equal(t, testCase.expectedLen, len)
    71  		})
    72  	}
    73  }