Skip to content

Commit b18a386

Browse files
committed
refactor: use spec.Parse
This moves the naming to the ParseDir() function as naming based on directory name only makes sense in the context of spec.json. Inline environments can technically be run form anywhere, only convention keeps them in this assumed directory structure.
1 parent 5c506a3 commit b18a386

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pkg/spec/depreciations_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
func TestDeprecated(t *testing.T) {
1515
data := []byte(`
1616
{
17+
"metadata": {
18+
"name": "test"
19+
},
1720
"spec": {
1821
"namespace": "new"
1922
},
@@ -23,7 +26,7 @@ func TestDeprecated(t *testing.T) {
2326
}
2427
`)
2528

26-
got, err := Parse(data, "test")
29+
got, err := Parse(data)
2730
require.Equal(t, ErrDeprecated{
2831
{old: "server", new: "spec.apiServer"},
2932
{old: "team", new: "metadata.labels.team"},

pkg/spec/spec.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,22 @@ func ParseDir(baseDir, name string) (*v1alpha1.Config, error) {
3939
return nil, err
4040
}
4141

42-
return Parse(data, name)
42+
c, err := Parse(data)
43+
if c != nil {
44+
// set the name field
45+
c.Metadata.Name = name
46+
}
47+
48+
return c, err
4349
}
4450

4551
// Parse parses the json `data` into a `v1alpha1.Config` object.
46-
// `name` is the name of the environment
47-
func Parse(data []byte, name string) (*v1alpha1.Config, error) {
52+
func Parse(data []byte) (*v1alpha1.Config, error) {
4853
config := v1alpha1.New()
4954
if err := json.Unmarshal(data, config); err != nil {
5055
return nil, errors.Wrap(err, "parsing spec.json")
5156
}
5257

53-
// set the name field
54-
config.Metadata.Name = name
55-
5658
if err := handleDeprecated(config, data); err != nil {
5759
return config, err
5860
}

0 commit comments

Comments
 (0)