github.com/evanlouie/fabrikate@v0.17.4/cmd/generate_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/evanlouie/fabrikate/core"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func checkComponentLengthsAgainstExpected(t *testing.T, components []core.Component, expectedLengths map[string]int) {
    11  	for _, component := range components {
    12  		if expectedLength, ok := expectedLengths[component.Name]; ok {
    13  			assert.True(t, ok)
    14  			assert.Equal(t, expectedLength, len(component.Manifest))
    15  		}
    16  	}
    17  }
    18  
    19  func TestGenerateJSON(t *testing.T) {
    20  	components, err := Generate("../testdata/generate", []string{"prod-east", "prod"}, false)
    21  
    22  	assert.Nil(t, err)
    23  
    24  	expectedLengths := map[string]int{
    25  		"elasticsearch":         14495,
    26  		"elasticsearch-curator": 2394,
    27  		"fluentd-elasticsearch": 20203,
    28  		"kibana":                1595,
    29  		"static":                188,
    30  	}
    31  
    32  	assert.Equal(t, 8, len(components))
    33  
    34  	checkComponentLengthsAgainstExpected(t, components, expectedLengths)
    35  }
    36  
    37  func TestGenerateYAML(t *testing.T) {
    38  	components, err := Generate("../testdata/generate-yaml", []string{"prod"}, false)
    39  
    40  	expectedLengths := map[string]int{
    41  		"prometheus-grafana": 125,
    42  		"grafana":            8575,
    43  		"prometheus":         21401,
    44  	}
    45  
    46  	assert.Nil(t, err)
    47  
    48  	assert.Equal(t, 3, len(components))
    49  
    50  	checkComponentLengthsAgainstExpected(t, components, expectedLengths)
    51  }
    52  
    53  func TestGenerateStaticRemoteYAML(t *testing.T) {
    54  	components, err := Generate("../testdata/generate-remote-static", []string{"common"}, false)
    55  
    56  	expectedLengths := map[string]int{
    57  		"keyvault-flexvolume": 5,
    58  		"keyvault-sub":        1372,
    59  	}
    60  
    61  	assert.Nil(t, err)
    62  	assert.Equal(t, 2, len(components))
    63  
    64  	checkComponentLengthsAgainstExpected(t, components, expectedLengths)
    65  }
    66  
    67  func TestGenerateWithHooks(t *testing.T) {
    68  	_, err := Generate("../testdata/generate-hooks", []string{"prod"}, false)
    69  
    70  	assert.Nil(t, err)
    71  }