Commit 28abf3f7
28abf3f71423Merged
Svyatoslav Dumchenko <[email protected]> ยท 5 years ago ยท 1 file ยท +1 added
Description
add deploy integration test
Details
- Commit
- 28abf3f71423
- Parent
- 193dc7ee0289
tests/integration/sync_test.goaddedView file
1+
// +build ignore integration2+
3+
package integration4+
5+
import (6+
"github.com/helmwave/helmwave/pkg/helmwave"7+
"github.com/helmwave/helmwave/pkg/helper"8+
"github.com/helmwave/helmwave/pkg/kubedog"9+
"github.com/helmwave/helmwave/pkg/template"10+
"github.com/helmwave/helmwave/pkg/yml"11+
"github.com/stretchr/testify/suite"12+
"helm.sh/helm/v3/pkg/action"13+
helm "helm.sh/helm/v3/pkg/cli"14+
helmRelease "helm.sh/helm/v3/pkg/release"15+
"os"16+
"testing"17+
)18+
19+
type SyncTestSuite struct {20+
suite.Suite21+
app *helmwave.Config22+
}23+
24+
func (s *SyncTestSuite) SetupTest() {25+
s.app = &helmwave.Config{26+
Helm: helm.New(),27+
Tpl: template.Tpl{28+
From: "../fixtures/helmwave.yml.tpl",29+
To: "helmwave.yml",30+
},31+
Yml: yml.Config{},32+
PlanPath: PlanPath,33+
Logger: &helmwave.Log{34+
Level: "DEBUG",35+
Format: "flat",36+
Color: false,37+
},38+
Parallel: false,39+
Kubedog: &kubedog.Config{},40+
}41+
42+
err := s.app.InitLogger()43+
s.Require().NoError(err)44+
45+
err = s.app.Tpl.Render()46+
s.Require().NoError(err)47+
48+
err = yml.Read(s.app.Tpl.To, &s.app.Yml)49+
s.Require().NoError(err)50+
}51+
52+
func (s *SyncTestSuite) TestSync() {53+
opts := &yml.SavePlanOptions{}54+
opts.File(s.app.PlanPath + PlanFile).Dir(s.app.PlanPath)55+
opts.PlanValues().PlanRepos().PlanValues()56+
opts.Tags(s.app.Tags.Value())57+
58+
err := s.app.Yml.Plan(opts, s.app.Helm)59+
s.Require().NoError(err)60+
61+
_ = os.Setenv("HELM_NAMESPACE", "test-nginx")62+
63+
err = s.app.Yml.Sync(s.app.PlanPath+PlanFile, s.app.Parallel, s.app.Helm)64+
s.Require().NoError(err)65+
66+
cfg, err := helper.ActionCfg("test-nginx", s.app.Helm)67+
s.Require().NoError(err)68+
s.Require().NotNil(cfg)69+
70+
list := action.NewList(cfg)71+
list.All = true72+
s.Require().NotNil(list)73+
74+
releases, err := list.Run()75+
s.Require().NoError(err)76+
s.Require().NotZero(len(releases))77+
78+
found := false79+
for _, release := range releases {80+
s.Require().NotNil(release)81+
if release.Name != "nginx" {82+
continue83+
}84+
85+
found = true86+
87+
s.Require().NotNil(release.Info)88+
s.Require().Equal(helmRelease.StatusDeployed, release.Info.Status)89+
}90+
91+
s.Require().True(found, "Release not found")92+
}93+
94+
func TestSyncTestSuite(t *testing.T) {95+
suite.Run(t, new(SyncTestSuite))96+
}