github.com/secure-build/gitlab-runner@v12.5.0+incompatible/helpers/docker/helperimage/info_test.go (about)

     1  package helperimage
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"gitlab.com/gitlab-org/gitlab-runner/helpers/docker/errors"
     9  )
    10  
    11  func TestGetInfo(t *testing.T) {
    12  	tests := []struct {
    13  		osType        string
    14  		expectedError error
    15  	}{
    16  		{osType: OSTypeLinux, expectedError: nil},
    17  		{osType: OSTypeWindows, expectedError: ErrUnsupportedOSVersion},
    18  		{osType: "unsupported", expectedError: errors.NewErrOSNotSupported("unsupported")},
    19  	}
    20  
    21  	for _, test := range tests {
    22  		t.Run(test.osType, func(t *testing.T) {
    23  			_, err := Get(headRevision, Config{OSType: test.osType})
    24  
    25  			assert.Equal(t, test.expectedError, err)
    26  		})
    27  	}
    28  }
    29  
    30  func TestContainerImage_String(t *testing.T) {
    31  	image := Info{
    32  		Name: "abc",
    33  		Tag:  "1234",
    34  	}
    35  
    36  	assert.Equal(t, "abc:1234", image.String())
    37  }
    38  
    39  func Test_imageRevision(t *testing.T) {
    40  	tests := []struct {
    41  		revision    string
    42  		expectedTag string
    43  	}{
    44  		{
    45  			revision:    headRevision,
    46  			expectedTag: latestImageRevision,
    47  		},
    48  		{
    49  			revision:    "1234",
    50  			expectedTag: "1234",
    51  		},
    52  	}
    53  
    54  	for _, test := range tests {
    55  		t.Run(test.revision, func(t *testing.T) {
    56  			assert.Equal(t, test.expectedTag, imageRevision(test.revision))
    57  		})
    58  	}
    59  
    60  }