-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v3 format support to keep YAML property orders and comments using kustomize/kyaml - refactoring charts packages. add api/v1alpha1 packages to define chartsnap's specs: e.g. testspec in values.yaml, snapshot file header and unknown resource.
- Loading branch information
1 parent
f40c890
commit 677c95f
Showing
46 changed files
with
4,162 additions
and
312 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
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
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
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,87 @@ | ||
['TestSpec FromFile when loading .chartsnap.yaml should load config 1'] | ||
SnapShot = """ | ||
{ | ||
\"DynamicFields\": [ | ||
{ | ||
\"Kind\": \"Secret\", | ||
\"APIVersion\": \"v1\", | ||
\"Name\": \"app1-cert\", | ||
\"JSONPath\": [ | ||
\"/data/ca.crt\", | ||
\"/data/tls.crt\", | ||
\"/data/tls.key\" | ||
], | ||
\"Base64\": true | ||
} | ||
] | ||
} | ||
""" | ||
['TestSpec FromFile when loading invalid yaml should not load config 1'] | ||
SnapShot = """ | ||
failed to decode file 'testdata/testspec_values_invalid.yaml': yaml: line 10: could not find expected ':'""" | ||
|
||
['TestSpec FromFile when values.yaml has testSpec should load config 1'] | ||
SnapShot = """ | ||
{ | ||
\"TestSpec\": { | ||
\"DynamicFields\": [ | ||
{ | ||
\"Kind\": \"Secret\", | ||
\"APIVersion\": \"v1\", | ||
\"Name\": \"app1-cert\", | ||
\"JSONPath\": [ | ||
\"/data/ca.crt\", | ||
\"/data/tls.crt\", | ||
\"/data/tls.key\" | ||
], | ||
\"Base64\": true | ||
} | ||
] | ||
} | ||
} | ||
""" | ||
['TestSpec Merge should merge dynamic fields 1'] | ||
SnapShot = """ | ||
{ | ||
\"DynamicFields\": [ | ||
{ | ||
\"Kind\": \"service\", | ||
\"APIVersion\": \"v1\", | ||
\"Name\": \"chartsnap-app1\", | ||
\"JSONPath\": [ | ||
\"/spec/ports/0/targetPort\" | ||
], | ||
\"Base64\": false | ||
}, | ||
{ | ||
\"Kind\": \"Pod\", | ||
\"APIVersion\": \"v1\", | ||
\"Name\": \"chartsnap-app1-test-connection\", | ||
\"JSONPath\": [ | ||
\"/metadata/name\" | ||
], | ||
\"Base64\": false | ||
}, | ||
{ | ||
\"Kind\": \"service\", | ||
\"APIVersion\": \"v1\", | ||
\"Name\": \"chartsnap-app1\", | ||
\"JSONPath\": [ | ||
\"/spec/ports/0/targetPort\" | ||
], | ||
\"Base64\": false | ||
}, | ||
{ | ||
\"Kind\": \"Service\", | ||
\"APIVersion\": \"v1\", | ||
\"Name\": \"chartsnap-app1\", | ||
\"JSONPath\": [ | ||
\"/spec/ports/1/targetPort\" | ||
], | ||
\"Base64\": false | ||
} | ||
] | ||
} | ||
""" |
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,40 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
) | ||
|
||
type Header struct { | ||
SnapshotVersion string `header:"snapshot_version"` | ||
} | ||
|
||
func (h *Header) ToString() string { | ||
return fmt.Sprintf("# chartsnap: snapshot_version=%s\n---\n", h.SnapshotVersion) | ||
} | ||
|
||
func ParseHeader(line string) *Header { | ||
h := Header{} | ||
ht := reflect.TypeOf(h) | ||
hv := reflect.ValueOf(&h).Elem() | ||
|
||
split := strings.Split(string([]byte(line)[1:]), " ") | ||
for _, v := range split { | ||
s := strings.Split(v, "=") | ||
if len(s) != 2 { | ||
continue | ||
} | ||
|
||
headerName := strings.TrimSpace(s[0]) | ||
headerValue := strings.TrimSpace(s[1]) | ||
|
||
for i := 0; i < hv.NumField(); i++ { | ||
field := ht.Field(i) | ||
if tag, ok := field.Tag.Lookup("header"); ok && tag == headerName { | ||
hv.Field(i).SetString(headerValue) | ||
} | ||
} | ||
} | ||
return &h | ||
} |
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,66 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestHeader_ToString(t *testing.T) { | ||
type fields struct { | ||
Version string | ||
SnapshotVersion string | ||
Chart string | ||
Values string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want string | ||
}{ | ||
{ | ||
name: "Test Header ToString", | ||
fields: fields{ | ||
SnapshotVersion: "v3", | ||
}, | ||
want: "# chartsnap: snapshot_version=v3\n---\n", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
h := &Header{ | ||
SnapshotVersion: tt.fields.SnapshotVersion, | ||
} | ||
if got := h.ToString(); got != tt.want { | ||
t.Errorf("Header.ToString() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestParseHeader(t *testing.T) { | ||
type args struct { | ||
line string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Header | ||
}{ | ||
{ | ||
name: "Test ParseHeader", | ||
args: args{ | ||
line: "# chartsnap: snapshot_version=v3\n", | ||
}, | ||
want: &Header{ | ||
SnapshotVersion: "v3", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ParseHeader(tt.args.line); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ParseHeader() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.