-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ut: add generator and namespace tests
- Loading branch information
Showing
2 changed files
with
187 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
pkg/generator/appconfiguration/generators/namespace_generator_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package generators | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"kusionstack.io/kusion/pkg/models" | ||
) | ||
|
||
func Test_namespaceGenerator_Generate(t *testing.T) { | ||
type fields struct { | ||
projectName string | ||
} | ||
type args struct { | ||
spec *models.Spec | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want *models.Spec | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "namespace", | ||
fields: fields{ | ||
projectName: "fake-project", | ||
}, | ||
args: args{ | ||
spec: &models.Spec{}, | ||
}, | ||
want: &models.Spec{ | ||
Resources: []models.Resource{ | ||
{ | ||
ID: "v1:Namespace:fake-project", | ||
Type: "Kubernetes", | ||
Attributes: map[string]interface{}{ | ||
"apiVersion": "v1", | ||
"kind": "Namespace", | ||
"metadata": map[string]interface{}{ | ||
"creationTimestamp": nil, | ||
"name": "fake-project", | ||
}, | ||
"spec": make(map[string]interface{}), | ||
"status": make(map[string]interface{}), | ||
}, | ||
DependsOn: nil, | ||
Extensions: nil, | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
g := &namespaceGenerator{ | ||
projectName: tt.fields.projectName, | ||
} | ||
if err := g.Generate(tt.args.spec); (err != nil) != tt.wantErr { | ||
t.Errorf("Generate() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
require.Equal(t, tt.want, tt.args.spec) | ||
}) | ||
} | ||
} |