github.com/openshift/installer@v1.4.17/pkg/asset/ignition/machine/master_test.go (about)

     1  package machine
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     9  	"k8s.io/utils/pointer"
    10  
    11  	"github.com/openshift/installer/pkg/asset"
    12  	"github.com/openshift/installer/pkg/asset/installconfig"
    13  	"github.com/openshift/installer/pkg/asset/tls"
    14  	"github.com/openshift/installer/pkg/ipnet"
    15  	"github.com/openshift/installer/pkg/types"
    16  	"github.com/openshift/installer/pkg/types/aws"
    17  )
    18  
    19  // TestMasterGenerate tests generating the master asset.
    20  func TestMasterGenerate(t *testing.T) {
    21  	installConfig := installconfig.MakeAsset(
    22  		&types.InstallConfig{
    23  			ObjectMeta: metav1.ObjectMeta{
    24  				Name: "test-cluster",
    25  			},
    26  			BaseDomain: "test-domain",
    27  			Networking: &types.Networking{
    28  				ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("10.0.1.0/24")},
    29  			},
    30  			Platform: types.Platform{
    31  				AWS: &aws.Platform{
    32  					Region: "us-east",
    33  				},
    34  			},
    35  			ControlPlane: &types.MachinePool{
    36  				Name:     "master",
    37  				Replicas: pointer.Int64Ptr(3),
    38  			},
    39  		})
    40  
    41  	rootCA := &tls.RootCA{}
    42  	err := rootCA.Generate(context.Background(), nil)
    43  	assert.NoError(t, err, "unexpected error generating root CA")
    44  
    45  	parents := asset.Parents{}
    46  	parents.Add(installConfig, rootCA)
    47  
    48  	master := &Master{}
    49  	err = master.Generate(context.Background(), parents)
    50  	assert.NoError(t, err, "unexpected error generating master asset")
    51  	expectedIgnitionConfigNames := []string{
    52  		"master.ign",
    53  	}
    54  	actualFiles := master.Files()
    55  	actualIgnitionConfigNames := make([]string, len(actualFiles))
    56  	for i, f := range actualFiles {
    57  		actualIgnitionConfigNames[i] = f.Filename
    58  	}
    59  	assert.Equal(t, expectedIgnitionConfigNames, actualIgnitionConfigNames, "unexpected names for master ignition configs")
    60  }