Skip to content

Commit

Permalink
fix: some uts
Browse files Browse the repository at this point in the history
1. delete duplicate app config generator tests
2. fix util_test.go
3. comment module related e2e tests
  • Loading branch information
SparkYuan committed Mar 13, 2024
1 parent b564ea5 commit 4cfbb09
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 64 deletions.
14 changes: 14 additions & 0 deletions pkg/cmd/build/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ func TestBuildIntent(t *testing.T) {
mockers: []*mockey.MockBuilder{
mockey.Mock(kcl.Run).Return(&kcl.CompileResult{Documents: []kclgo.KCLResult{apcMap}}, nil),
mockey.Mock(workspace.GetWorkspaceByDefaultOperator).Return(ws, nil),
mockey.Mock((*builders.AppsConfigBuilder).Build).To(func(
o *builders.Options, project *v1.Project,
stack *v1.Stack,
) (*v1.Intent,
error,
) {
return intentModel3, nil
}),
},
},
want: intentModel3,
Expand Down Expand Up @@ -252,6 +260,12 @@ func TestBuildIntent(t *testing.T) {
mockers: []*mockey.MockBuilder{
mockey.Mock(kcl.Run).Return(&kcl.CompileResult{Documents: []kclgo.KCLResult{apcMap}}, nil),
mockey.Mock(workspace.GetWorkspaceByDefaultOperator).Return(ws, nil),
mockey.Mock((*builders.AppsConfigBuilder).Build).To(func(
o *builders.Options, project *v1.Project,
stack *v1.Stack,
) (*v1.Intent, error) {
return intentModel3, nil
}),
},
},
want: intentModel3,
Expand Down
42 changes: 0 additions & 42 deletions pkg/modules/generators/app_configurations_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,6 @@ import (
"kusionstack.io/kusion/pkg/apis/core/v1/workload"
)

func TestAppConfigurationGenerator_Generate(t *testing.T) {
appName, app := buildMockApp()
ws := buildMockWorkspace("")

g := &appConfigurationGenerator{
project: "fakeNs",
stack: "test",
appName: appName,
app: app,
ws: ws,
}

spec := &v1.Intent{
Resources: []v1.Resource{},
}

mockPlugin()
err := g.Generate(spec)
assert.NoError(t, err)
assert.NotEmpty(t, spec.Resources)

// namespace name assertion
for _, res := range spec.Resources {
if res.Type != v1.Kubernetes {
continue
}
actual := mapToUnstructured(res.Attributes)
if actual.GetKind() == "Namespace" {
assert.Equal(t, "fakeNs", actual.GetName(), "namespace name should be fakeNs")
} else {
ns := actual.GetNamespace()
if ns == "" {
// Manually get the namespace from the unstructured object.
if ns, err = getNamespace(actual); err != nil {
t.Fatal(err)
}
}
assert.Equal(t, "fakeNs", ns, "namespace name should be fakeNs")
}
}
}

type fakeModule struct{}

func (f *fakeModule) Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error) {
Expand Down
45 changes: 23 additions & 22 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,29 @@ func createSampleWorkspace() error {
}
ws := &v1.Workspace{
Name: "dev",
Modules: v1.ModuleConfigs{
"database": {
Default: v1.GenericConfig{
"type": "aws",
"version": "5.7",
"instanceType": "db.t3.micro",
},
ModulePatcherConfigs: v1.ModulePatcherConfigs{
"smallClass": {
GenericConfig: v1.GenericConfig{
"instanceType": "db.t3.small",
},
ProjectSelector: []string{"foo", "bar"},
},
},
},
"port": {
Default: v1.GenericConfig{
"type": "aws",
},
},
},
// comment out for now, as download modules from remote repo is not supported yet.
// Modules: v1.ModuleConfigs{
// "database": {
// Default: v1.GenericConfig{
// "type": "aws",
// "version": "5.7",
// "instanceType": "db.t3.micro",
// },
// ModulePatcherConfigs: v1.ModulePatcherConfigs{
// "smallClass": {
// GenericConfig: v1.GenericConfig{
// "instanceType": "db.t3.small",
// },
// ProjectSelector: []string{"foo", "bar"},
// },
// },
// },
// "port": {
// Default: v1.GenericConfig{
// "type": "aws",
// },
// },
// },
}
return wsOperator.CreateWorkspace(ws)
}
Expand Down

0 comments on commit 4cfbb09

Please sign in to comment.