<commit_before>package installconfig

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/assert"

	"github.com/openshift/installer/pkg/asset"
)

type testAsset struct {
	name string
}

func (a *testAsset) Dependencies() []asset.Asset {
	return []asset.Asset{}
}

func (a *testAsset) Generate(map[asset.Asset]*asset.State) (*asset.State, error) {
	return nil, nil
}

func TestInstallConfigDependencies(t *testing.T) {
	stock := &StockImpl{
		clusterID:    &testAsset{name: "test-cluster-id"},
		emailAddress: &testAsset{name: "test-email"},
		password:     &testAsset{name: "test-password"},
		baseDomain:   &testAsset{name: "test-domain"},
		clusterName:  &testAsset{name: "test-cluster"},
		license:      &testAsset{name: "test-license"},
		pullSecret:   &testAsset{name: "test-pull-secret"},
		platform:     &testAsset{name: "test-platform"},
	}
	installConfig := &installConfig{
		assetStock: stock,
	}
	exp := []string{
		"test-cluster-id",
		"test-email",
		"test-password",
		"test-domain",
		"test-cluster",
		"test-license",
		"test-pull-secret",
		"test-platform",
	}
	deps := installConfig.Dependencies()
	act := make([]string, len(deps))
	for i, d := range deps {
		a, ok := d.(*testAsset)
		assert.True(t, ok, "expected dependency to be a *testAsset")
		act[i] = a.name
	}
	assert.Equal(t, exp, act, "unexpected dependency")
}

func TestInstallConfigGenerate(t *testing.T) {
	cases := []struct {
		name                 string
		platformContents     []string
		expectedPlatformYaml string
	}{
		{
			name: "aws",
			platformContents: []string{
				"aws",
				"test-region",
				"test-keypairname",
			},
			expectedPlatformYaml: `  aws:
    keyPairName: test-keypairname
    region: test-region
    vpcCIDRBlock: ""
    vpcID: ""`,
		},
		{
			name: "libvirt",
			platformContents: []string{
				"libvirt",
				"test-uri",
				"test-sshkey",
			},
			expectedPlatformYaml: `  libvirt:
    URI: test-uri
    masterIPs: null
    network:
      if: ""
      ipRange: ""
      name: ""
      resolver: ""
    sshKey: test-sshkey`,
		},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			stock := &StockImpl{
				clusterID:    &testAsset{},
				emailAddress: &testAsset{},
				password:     &test<PASSWORD>{},
				baseDomain:   &testAsset{},
				clusterName:  &testAsset{},
				license:      &testAsset{},
				pullSecret:   &testAsset{},
				platform:     &testAsset{},
			}

			dir, err := ioutil.TempDir("", "TestInstallConfigGenerate")
			if err != nil {
				t.Skip("could not create temporary directory: %v", err)
			}
			defer os.RemoveAll(dir)

			installConfig := &installConfig{
				assetStock: stock,
				directory:  dir,
			}

			states := map[asset.Asset]*asset.State{
				stock.clusterID: &asset.State{
					Contents: []asset.Content{{Data: []byte("test-cluster-id")}},
				},
				stock.emailAddress: &asset.State{
					Contents: []asset.Content{{Data: []byte("test-email")}},
				},<commit_msg>Change call of t.Skip to t.Skipf in installconfig_test.go<commit_after>package installconfig

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/assert"

	"github.com/openshift/installer/pkg/asset"
)

type testAsset struct {
	name string
}

func (a *testAsset) Dependencies() []asset.Asset {
	return []asset.Asset{}
}

func (a *testAsset) Generate(map[asset.Asset]*asset.State) (*asset.State, error) {
	return nil, nil
}

func TestInstallConfigDependencies(t *testing.T) {
	stock := &StockImpl{
		clusterID:    &testAsset{name: "test-cluster-id"},
		emailAddress: &testAsset{name: "test-email"},
		password:     &testAsset{name: "<PASSWORD>"},
		baseDomain:   &testAsset{name: "test-domain"},
		clusterName:  &testAsset{name: "test-cluster"},
		license:      &testAsset{name: "test-license"},
		pullSecret:   &testAsset{name: "test-pull-secret"},
		platform:     &testAsset{name: "test-platform"},
	}
	installConfig := &installConfig{
		assetStock: stock,
	}
	exp := []string{
		"test-cluster-id",
		"test-email",
		"test-password",
		"test-domain",
		"test-cluster",
		"test-license",
		"test-pull-secret",
		"test-platform",
	}
	deps := installConfig.Dependencies()
	act := make([]string, len(deps))
	for i, d := range deps {
		a, ok := d.(*testAsset)
		assert.True(t, ok, "expected dependency to be a *testAsset")
		act[i] = a.name
	}
	assert.Equal(t, exp, act, "unexpected dependency")
}

func TestInstallConfigGenerate(t *testing.T) {
	cases := []struct {
		name                 string
		platformContents     []string
		expectedPlatformYaml string
	}{
		{
			name: "aws",
			platformContents: []string{
				"aws",
				"test-region",
				"test-keypairname",
			},
			expectedPlatformYaml: `  aws:
    keyPairName: test-keypairname
    region: test-region
    vpcCIDRBlock: ""
    vpcID: ""`,
		},
		{
			name: "libvirt",
			platformContents: []string{
				"libvirt",
				"test-uri",
				"test-sshkey",
			},
			expectedPlatformYaml: `  libvirt:
    URI: test-uri
    masterIPs: null
    network:
      if: ""
      ipRange: ""
      name: ""
      resolver: ""
    sshKey: test-sshkey`,
		},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			stock := &StockImpl{
				clusterID:    &testAsset{},
				emailAddress: &testAsset{},
				password:     &testAsset{},
				baseDomain:   &testAsset{},
				clusterName:  &testAsset{},
				license:      &testAsset{},
				pullSecret:   &testAsset{},
				platform:     &testAsset{},
			}

			dir, err := ioutil.TempDir("", "TestInstallConfigGenerate")
			if err != nil {
				t.Skipf("could not create temporary directory: %v", err)
			}
			defer os.RemoveAll(dir)

			installConfig := &installConfig{
				assetStock: stock,
				directory:  dir,
			}

			states := map[asset.Asset]*asset.State{
				stock.clusterID: &asset.State{
					Contents: []asset.Content{{Data: []byte("test-cluster-id")}},
				},
				stock.emailAddress: &asset.State{
					Contents: []asset.Content{{Data: []byte("test-email")}},
				},
{'fraction_non_alphanumeric': 0.1659155399766316, 'fraction_numerical': 0.0, 'mean_word_length': 3.31700288184438, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3391632', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2097, 'n_words': 421}