helm-library-common/charts/common/tests/addon_netshoot_test.go
Julien Cabillot b0085938f1 first import
2021-12-29 16:18:45 -05:00

65 lines
2.0 KiB
Go

package common
import (
"testing"
"github.com/Jeffail/gabs/v2"
"github.com/k8s-at-home/library-charts/test/helmunit"
"github.com/stretchr/testify/suite"
)
type AddonNetshootTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
baseValues []string
}
func (suite *AddonNetshootTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../../../helper-charts/common-test")
suite.Chart.UpdateDependencies()
suite.baseValues = []string{"addons.netshoot.enabled=true"}
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestAddonNetshoot(t *testing.T) {
suite.Run(t, new(AddonNetshootTestSuite))
}
func (suite *AddonNetshootTestSuite) TestContainer() {
tests := map[string]struct {
values []string
expectedNetshootContainer bool
}{
"Default": {values: nil, expectedNetshootContainer: false},
"AddonEnabled": {values: suite.baseValues, expectedNetshootContainer: true},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
var netshootContainer *gabs.Container
for _, container := range containers {
containerName := container.Path("name").Data().(string)
if containerName == "netshoot" {
netshootContainer = container
break
}
}
if tc.expectedNetshootContainer {
suite.Assertions.NotEmpty(netshootContainer)
} else {
suite.Assertions.Empty(netshootContainer)
}
})
}
}