github.com/openshift/installer@v1.4.17/pkg/asset/agent/image/oc_test.go (about)

     1  package image
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/openshift/installer/pkg/asset/agent/mirror"
     9  )
    10  
    11  func TestGetIcspContents(t *testing.T) {
    12  
    13  	cases := []struct {
    14  		name           string
    15  		mirrorConfig   []mirror.RegistriesConfig
    16  		expectedError  string
    17  		expectedConfig string
    18  	}{
    19  		{
    20  			name: "valid-config",
    21  			mirrorConfig: []mirror.RegistriesConfig{
    22  				{
    23  					Location: "registry.ci.openshift.org/ocp/release",
    24  					Mirror:   "virthost.ostest.test.metalkube.org:5000/localimages/local-release-image",
    25  				},
    26  				{
    27  					Location: "quay.io/openshift-release-dev/ocp-v4.0-art-dev",
    28  					Mirror:   "virthost.ostest.test.metalkube.org:5000/localimages/local-release-image",
    29  				},
    30  			},
    31  			expectedConfig: "apiVersion: operator.openshift.io/v1alpha1\nkind: ImageContentSourcePolicy\nmetadata:\n  creationTimestamp: null\n  name: image-policy\nspec:\n  repositoryDigestMirrors:\n  - mirrors:\n    - virthost.ostest.test.metalkube.org:5000/localimages/local-release-image\n    source: registry.ci.openshift.org/ocp/release\n  - mirrors:\n    - virthost.ostest.test.metalkube.org:5000/localimages/local-release-image\n    source: quay.io/openshift-release-dev/ocp-v4.0-art-dev\n",
    32  			expectedError:  "",
    33  		},
    34  		{
    35  			name:           "empty-config",
    36  			mirrorConfig:   []mirror.RegistriesConfig{},
    37  			expectedConfig: "apiVersion: operator.openshift.io/v1alpha1\nkind: ImageContentSourcePolicy\nmetadata:\n  creationTimestamp: null\n  name: image-policy\nspec:\n  repositoryDigestMirrors: []\n",
    38  			expectedError:  "",
    39  		},
    40  	}
    41  	for _, tc := range cases {
    42  		t.Run(tc.name, func(t *testing.T) {
    43  			contents, err := getIcspContents(tc.mirrorConfig)
    44  			if tc.expectedError != "" {
    45  				assert.Equal(t, tc.expectedError, err.Error())
    46  			} else {
    47  				assert.NoError(t, err)
    48  			}
    49  
    50  			assert.Equal(t, tc.expectedConfig, string(contents))
    51  		})
    52  	}
    53  }