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

     1  package image
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/openshift/installer/pkg/asset"
    10  	"github.com/openshift/installer/pkg/types"
    11  )
    12  
    13  func TestRegistriesConf_Generate(t *testing.T) {
    14  	cases := []struct {
    15  		name         string
    16  		dependencies []asset.Asset
    17  
    18  		expectedError string
    19  		expectedData  []byte
    20  	}{
    21  		{
    22  			name: "default",
    23  			dependencies: []asset.Asset{
    24  				&ImageBasedInstallationConfig{
    25  					Config: ibiConfig().
    26  						imageDigestSources([]types.ImageDigestSource{
    27  							{
    28  								Source:  "quay.io",
    29  								Mirrors: []string{"mirror-quay.io"},
    30  							},
    31  						}).
    32  						build(),
    33  				},
    34  			},
    35  
    36  			expectedData: []byte("credential-helpers = []\nshort-name-mode = \"\"\nunqualified-search-registries = []\n\n[[registry]]\n  location = \"quay.io\"\n  mirror-by-digest-only = true\n  prefix = \"\"\n\n  [[registry.mirror]]\n    location = \"mirror-quay.io\"\n"),
    37  		},
    38  	}
    39  
    40  	for _, tc := range cases {
    41  		t.Run(tc.name, func(t *testing.T) {
    42  			parents := asset.Parents{}
    43  			parents.Add(tc.dependencies...)
    44  
    45  			registriesConf := &RegistriesConf{}
    46  			err := registriesConf.Generate(context.Background(), parents)
    47  
    48  			if tc.expectedError != "" {
    49  				assert.Equal(t, tc.expectedError, err.Error())
    50  			} else {
    51  				assert.NoError(t, err)
    52  				assert.Equal(t, tc.expectedData, registriesConf.Data)
    53  			}
    54  		})
    55  	}
    56  }