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
  • Loading branch information
SparkYuan committed Mar 13, 2024
1 parent b564ea5 commit 307d4e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 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

0 comments on commit 307d4e5

Please sign in to comment.