github.com/chenbh/concourse/v6@v6.4.2/worker/runtime/user_namespace_test.go (about)

     1  package runtime_test
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/chenbh/concourse/v6/worker/runtime"
     8  	"github.com/stretchr/testify/require"
     9  	"github.com/stretchr/testify/suite"
    10  )
    11  
    12  type UserNamespaceSuite struct {
    13  	suite.Suite
    14  	*require.Assertions
    15  }
    16  
    17  func (s *UserNamespaceSuite) TestMaxValid() {
    18  	for _, tc := range []struct {
    19  		desc      string
    20  		input     string
    21  		shouldErr bool
    22  		val       uint32
    23  	}{
    24  		{
    25  			desc:      "empty input",
    26  			shouldErr: true,
    27  		},
    28  		{
    29  			desc:      "invalid input",
    30  			input:     "0",
    31  			shouldErr: true,
    32  		},
    33  		{
    34  			desc:  "size of 1",
    35  			input: "0 1 1",
    36  			val:   0,
    37  		},
    38  		{
    39  			desc:  "size > 1",
    40  			input: "0 1 10",
    41  			val:   9,
    42  		},
    43  		{
    44  			desc:  "size > maxUint32",
    45  			input: "0 1 10",
    46  			val:   9,
    47  		},
    48  		{
    49  			desc:  "multiline size = 1",
    50  			input: "0 1 1\n1 2 1",
    51  			val:   1,
    52  		},
    53  		{
    54  			desc:  "multiline size = 1 first",
    55  			input: "1 2 1\n0 1 1",
    56  			val:   1,
    57  		},
    58  	} {
    59  		s.T().Run(tc.desc, func(t *testing.T) {
    60  			res, err := runtime.MaxValid(bytes.NewBufferString(tc.input))
    61  			if tc.shouldErr {
    62  				s.Error(err)
    63  				return
    64  			}
    65  
    66  			s.NoError(err)
    67  			s.Equal(int(tc.val), int(res))
    68  		})
    69  	}
    70  }