github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/action/yml_internal_test.go (about)

     1  //go:build integration
     2  
     3  package action
     4  
     5  import (
     6  	"context"
     7  	"path/filepath"
     8  	"testing"
     9  
    10  	"github.com/helmwave/helmwave/pkg/plan"
    11  	"github.com/helmwave/helmwave/pkg/template"
    12  	"github.com/helmwave/helmwave/tests"
    13  	"github.com/stretchr/testify/suite"
    14  )
    15  
    16  type YmlTestSuite struct {
    17  	suite.Suite
    18  
    19  	ctx context.Context
    20  }
    21  
    22  //nolint:paralleltest // can't parallel because of setenv
    23  func TestYmlTestSuite(t *testing.T) {
    24  	// t.Parallel()
    25  	suite.Run(t, new(YmlTestSuite))
    26  }
    27  
    28  func (ts *YmlTestSuite) SetupTest() {
    29  	ts.ctx = tests.GetContext(ts.T())
    30  }
    31  
    32  func (ts *YmlTestSuite) TestCmd() {
    33  	s := &Yml{}
    34  	cmd := s.Cmd()
    35  
    36  	ts.Require().NotNil(cmd)
    37  	ts.Require().NotEmpty(cmd.Name)
    38  }
    39  
    40  func (ts *YmlTestSuite) TestRenderEnv() {
    41  	tmpDir := ts.T().TempDir()
    42  	y := &Yml{
    43  		tpl:       filepath.Join(tests.Root, "01_helmwave.yml.tpl"),
    44  		file:      filepath.Join(tmpDir, "01_helmwave.yml"),
    45  		templater: template.TemplaterSprig,
    46  	}
    47  
    48  	value := "test01"
    49  	ts.T().Setenv("NAMESPACE", value)
    50  	ts.T().Setenv("PROJECT_NAME", value)
    51  
    52  	ts.Require().NoError(y.Run(ts.ctx))
    53  
    54  	b, err := plan.NewBody(ts.ctx, y.file, true)
    55  	ts.Require().NoError(err)
    56  
    57  	ts.Require().Equal(value, b.Project)
    58  	ts.Require().Len(b.Releases, 1)
    59  	ts.Require().Equal(value, b.Releases[0].Namespace())
    60  }