diff --git a/go.mod b/go.mod index faa055793f7a..5c2b91180d29 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( // * We log an error if writing a cache key fails (e.g. because disk is full) // * We inject a header that allows ghproxy to detect if the response was revalidated or a cache miss github.com/cjwagner/httpcache v0.0.0-20230907212505-d4841bbad466 // indirect - github.com/clarketm/json v1.13.4 + github.com/clarketm/json v1.13.4 // indirect github.com/client9/misspell v0.3.4 github.com/denormal/go-gitignore v0.0.0-20180930084346-ae8ad1d07817 // indirect github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 // indirect diff --git a/hack/gen-prow-documented/main.go b/hack/gen-prow-documented/main.go deleted file mode 100644 index 7b55ab093e23..000000000000 --- a/hack/gen-prow-documented/main.go +++ /dev/null @@ -1,95 +0,0 @@ -/* -Copyright 2022 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "flag" - "fmt" - "os" - "path" - "path/filepath" - - "github.com/sirupsen/logrus" - "k8s.io/test-infra/pkg/genyaml" - "sigs.k8s.io/prow/pkg/config" - "sigs.k8s.io/prow/pkg/plugins" -) - -const ( - // Pretending that it runs from root of the repo - defaultRootDir = "." -) - -var genConfigs = []genConfig{ - { - in: []string{ - "prow/config/*.go", - "prow/apis/prowjobs/v1/*.go", - }, - format: &config.ProwConfig{}, - out: "prow/config/prow-config-documented.yaml", - }, - { - in: []string{ - "prow/plugins/*.go", - }, - format: &plugins.Configuration{}, - out: "prow/plugins/plugin-config-documented.yaml", - }, -} - -type genConfig struct { - in []string - format interface{} - out string -} - -func (g *genConfig) gen(rootDir string) error { - var inputFiles []string - for _, goGlob := range g.in { - ifs, err := filepath.Glob(path.Join(rootDir, goGlob)) - if err != nil { - return fmt.Errorf("filepath glob: %w", err) - } - inputFiles = append(inputFiles, ifs...) - } - - commentMap, err := genyaml.NewCommentMap(nil, inputFiles...) - if err != nil { - return fmt.Errorf("failed to construct commentMap: %w", err) - } - actualYaml, err := commentMap.GenYaml(genyaml.PopulateStruct(g.format)) - if err != nil { - return fmt.Errorf("genyaml errored: %w", err) - } - if err := os.WriteFile(path.Join(rootDir, g.out), []byte(actualYaml), 0644); err != nil { - return fmt.Errorf("failed to write fixture: %w", err) - } - return nil -} - -func main() { - rootDir := flag.String("root-dir", defaultRootDir, "Repo root dir.") - flag.Parse() - - for _, g := range genConfigs { - if err := g.gen(*rootDir); err != nil { - logrus.WithError(err).WithField("fixture", g.out).Error("Failed generating.") - os.Exit(1) - } - } -} diff --git a/hack/gen-prow-documented/main_test.go b/hack/gen-prow-documented/main_test.go deleted file mode 100644 index 45e357a394be..000000000000 --- a/hack/gen-prow-documented/main_test.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2022 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "os" - "path" - "testing" - - "github.com/google/go-cmp/cmp" -) - -func TestGen(t *testing.T) { - type FakeReporter struct { - // Context is the name of the GitHub status context for the job. - // Defaults: the same as the name of the job. - Context string `json:"context,omitempty"` - // SkipReport skips commenting and setting status on GitHub. - SkipReport bool `json:"skip_report,omitempty"` - } - - tests := []struct { - name string - rawContents []byte - expectedRawYaml []byte - }{ - { - name: "also-read-raw", - rawContents: []byte(`package main -type FakeReporter struct { - // Context is the name of the GitHub status context for the job. - // Defaults: the same as the name of the job. - Context string ` + "`" + `json:"context,omitempty"` + "`" + ` - // SkipReport skips commenting and setting status on GitHub. - SkipReport bool ` + "`" + `json:"skip_report,omitempty"` + "`" + ` -}`), - expectedRawYaml: []byte(`# Context is the name of the GitHub status context for the job. -# Defaults: the same as the name of the job. -context: ' ' -# SkipReport skips commenting and setting status on GitHub. -skip_report: true -`), - }, - } - - for _, tc := range tests { - tc := tc - t.Run(tc.name, func(t *testing.T) { - tmpDir := t.TempDir() - in, out := tc.name+".in", tc.name+".out" - if err := os.WriteFile(path.Join(tmpDir, in), tc.rawContents, 0644); err != nil { - t.Fatalf("Failed creating input: %v", err) - } - g := genConfig{ - in: []string{ - in, - }, - format: &FakeReporter{}, - out: out, - } - - if err := g.gen(tmpDir); err != nil { - t.Fatalf("Got unexpected error: %v", err) - } - - got, err := os.ReadFile(path.Join(tmpDir, out)) - if err != nil { - t.Fatalf("Failed reading out: %v", err) - } - if diff := cmp.Diff(string(tc.expectedRawYaml), string(got)); diff != "" { - t.Fatalf("Mismatch:\n%s", diff) - } - }) - } -} diff --git a/pkg/genyaml/OWNERS b/pkg/genyaml/OWNERS deleted file mode 100644 index 8a90582a8e82..000000000000 --- a/pkg/genyaml/OWNERS +++ /dev/null @@ -1,6 +0,0 @@ -# See the OWNERS docs at https://go.k8s.io/owners - -reviewers: -- clarketm -approvers: -- clarketm diff --git a/pkg/genyaml/README.md b/pkg/genyaml/README.md deleted file mode 100644 index 2c9f6cb9b4fa..000000000000 --- a/pkg/genyaml/README.md +++ /dev/null @@ -1,190 +0,0 @@ -# Genyaml - -## Description -`genyaml` is a simple documentation tool used to marshal YAML from Golang structs. It extracts *doc comments* from `.go` sources files and adds them as *comment nodes* in the YAML output. - -## Usage - -TODOs are ignored (e.g. TODO(clarketm)... or TODO...) if and only if they are on a **single** line. - -```go -type Employee struct { - // Name of employee - Name string - // Age of employee - Age int - // TODO(clarketm): change this to a float64 - // Salary of employee - Salary int -} -``` - -```yaml -# Age of employee -Age: 22 - -# Name of employee -Name: Jim - -# Salary of employee -Salary: 100000 -``` - -Multiline comments are preserved, albeit *tabs* are converted to *spaces* and *multiple* spaces are compressed into a *single* line. - -```go -type Multiline struct { - // StringField1 comment - // second line - // third line - StringField1 string `json:"string1"` - - /* StringField2 comment - second line - third line - */ - StringField2 string `json:"string2"` - - /* StringField3 comment - second line - third line - */ - StringField3 string `json:"string3"` -} -``` - -```yaml -# StringField1 comment -# second line -# third line -string1: string1 - -# StringField2 comment -# second line -# third line -string2: string2 - -# StringField3 comment -# second line -# third line -string3: string3 -``` - -All subsequent lines and blocks after a `---` will be ignored. - -```go -type Person struct { - // Name of person - // --- - // The name of the person is both the first and last name separated - // by a space character - Name string -} -``` - -```yaml -# Name of person -Name: Frank -``` - -Generator instructions prefixed with a `+` are ignored. - -```go -type Dog struct { - // Gender of dog (male|female) - // +optional - Gender string `json:"gender,omitempty"` - // Weight in pounds of dog - Weight int `json:"weight,omitempty"` -} -``` - -```yaml -# Gender of dog (male|female) -gender: male - -# Weight in pounds of dog -weight: 150 -``` - -## Example - -First, assume there is a Go file `config.go` with the following contents: -> NOTE: `genyaml` reads **json** tags for maximum portability. - -```go -// config.go - -package example - -type Configuration struct { - // Plugin comment - Plugin []Plugin `json:"plugin,omitempty"` -} - -type Plugin struct { - // StringField comment - StringField string `json:"string,omitempty"` - // BooleanField comment - BooleanField bool `json:"boolean,omitempty"` - // IntegerField comment - IntegerField int `json:"integer,omitempty"` -} -//... -``` - -Next, in a separate `example.go` file, initialize a `Configuration` struct and marshal it to *commented* YAML. - -```go -// example.go - -package example - -// Import genyaml -import "k8s.io/test-infra/pkg/genyaml" - -//... - -// Initialize a `Configuration` struct: -config := &example.Configuration{ - Plugin: []example.Plugin{ - { - StringField: "string", - BooleanField: true, - IntegerField: 1, - }, - }, -} - -// Initialize a CommentMap instance from the `config.go` source file: -cm, err := genyaml.NewCommentMap(nil, "config.go") - -// Generate a commented YAML snippet: -yamlSnippet, err := cm.GenYaml(config) -``` - -The doc comments are extracted from the `config.go` file and attached to the corresponding YAML fields: - -```go -fmt.Println(yamlSnippet) -``` - -```yaml -# Plugin comment -plugin: - - # BooleanField comment - boolean: true - - # IntegerField comment - integer: 1 - - # StringField comment - string: string - -``` - -## Limitations / Going Forward - -- [ ] Embedded structs must include a tag name (i.e. must not be *spread*), otherwise the type can not be inferred from the YAML output. -- [ ] Interface types, more specifically concrete types implementing a particular interface, can can not be inferred from the YAML output. -- [ ] Upstream this functionality to `go-yaml` (or a fork) to leverage custom formatting of YAML and direct reflection on types for resolving embedded structs and interface types across multiple source files. diff --git a/pkg/genyaml/genyaml.go b/pkg/genyaml/genyaml.go deleted file mode 100644 index 297b423d053f..000000000000 --- a/pkg/genyaml/genyaml.go +++ /dev/null @@ -1,492 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package genyaml can generate an example YAML snippet from -// an initialized struct and decorate it with godoc comments parsed -// from the AST of a given file. -// -// Example: -// -// cm, err := NewCommentMap("example_config.go") -// -// yamlSnippet, err := cm.GenYaml(&plugins.Configuration{ -// Approve: []plugins.Approve{ -// { -// Repos: []string{ -// "ORGANIZATION", -// "ORGANIZATION/REPOSITORY", -// }, -// IssueRequired: false, -// RequireSelfApproval: new(bool), -// LgtmActsAsApprove: false, -// IgnoreReviewState: new(bool), -// }, -// }, -// }) -// -// Alternatively, you can also use `PopulateStruct` to recursively fill all pointer fields, slices and maps of a struct via reflection: -// -// yamlSnippet, err := cm.GenYaml(PopulateStruct(&plugins.Configuration{})) -// -// yamlSnippet will be assigned a string containing the following YAML: -// -// # Approve is the configuration for the Approve plugin. -// approve: -// - # Repos is either of the form org/repos or just org. -// repos: -// - ORGANIZATION -// - ORGANIZATION/REPOSITORY -// -// # IssueRequired indicates if an associated issue is required for approval in the specified repos. -// issue_required: true -// -// # RequireSelfApproval requires PR authors to explicitly approve their PRs. Otherwise the plugin assumes the author of the PR approves the changes in the PR. -// require_self_approval: false -// -// # LgtmActsAsApprove indicates that the lgtm command should be used to indicate approval -// lgtm_acts_as_approve: true -// -// # IgnoreReviewState causes the approve plugin to ignore the GitHub review state. Otherwise: * an APPROVE github review is equivalent to leaving an \"/approve\" message. * A REQUEST_CHANGES github review is equivalent to leaving an /approve cancel\" message. -// ignore_review_state: false -package genyaml - -import ( - "bytes" - "errors" - "fmt" - "go/ast" - "go/doc" - "go/parser" - "go/token" - "path/filepath" - "reflect" - "regexp" - "strings" - "sync" - - "github.com/clarketm/json" - "k8s.io/apimachinery/pkg/util/sets" - yaml3 "sigs.k8s.io/yaml/goyaml.v3" -) - -const ( - jsonTag = "json" -) - -// Comment is an abstract structure for storing mapped types to comments. -type CommentMap struct { - // comments is a map of string(typeSpecName) -> string(tagName) -> Comment. - comments map[string]map[string]Comment - // RWMutex is a read/write mutex. - sync.RWMutex -} - -// NewCommentMap is the constructor for CommentMap accepting a variadic number -// of path and raw files contents. -func NewCommentMap(rawFiles map[string][]byte, paths ...string) (*CommentMap, error) { - cm := &CommentMap{ - comments: make(map[string]map[string]Comment), - } - - // Group files in dir assuming they are from the same package, this - // technically doesn't hold true all the time, but is the best effort to - // ensure that generated yamls are from the same package. - type group struct { - paths []string - rawContents map[string][]byte - } - - packageFiles := map[string]*group{} - for _, path := range paths { - dir := filepath.Dir(path) - if _, ok := packageFiles[dir]; !ok { - packageFiles[dir] = &group{} - } - packageFiles[dir].paths = append(packageFiles[dir].paths, path) - } - - for path, content := range rawFiles { - dir := filepath.Dir(path) - if _, ok := packageFiles[dir]; !ok { - packageFiles[dir] = &group{} - } - packageFiles[dir].rawContents = map[string][]byte{path: content} - } - - for pkg, files := range packageFiles { - if err := cm.addPackage(files.paths, files.rawContents); err != nil { - return nil, fmt.Errorf("failed to add files in %s: %w", pkg, err) - } - } - - return cm, nil -} - -// Comment is an abstract structure for storing parsed AST comments decorated with contextual information. -type Comment struct { - // Type is the underlying type of the identifier associated with the comment. - Type string - // IsObj determines if the underlying type is a object type (e.g. struct) or primitive type (e.g. string). - IsObj bool - // Doc is a comment string parsed from the AST of a node. - Doc string -} - -// marshal marshals the object into JSON then converts JSON to YAML and returns the YAML. -func marshal(o interface{}) ([]byte, error) { - j, err := json.Marshal(o) - if err != nil { - return nil, fmt.Errorf("error marshaling into JSON: %w", err) - } - - y, err := jsonToYaml(j) - if err != nil { - return nil, fmt.Errorf("error converting JSON to YAML: %w", err) - } - - return y, nil -} - -// jsonToYaml Converts JSON to YAML. -func jsonToYaml(j []byte) ([]byte, error) { - // Convert the JSON to an object. - var jsonObj interface{} - // We are using yaml.Unmarshal here (instead of json.Unmarshal) because the - // Go JSON library doesn't try to pick the right number type (int, float, - // etc.) when unmarshalling to interface{}, it just picks float64 - // universally. go-yaml does go through the effort of picking the right - // number type, so we can preserve number type throughout this process. - err := yaml3.Unmarshal(j, &jsonObj) - if err != nil { - return nil, err - } - - // marshal this object into YAML. - return yaml3.Marshal(jsonObj) -} - -// astFrom takes paths of Go files, or the content of Go files, -// returns the abstract syntax tree (AST) for that file. -func astFrom(paths []string, rawFiles map[string][]byte) (*doc.Package, error) { - fset := token.NewFileSet() - m := make(map[string]*ast.File) - - for _, file := range paths { - f, err := parser.ParseFile(fset, file, nil, parser.ParseComments) - if err != nil { - return nil, fmt.Errorf("unable to parse file to AST from path %s: %w", file, err) - } - m[file] = f - } - for fn, content := range rawFiles { - f, err := parser.ParseFile(fset, fn, content, parser.ParseComments) - if err != nil { - return nil, fmt.Errorf("unable to parse file to AST from raw content %s: %w", fn, err) - } - m[fn] = f - } - - // Copied from the go doc command: https://github.com/golang/go/blob/fc116b69e2004c159d0f2563c6e91ac75a79f872/src/go/doc/doc.go#L203 - apkg, _ := ast.NewPackage(fset, m, simpleImporter, nil) - - astDoc := doc.New(apkg, "", 0) - if astDoc == nil { - return nil, fmt.Errorf("unable to parse AST documentation from paths %v: got no doc", paths) - } - - return astDoc, nil -} - -func simpleImporter(imports map[string]*ast.Object, path string) (*ast.Object, error) { - pkg := imports[path] - if pkg == nil { - // note that strings.LastIndex returns -1 if there is no "/" - pkg = ast.NewObj(ast.Pkg, path[strings.LastIndex(path, "/")+1:]) - pkg.Data = ast.NewScope(nil) // required by ast.NewPackage for dot-import - imports[path] = pkg - } - return pkg, nil -} - -// fmtRawDoc formats/sanitizes a Go doc string removing TODOs, newlines, whitespace, and various other characters from the resultant string. -func fmtRawDoc(rawDoc string) string { - var buffer bytes.Buffer - - // Ignore all lines after ---. - rawDoc = strings.Split(rawDoc, "---")[0] - - for _, line := range strings.Split(rawDoc, "\n") { - line = strings.TrimSpace(line) // Trim leading and trailing whitespace. - switch { - case strings.HasPrefix(line, "TODO"): // Ignore one line TODOs. - case strings.HasPrefix(line, "+"): // Ignore instructions to the generators. - default: - line += "\n" - buffer.WriteString(line) - } - } - - postDoc := strings.TrimRight(buffer.String(), "\n") // Remove last newline. - postDoc = strings.Replace(postDoc, "\t", " ", -1) // Replace tabs with spaces. - postDoc = regexp.MustCompile(` +`).ReplaceAllString(postDoc, " ") // Compress multiple spaces to a single space. - - return postDoc -} - -// fieldTag extracts the given tag or returns an empty string if the tag is not defined. -func fieldTag(field *ast.Field, tag string) string { - if field.Tag == nil { - return "" - } - - return reflect.StructTag(field.Tag.Value[1 : len(field.Tag.Value)-1]).Get(tag) -} - -// fieldName extracts the name of the field as it should appear in YAML format and returns the resultant string. -// "-" indicates that this field is not part of the YAML representation and is thus excluded. -func fieldName(field *ast.Field, tag string) string { - tagVal := strings.Split(fieldTag(field, tag), ",")[0] // This can return "-". - if tagVal == "" { - // Set field name to the defined name in struct if defined. - if field.Names != nil { - return field.Names[0].Name - } - // Fallback field name to the immediate field type. - name, _ := fieldType(field, false) - return name - } - return tagVal -} - -// fieldIsInlined returns true if the field is tagged with ",inline" -func fieldIsInlined(field *ast.Field, tag string) bool { - values := sets.NewString(strings.Split(fieldTag(field, tag), ",")...) - - return values.Has("inline") -} - -// fieldType extracts the type of the field and returns the resultant string type and a bool indicating if it is an object type. -func fieldType(field *ast.Field, recurse bool) (string, bool) { - typeName := "" - isObj, isSelect := false, false - - // Find leaf node. - ast.Inspect(field, func(n ast.Node) bool { - switch x := n.(type) { - case *ast.Field: - // First node is always a field; skip. - return true - case *ast.Ident: - // Encountered a type, overwrite typeName and isObj. - typeName = x.Name - isObj = x.Obj != nil || isSelect - case *ast.SelectorExpr: - // SelectorExpr are not object types yet reference one, thus continue with DFS. - isSelect = true - } - - return recurse || isSelect - }) - - return typeName, isObj -} - -// getType returns the type's name within its package for a defined type. For other (non-defined) types it returns the empty string. -func getType(typ interface{}) string { - t := reflect.TypeOf(typ) - if t.Kind() == reflect.Ptr { - return t.Elem().Name() - } - return t.Name() -} - -// genDocMap extracts the name of the field as it should appear in YAML format and returns the resultant string. -func (cm *CommentMap) genDocMap(packageFiles []string, rawFiles map[string][]byte) error { - pkg, err := astFrom(packageFiles, rawFiles) - if err != nil { - return fmt.Errorf("unable to generate AST documentation map: %w", err) - } - - inlineFields := map[string][]string{} - - for _, t := range pkg.Types { - if typeSpec, ok := t.Decl.Specs[0].(*ast.TypeSpec); ok { - - var lst []*ast.Field - - // Support struct type, interface type, and type alias. - switch typ := typeSpec.Type.(type) { - case *ast.InterfaceType: - lst = typ.Methods.List - case *ast.StructType: - lst = typ.Fields.List - case *ast.Ident: - // ensure that aliases for non-struct/interface types continue to work - if typ.Obj != nil { - if alias, ok := typ.Obj.Decl.(*ast.TypeSpec).Type.(*ast.InterfaceType); ok { - lst = alias.Methods.List - } else if alias, ok := typ.Obj.Decl.(*ast.TypeSpec).Type.(*ast.StructType); ok { - lst = alias.Fields.List - } - } - } - - typeSpecName := typeSpec.Name.Name - cm.comments[typeSpecName] = make(map[string]Comment) - - for _, field := range lst { - - if tagName := fieldName(field, jsonTag); tagName != "-" { - typeName, isObj := fieldType(field, true) - docString := fmtRawDoc(field.Doc.Text()) - cm.comments[typeSpecName][tagName] = Comment{typeName, isObj, docString} - - if fieldIsInlined(field, jsonTag) { - existing, ok := inlineFields[typeSpecName] - if !ok { - existing = []string{} - } - inlineFields[typeSpecName] = append(existing, tagName) - } - } - } - } - } - - // copy comments for inline fields from their original parent structures; this is needed - // because when walking the generated YAML, the step to switch to the "correct" parent - // struct is missing - for typeSpecName, inlined := range inlineFields { - for _, inlinedType := range inlined { - for tagName, comment := range cm.comments[inlinedType] { - cm.comments[typeSpecName][tagName] = comment - } - } - } - - return nil -} - -// injectComment reads a YAML node and injects a head comment based on its value and typeSpec. -func (cm *CommentMap) injectComment(parent *yaml3.Node, typeSpec []string, depth int) { - if parent == nil || depth >= len(typeSpec) { - return - } - - typ := typeSpec[depth] - isArray := parent.Kind == yaml3.SequenceNode - - // Decorate YAML node with comment. - if v, ok := cm.comments[typ][parent.Value]; ok { - parent.HeadComment = v.Doc - } - - if parent.Content != nil { - for i, child := range parent.Content { - - // Default type for node is current (i.e. most recent) type. - nxtTyp := typeSpec[len(typeSpec)-1] - - if i > 0 { - prevSibling := parent.Content[i-1] - - // Skip value nodes. - if prevSibling.Kind == yaml3.ScalarNode && child.Kind == yaml3.ScalarNode && i%2 == 1 { - continue - } - - // New type detected; add type of key (i.e. prevSibling) to stack. - if parent.Kind == yaml3.MappingNode && prevSibling.Kind == yaml3.ScalarNode { - if subTypeSpec, ok := cm.comments[typ][prevSibling.Value]; ok && subTypeSpec.IsObj { - nxtTyp = subTypeSpec.Type - } - } - } - - // only recurse into the first element of an array, as documenting all further - // array items would be redundant - if !isArray || i == 0 { - // Recurse to inject comments on nested YAML nodes. - cm.injectComment(child, append(typeSpec, nxtTyp), depth+1) - } - } - } - -} - -// PrintComments pretty prints comments. -func (cm *CommentMap) PrintComments() { - cm.RLock() - defer cm.RUnlock() - - data, err := json.MarshalIndent(cm.comments, "", " ") - if err == nil { - fmt.Print(string(data)) - } -} - -// addPackage allow for adding to the CommentMap via a list of paths to go files in the same package -func (cm *CommentMap) addPackage(paths []string, rawFiles map[string][]byte) error { - cm.Lock() - defer cm.Unlock() - - err := cm.genDocMap(paths, rawFiles) - if err != nil { - return err - } - - return nil -} - -// GenYaml generates a fully commented YAML snippet for a given plugin configuration. -func (cm *CommentMap) GenYaml(config interface{}) (string, error) { - var buffer bytes.Buffer - - encoder := yaml3.NewEncoder(&buffer) - - err := cm.EncodeYaml(config, encoder) - if err != nil { - return "", fmt.Errorf("failed to encode config as YAML: %w", err) - } - - return buffer.String(), nil -} - -// EncodeYaml encodes a fully commented YAML snippet for a given plugin configuration -// using the given encoder. -func (cm *CommentMap) EncodeYaml(config interface{}, encoder *yaml3.Encoder) error { - cm.RLock() - defer cm.RUnlock() - - var baseTypeSpec = getType(config) - - // Convert Config object to an abstract YAML node. - y1, err := marshal(&config) - if err != nil { - return fmt.Errorf("failed to marshal config to yaml: %w", err) - } - - node := yaml3.Node{} - err = yaml3.Unmarshal([]byte(y1), &node) - if err != nil { - return errors.New("failed to unmarshal yaml to yaml node") - } - - // Inject comments - cm.injectComment(&node, []string{baseTypeSpec}, 0) - - return encoder.Encode(&node) -} diff --git a/pkg/genyaml/genyaml_test.go b/pkg/genyaml/genyaml_test.go deleted file mode 100644 index 1169133e672e..000000000000 --- a/pkg/genyaml/genyaml_test.go +++ /dev/null @@ -1,476 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package genyaml - -import ( - "bytes" - "encoding/json" - "os" - "path/filepath" - "strings" - "testing" - - yaml3 "sigs.k8s.io/yaml/goyaml.v3" - - simplealiases "k8s.io/test-infra/pkg/genyaml/testdata/alias_simple_types" - aliases "k8s.io/test-infra/pkg/genyaml/testdata/alias_types" - embedded "k8s.io/test-infra/pkg/genyaml/testdata/embedded_structs" - inlines "k8s.io/test-infra/pkg/genyaml/testdata/inline_structs" - interfaces "k8s.io/test-infra/pkg/genyaml/testdata/interface_types" - multiline "k8s.io/test-infra/pkg/genyaml/testdata/multiline_comments" - nested "k8s.io/test-infra/pkg/genyaml/testdata/nested_structs" - tags "k8s.io/test-infra/pkg/genyaml/testdata/no_tags" - omit "k8s.io/test-infra/pkg/genyaml/testdata/omit_if_empty" - pointers "k8s.io/test-infra/pkg/genyaml/testdata/pointer_types" - primitives "k8s.io/test-infra/pkg/genyaml/testdata/primitive_types" - private "k8s.io/test-infra/pkg/genyaml/testdata/private_members" - sequence "k8s.io/test-infra/pkg/genyaml/testdata/sequence_items" -) - -const ( - testDir = "testdata" -) - -func resolvePath(t *testing.T, filename string) string { - name := filepath.Base(t.Name()) - return strings.ToLower(filepath.Join(testDir, name, filename)) -} - -func fileName(t *testing.T, extension string) string { - name := filepath.Base(t.Name()) - return strings.ToLower(filepath.Join(testDir, name, name+"."+extension)) -} - -func readFile(t *testing.T, extension string) []byte { - data, err := os.ReadFile(fileName(t, extension)) - if err != nil { - t.Errorf("Failed reading .%s file: %v.", extension, err) - } - - return data -} - -func TestFmtRawDoc(t *testing.T) { - tests := []struct { - name string - rawDoc string - expected string - }{ - { - name: "Single line comment", - rawDoc: "Owners of the cat.", - expected: "Owners of the cat.", - }, - { - name: "Multi line comment", - rawDoc: "StringField comment\nsecond line\nthird line", - expected: `StringField comment -second line -third line`, - }, - { - name: "Delete trailing space(s)", - rawDoc: "Some comment ", - expected: "Some comment", - }, - { - name: "Delete trailing newline(s)", - rawDoc: "Some comment\n\n\n\n", - expected: "Some comment", - }, - { - name: "Escape double quote(s)", - rawDoc: `"Some comment"`, - expected: `"Some comment"`, - }, - { - name: "Convert tab to space", - rawDoc: "tab tab tabtab", - expected: "tab tab tabtab", - }, - { - name: "Strip TODO prefixed comment", - rawDoc: "TODO: some future work", - expected: "", - }, - { - name: "Strip + prefixed comment", - rawDoc: "+: some future work", - expected: "", - }, - { - name: "Strip TODO prefixed comment from multi line comment", - rawDoc: "TODO: some future work\nmore comment", - expected: "more comment", - }, - { - name: "Strip + prefixed comment from multi line comment", - rawDoc: "+: some future work\nmore comment", - expected: "more comment", - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - actualFormattedRawDoc := fmtRawDoc(test.rawDoc) - - if actualFormattedRawDoc != test.expected { - t.Fatalf("Expected %q, but got result %q", test.expected, actualFormattedRawDoc) - } - }) - } -} - -func TestInjectComment(t *testing.T) { - tests := []struct { - name string - typeSpec string - actualNode *yaml3.Node - expectedNode *yaml3.Node - }{ - { - name: "Inject comments", - typeSpec: "ExampleStruct", - actualNode: &yaml3.Node{ - Kind: yaml3.DocumentNode, - Content: []*yaml3.Node{ - { - Kind: yaml3.MappingNode, - Tag: "!!map", - Content: []*yaml3.Node{ - { - Kind: yaml3.ScalarNode, - Tag: "!!str", - Value: "exampleKey", - }, - { - Kind: yaml3.ScalarNode, - Tag: "!!bool", - Value: "true", - }, - }, - }, - }, - }, - expectedNode: &yaml3.Node{ - Kind: yaml3.DocumentNode, - Content: []*yaml3.Node{ - { - Kind: yaml3.MappingNode, - Tag: "!!map", - Content: []*yaml3.Node{ - { - Kind: yaml3.ScalarNode, - Tag: "!!str", - Value: "exampleKey", - HeadComment: "Some comment", - }, - { - Kind: yaml3.ScalarNode, - Tag: "!!bool", - Value: "true", - }, - }, - }, - }, - }, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - cm, err := NewCommentMap(nil) - if err != nil { - t.Fatalf("Failed to construct comment map: %v", err) - } - - if err := json.Unmarshal(readFile(t, "json"), &cm.comments); err != nil { - t.Errorf("Unexpected error unmarshalling JSON to comments: %v.", err) - } - - cm.injectComment(test.actualNode, []string{test.typeSpec}, 0) - - expectedYaml, err := yaml3.Marshal(test.expectedNode) - if err != nil { - t.Errorf("Unexpected error marshalling Node to YAML: %v.", err) - } - - actualYaml, err := yaml3.Marshal(test.actualNode) - if err != nil { - t.Errorf("Unexpected error marshalling Node to YAML: %v.", err) - } - - if !bytes.Equal(expectedYaml, actualYaml) { - t.Error("Expected yaml snippets to not be equal.") - } - }) - } -} - -func TestAddPath(t *testing.T) { - tests := []struct { - name string - paths []string - expected bool - }{ - { - name: "Single path", - paths: []string{"example_config.go"}, - expected: true, - }, - { - name: "Multiple paths", - paths: []string{"example_config1.go", "example_config2.go"}, - expected: true, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - var resolved []string - for _, file := range test.paths { - resolved = append(resolved, resolvePath(t, file)) - } - cm, err := NewCommentMap(nil, resolved...) - if err != nil { - t.Fatalf("failed to construct comment map: %v", err) - } - - expectedComments := readFile(t, "json") - actualComments, err := json.MarshalIndent(cm.comments, "", " ") - - if err != nil { - t.Errorf("Unexpected error generating JSON from comments: %v.", err) - } - - equal := bytes.Equal(expectedComments, actualComments) - - if equal != test.expected { - t.Errorf("Expected comments equality to be: %t.", test.expected) - } - }) - } - -} - -func TestGenYAML(t *testing.T) { - tests := []struct { - name string - paths []string - rawContents map[string][]byte - structObj interface{} - expectedRawYaml []byte - expected bool - }{ - { - name: "alias types", - paths: []string{"example_config.go"}, - structObj: &aliases.Alias{ - StringField: "string", - }, - expected: true, - }, - { - name: "also-read-raw", - rawContents: map[string][]byte{ - "alias_types.yaml": []byte(`package alias_types -type Alias = AliasedType -type AliasedType struct { - // StringField comment - StringField string ` + "`json:\"string\"`" + ` -}`), - }, - structObj: &aliases.Alias{ - StringField: "string", - }, - expectedRawYaml: []byte(`# StringField comment -string: string -`), - expected: true, - }, - { - name: "alias simple types", - paths: []string{"example_config.go"}, - structObj: &simplealiases.SimpleAliases{ - AliasField: simplealiases.Alias("string"), - }, - expected: true, - }, - { - name: "primitive types", - paths: []string{"example_config.go"}, - structObj: &primitives.Primitives{ - StringField: "string", - BooleanField: true, - IntegerField: 1, - }, - expected: true, - }, - { - name: "multiline comments", - paths: []string{"example_config.go"}, - structObj: &multiline.Multiline{ - StringField1: "string1", - StringField2: "string2", - StringField3: "string3", - StringField4: "string4", - StringField5: "string5", - StringField6: "string6", - }, - expected: true, - }, - { - name: "nested structs", - paths: []string{"example_config.go"}, - structObj: &nested.Parent{ - Age: 35, - Children: []nested.Child{ - {Name: "Jimbo", Age: 4}, - {Name: "Jenny", Age: 5}, - }, - Name: "Mildred", - }, - expected: true, - }, - { - name: "inline structs", - paths: []string{"example_config.go"}, - structObj: &inlines.Resource{ - Metadata: inlines.Metadata{ - Name: "test", - }, - }, - expected: true, - }, - { - name: "embedded structs", - paths: []string{"example_config.go"}, - structObj: &embedded.Building{ - Address: "123 North Main Street", - Bathroom: embedded.Bathroom{Width: 100, Height: 200}, - Bedroom: embedded.Bedroom{Width: 100, Height: 200}, - }, - expected: true, - }, - { - name: "no tags", - paths: []string{"example_config.go"}, - structObj: &tags.Tagless{ - StringField: "string", - BooleanField: true, - IntegerField: 1, - }, - expected: true, - }, - { - name: "omit if empty", - paths: []string{"example_config.go"}, - structObj: &omit.OmitEmptyStrings{ - StringFieldOmitEmpty: "", - StringFieldKeepEmpty: "", - BooleanField: true, - IntegerField: 1, - }, - expected: true, - }, - { - name: "pointer types", - paths: []string{"example_config.go"}, - structObj: &pointers.Zoo{ - Employees: []*pointers.Employee{ - { - Name: "Jim", - Age: 22, - }, - { - Name: "Jane", - Age: 21, - }, - }, - }, - expected: true, - }, - { - name: "private members", - paths: []string{"example_config.go"}, - structObj: private.NewPerson("gamer123", "password123"), - expected: true, - }, - { - name: "sequence items", - paths: []string{"example_config.go"}, - structObj: &sequence.Recipe{ - Ingredients: []sequence.Ingredient{ - { - Name: "potatoes", - Amount: 1, - }, - { - Name: "eggs", - Amount: 2, - }, - }, - }, - expected: true, - }, - { - name: "interface types", - paths: []string{"example_config.go"}, - structObj: &interfaces.Zoo{ - Animals: []interfaces.Animal{ - &interfaces.Lion{ - Name: "Leo", - }, - &interfaces.Cheetah{ - Name: "Charles", - }, - }, - }, - // INFO: Interface type comments are not implemented. - expected: false, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - var paths []string - for _, path := range test.paths { - paths = append(paths, resolvePath(t, path)) - } - cm, err := NewCommentMap(test.rawContents, paths...) - if err != nil { - t.Fatalf("failed to construct comment map: %v", err) - } - expectedYaml := test.expectedRawYaml - if len(expectedYaml) == 0 { - expectedYaml = readFile(t, "yaml") - } - - actualYaml, err := cm.GenYaml(test.structObj) - - if err != nil { - t.Errorf("Unexpected error generating YAML from struct: %v.", err) - } - - equal := bytes.Equal(expectedYaml, []byte(actualYaml)) - - if equal != test.expected { - t.Errorf("Expected yaml snippets equality to be: %t.", test.expected) - } - }) - } -} diff --git a/pkg/genyaml/populate_struct.go b/pkg/genyaml/populate_struct.go deleted file mode 100644 index 927c8740e927..000000000000 --- a/pkg/genyaml/populate_struct.go +++ /dev/null @@ -1,146 +0,0 @@ -/* -Copyright 2020 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package genyaml - -import ( - "encoding/json" - "fmt" - "reflect" - "strings" - - "github.com/sirupsen/logrus" -) - -// PopulateStruct will recursively populate a struct via reflection for consumption by genyaml by: -// * Filling all pointer fields -// * Filling all slices with a one-element slice and filling that one element -// * Filling all maps with a one-element map and filling that one element -// NOTE: PopulateStruct will panic if not fed a pointer. Generally if you care about -// the stability of the app that runs this code, it is strongly recommended to recover panics: -// defer func(){if r := recover(); r != nil { fmt.Printf("Recovered panic: %v", r } }( -func PopulateStruct(in interface{}) interface{} { - typeOf := reflect.TypeOf(in) - if typeOf.Kind() != reflect.Ptr { - panic(fmt.Sprintf("got nonpointer type %T", in)) - } - if typeOf.Elem().Kind() != reflect.Struct { - return in - } - valueOf := reflect.ValueOf(in) - for i := 0; i < typeOf.Elem().NumField(); i++ { - // Unexported - if !valueOf.Elem().Field(i).CanSet() { - continue - } - - if typeOf.Elem().Field(i).Anonymous { - // We can only warn about this, because the go stdlib and some kube types do this :/ - if !strings.Contains(typeOf.Elem().Field(i).Tag.Get("json"), ",inline") { - logrus.Warningf("Found anonymous field without inline annotation, this will produce invalid results. Please add a `json:\",inline\"` annotation if you control the type. Type: %T, parentType: %T", valueOf.Elem().Field(i).Interface(), valueOf.Elem().Interface()) - } - } - switch k := typeOf.Elem().Field(i).Type.Kind(); k { - // We must populate strings, because genyaml uses a custom json lib - // that omits structs that have empty values only and we have some - // structs that only have string fields - // TODO: Is that genyaml behavior intentional? - case reflect.String: - // ArrayOrString comes from Tekton and has a custom marshaller - // that errors when only setting the String field - if typeOf.Elem().Name() == "ArrayOrString" { - valueOf.Elem().FieldByName("Type").SetString("string") - } - valueOf.Elem().Field(i).SetString(" ") - // Needed because of the String field handling - case reflect.Struct: - PopulateStruct(valueOf.Elem().Field(i).Addr().Interface()) - case reflect.Ptr: - ptr := createNonNilPtr(valueOf.Elem().Field(i).Type()) - // Populate our ptr - if ptr.Elem().Kind() == reflect.Struct { - PopulateStruct(ptr.Interface()) - } - // Set it on the parent struct - valueOf.Elem().Field(i).Set(ptr) - case reflect.Slice: - if typeOf.Elem().Field(i).Type == typeOfBytes || typeOf.Elem().Field(i).Type == typeOfJSONRawMessage { - continue - } - // Create a one element slice - slice := reflect.MakeSlice(typeOf.Elem().Field(i).Type, 1, 1) - // Get a pointer to the value - var sliceElementPtr interface{} - if slice.Index(0).Type().Kind() == reflect.Ptr { - // Slice of pointers, make it a non-nil pointer, then pass on its address - slice.Index(0).Set(createNonNilPtr(slice.Index(0).Type())) - sliceElementPtr = slice.Index(0).Interface() - } else { - // Slice of literals - sliceElementPtr = slice.Index(0).Addr().Interface() - } - PopulateStruct(sliceElementPtr) - // Set it on the parent struct - valueOf.Elem().Field(i).Set(slice) - case reflect.Map: - keyType := typeOf.Elem().Field(i).Type.Key() - valueType := typeOf.Elem().Field(i).Type.Elem() - - key := reflect.New(keyType).Elem() - value := reflect.New(valueType).Elem() - - var keyPtr, valPtr interface{} - if key.Kind() == reflect.Ptr { - key.Set(createNonNilPtr(key.Type())) - keyPtr = key.Interface() - } else { - keyPtr = key.Addr().Interface() - } - if value.Kind() == reflect.Ptr { - value.Set(createNonNilPtr(value.Type())) - valPtr = value.Interface() - } else { - valPtr = value.Addr().Interface() - } - PopulateStruct(keyPtr) - PopulateStruct(valPtr) - - mapType := reflect.MapOf(typeOf.Elem().Field(i).Type.Key(), typeOf.Elem().Field(i).Type.Elem()) - concreteMap := reflect.MakeMapWithSize(mapType, 0) - concreteMap.SetMapIndex(key, value) - - valueOf.Elem().Field(i).Set(concreteMap) - case reflect.Bool: - if strings.Contains(typeOf.Elem().Field(i).Tag.Get("json"), ",omitempty") { - valueOf.Elem().Field(i).SetBool(true) - } - } - - } - return in -} - -func createNonNilPtr(in reflect.Type) reflect.Value { - // construct a new **type and call Elem() to get the *type - ptr := reflect.New(in).Elem() - // Give it a value - ptr.Set(reflect.New(ptr.Type().Elem())) - - return ptr -} - -var typeOfBytes = reflect.TypeOf([]byte(nil)) -var typeOfJSONRawMessage = reflect.TypeOf(json.RawMessage{}) diff --git a/pkg/genyaml/populate_struct_test.go b/pkg/genyaml/populate_struct_test.go deleted file mode 100644 index 67066615ac65..000000000000 --- a/pkg/genyaml/populate_struct_test.go +++ /dev/null @@ -1,181 +0,0 @@ -/* -Copyright 2020 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package genyaml - -import ( - "testing" -) - -func TestPopulateStructHandlesPointerFields(t *testing.T) { - s := struct { - Field *struct { - NestedField *int - } - }{} - - PopulateStruct(&s) - if s.Field == nil { - t.Fatalf("Pointer field in struct didn't get set, struct: %+v", s) - } - if s.Field.NestedField == nil { - t.Fatalf("Nested pointer field in struct didn't get set, struct: %+v", s) - } -} - -func TestPopulateStructHandlesSlicesOfLiterals(t *testing.T) { - s := struct { - Field []struct { - NestedField *int - } - }{} - - PopulateStruct(&s) - if n := len(s.Field); n != 1 { - t.Fatalf("Slice didn't get populated, struct: %+v", s) - } - - if s.Field[0].NestedField == nil { - t.Fatalf("Slice element field didn't get populated, struct: %+v", s) - } -} - -func TestPopulateStructHandlesSliceOfPointers(t *testing.T) { - s := struct { - Field []*struct { - NestedField *int - } - }{} - - PopulateStruct(&s) - if n := len(s.Field); n != 1 { - t.Fatalf("Slice didn't get populated, struct: %+v", s) - } - if s.Field[0] == nil { - t.Fatalf("Slice element didn't get populated, struct: %+v", s) - } - - if s.Field[0].NestedField == nil { - t.Fatalf("Slice element field didn't get populated, struct: %+v", s) - } -} - -func TestPopulateStructHandlesMaps(t *testing.T) { - s := struct { - Field map[string]struct { - NestedField *int - } - }{} - - PopulateStruct(&s) - if n := len(s.Field); n != 1 { - t.Fatalf("Map didn't get populated, struct: %+v", s) - } - - for _, v := range s.Field { - if v.NestedField == nil { - t.Fatalf("Pointer field in map element didn't get populated, struct: %+v", s) - } - } -} - -func TestPopulateStructHandlesMapsWithPointerValues(t *testing.T) { - s := struct { - Field map[string]*struct { - NestedField *int - } - }{} - - PopulateStruct(&s) - if n := len(s.Field); n != 1 { - t.Fatalf("Map didn't get populated, struct: %+v", s) - } - - for _, v := range s.Field { - if v == nil { - t.Fatalf("Map value is a nilpointer, struct: %+v", s) - } - if v.NestedField == nil { - t.Fatalf("Pointer field in map element didn't get populated, struct: %+v", s) - } - } -} - -func TestPopulateStructHandlesMapsWithPointerKeys(t *testing.T) { - s := struct { - Field map[*string]struct { - NestedField *int - } - }{} - - PopulateStruct(&s) - if n := len(s.Field); n != 1 { - t.Fatalf("Map didn't get populated, struct: %+v", s) - } - - for k, v := range s.Field { - if k == nil { - t.Fatalf("Map key is a nilpointer, struct: %+v", s) - } - if v.NestedField == nil { - t.Fatalf("Pointer field in map element didn't get populated, struct: %+v", s) - } - } -} - -// this is needed because genyaml uses a custom json unmarshaler that omits empty structs -// even if they are not pointers. If we don't do this, structs that only have string fields -// end up being omitted. -// TODO: Is there a necessity for genyaml to have this custom unmarshaler? -func TestPopulateStructSetsStrings(t *testing.T) { - s := struct { - String string - Field struct { - String string - } - }{} - - PopulateStruct(&s) - if s.String == "" { - t.Errorf("String field didn't get set, struct: %+v", s) - } - if s.Field.String == "" { - t.Errorf("Nested string field didn't get set, struct: %+v", s) - } -} - -func TestPopulateStructBool(t *testing.T) { - s := struct { - Bool bool `json:"bool,omitempty"` - String string `json:"string,omitempty"` - }{} - - PopulateStruct(&s) - if !s.Bool { - t.Fatalf("Bool field didn't get set, struct: %+v", s) - } -} - -func TestPopulateStructHandlesUnexportedFields(_ *testing.T) { - s := struct { - unexported *struct { - justAsUnexported *int - } - }{} - - PopulateStruct(&s) - // This test indicates success by not panicking, so nothing further to check -} diff --git a/pkg/genyaml/testdata/alias_simple_types/alias_simple_types.yaml b/pkg/genyaml/testdata/alias_simple_types/alias_simple_types.yaml deleted file mode 100644 index 976852ea8b23..000000000000 --- a/pkg/genyaml/testdata/alias_simple_types/alias_simple_types.yaml +++ /dev/null @@ -1,2 +0,0 @@ -# AliasField is a specialized field -string: string diff --git a/pkg/genyaml/testdata/alias_simple_types/example_config.go b/pkg/genyaml/testdata/alias_simple_types/example_config.go deleted file mode 100644 index 019fcff0ab04..000000000000 --- a/pkg/genyaml/testdata/alias_simple_types/example_config.go +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package alias_simple_types - -type Alias string - -type SimpleAliases struct { - // AliasField is a specialized field - AliasField Alias `json:"string"` -} diff --git a/pkg/genyaml/testdata/alias_types/alias_types.yaml b/pkg/genyaml/testdata/alias_types/alias_types.yaml deleted file mode 100644 index be9714ae8c1f..000000000000 --- a/pkg/genyaml/testdata/alias_types/alias_types.yaml +++ /dev/null @@ -1,2 +0,0 @@ -# StringField comment -string: string diff --git a/pkg/genyaml/testdata/alias_types/example_config.go b/pkg/genyaml/testdata/alias_types/example_config.go deleted file mode 100644 index 3f7c36ea075e..000000000000 --- a/pkg/genyaml/testdata/alias_types/example_config.go +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package alias_types - -type Alias = AliasedType - -type AliasedType struct { - // StringField comment - StringField string `json:"string"` -} diff --git a/pkg/genyaml/testdata/embedded_structs/embedded_structs.yaml b/pkg/genyaml/testdata/embedded_structs/embedded_structs.yaml deleted file mode 100644 index f2cd16bd3b81..000000000000 --- a/pkg/genyaml/testdata/embedded_structs/embedded_structs.yaml +++ /dev/null @@ -1,14 +0,0 @@ -# Address of building -Address: 123 North Main Street -# Bathroom in building -bathroom: - # Height of Bathroom - height: 200 - # Width of Bathroom - width: 100 -# Bedroom in building -bedroom: - # Height of Bedroom - height: 200 - # Width of Bedroom - width: 100 diff --git a/pkg/genyaml/testdata/embedded_structs/example_config.go b/pkg/genyaml/testdata/embedded_structs/example_config.go deleted file mode 100644 index b08800373254..000000000000 --- a/pkg/genyaml/testdata/embedded_structs/example_config.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package embedded_structs - -type Building struct { - // Address of building - Address string - // Bathroom in building - Bathroom `json:"bathroom"` - // Bedroom in building - Bedroom `json:"bedroom"` -} - -type Bathroom struct { - // Width of Bathroom - Width int `json:"width"` - // Height of Bathroom - Height int `json:"height"` -} - -type Bedroom struct { - // Width of Bedroom - Width int `json:"width"` - // Height of Bedroom - Height int `json:"height"` -} diff --git a/pkg/genyaml/testdata/inject_comments/inject_comments.json b/pkg/genyaml/testdata/inject_comments/inject_comments.json deleted file mode 100644 index f9e33fefe559..000000000000 --- a/pkg/genyaml/testdata/inject_comments/inject_comments.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ExampleStruct": { - "exampleKey": { - "Type": "bool", - "IsObj": false, - "Doc": "Some comment" - } - } -} \ No newline at end of file diff --git a/pkg/genyaml/testdata/inline_structs/example_config.go b/pkg/genyaml/testdata/inline_structs/example_config.go deleted file mode 100644 index b8d7c300fddc..000000000000 --- a/pkg/genyaml/testdata/inline_structs/example_config.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package inline_structs - -type Metadata struct { - // Name is the name of a resource. - Name string `json:"name"` -} - -type Resource struct { - // This comment string disappears due to the inlining. - Metadata `json:",inline"` -} diff --git a/pkg/genyaml/testdata/inline_structs/inline_structs.yaml b/pkg/genyaml/testdata/inline_structs/inline_structs.yaml deleted file mode 100644 index 0a3de248ec87..000000000000 --- a/pkg/genyaml/testdata/inline_structs/inline_structs.yaml +++ /dev/null @@ -1,2 +0,0 @@ -# Name is the name of a resource. -name: test diff --git a/pkg/genyaml/testdata/interface_types/example_config.go b/pkg/genyaml/testdata/interface_types/example_config.go deleted file mode 100644 index 31fbfb95e6c5..000000000000 --- a/pkg/genyaml/testdata/interface_types/example_config.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package interface_types - -type Zoo struct { - // Animals is an array of animals of the zoo - Animals []Animal `json:"animals"` -} - -type Animal interface { - // Sound the animal makes - Sound() -} - -type Cheetah struct { - // Name of cheetah - Name string `json:"name"` -} - -func (c *Cheetah) Sound() { - println("meowww") -} - -type Lion struct { - // Name of lion - Name string `json:"name"` -} - -func (l *Lion) Sound() { - println("roarrr") -} diff --git a/pkg/genyaml/testdata/interface_types/interface_types.yaml b/pkg/genyaml/testdata/interface_types/interface_types.yaml deleted file mode 100644 index 0668c669c310..000000000000 --- a/pkg/genyaml/testdata/interface_types/interface_types.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# Animals is an array of animals of the zoo -animals: - - # Name of lion - name: Leo - - - # Name of cheetah - name: Charles diff --git a/pkg/genyaml/testdata/multiline_comments/example_config.go b/pkg/genyaml/testdata/multiline_comments/example_config.go deleted file mode 100644 index 1300d4cc5ba7..000000000000 --- a/pkg/genyaml/testdata/multiline_comments/example_config.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package multiline_comments - -type Multiline struct { - // StringField1 comment - // second line - // third line - StringField1 string `json:"string1"` - - /* StringField2 comment - second line - third line - */ - StringField2 string `json:"string2"` - - /* StringField3 comment - second line - third line - */ - StringField3 string `json:"string3"` - - // - // - // Paragraph line - // - // - StringField4 string `json:"string4"` - - /* - - Paragraph block - - */ - StringField5 string `json:"string5"` - - /* - Tab Tab TabTab - */ - StringField6 string `json:"string6"` -} diff --git a/pkg/genyaml/testdata/multiline_comments/multiline_comments.yaml b/pkg/genyaml/testdata/multiline_comments/multiline_comments.yaml deleted file mode 100644 index 0777cba760c3..000000000000 --- a/pkg/genyaml/testdata/multiline_comments/multiline_comments.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# StringField1 comment -# second line -# third line -string1: string1 -# StringField2 comment -# second line -# third line -string2: string2 -# StringField3 comment -# second line -# third line -string3: string3 -# Paragraph line -string4: string4 -# Paragraph block -string5: string5 -# Tab Tab TabTab -string6: string6 diff --git a/pkg/genyaml/testdata/multiple_paths/example_config1.go b/pkg/genyaml/testdata/multiple_paths/example_config1.go deleted file mode 100644 index db07d28d13e8..000000000000 --- a/pkg/genyaml/testdata/multiple_paths/example_config1.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package multiple_paths - -type Example1 struct { - // Example1 StringField comment - StringField string `json:"string"` - // Example1 BooleanField comment - BooleanField bool `json:"boolean"` - // Example1 IntegerField comment - IntegerField int `json:"integer"` -} diff --git a/pkg/genyaml/testdata/multiple_paths/example_config2.go b/pkg/genyaml/testdata/multiple_paths/example_config2.go deleted file mode 100644 index 688956c371d8..000000000000 --- a/pkg/genyaml/testdata/multiple_paths/example_config2.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package multiple_paths - -type Example2 struct { - // Example2 StringField comment - StringField string `json:"string"` - // Example2 BooleanField comment - BooleanField bool `json:"boolean"` - // Example2 IntegerField comment - IntegerField int `json:"integer"` -} diff --git a/pkg/genyaml/testdata/multiple_paths/multiple_paths.json b/pkg/genyaml/testdata/multiple_paths/multiple_paths.json deleted file mode 100644 index 169bcbf0667d..000000000000 --- a/pkg/genyaml/testdata/multiple_paths/multiple_paths.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "Example1": { - "boolean": { - "Type": "bool", - "IsObj": false, - "Doc": "Example1 BooleanField comment" - }, - "integer": { - "Type": "int", - "IsObj": false, - "Doc": "Example1 IntegerField comment" - }, - "string": { - "Type": "string", - "IsObj": false, - "Doc": "Example1 StringField comment" - } - }, - "Example2": { - "boolean": { - "Type": "bool", - "IsObj": false, - "Doc": "Example2 BooleanField comment" - }, - "integer": { - "Type": "int", - "IsObj": false, - "Doc": "Example2 IntegerField comment" - }, - "string": { - "Type": "string", - "IsObj": false, - "Doc": "Example2 StringField comment" - } - } -} \ No newline at end of file diff --git a/pkg/genyaml/testdata/nested_structs/example_config.go b/pkg/genyaml/testdata/nested_structs/example_config.go deleted file mode 100644 index 29ad03c23147..000000000000 --- a/pkg/genyaml/testdata/nested_structs/example_config.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package nested_structs - -type Parent struct { - // Name of parent - Name string - // Age of parent - Age int - // Children of parent - Children []Child -} - -type Child struct { - // Name of child - Name string - // Age of child - Age int -} diff --git a/pkg/genyaml/testdata/nested_structs/nested_structs.yaml b/pkg/genyaml/testdata/nested_structs/nested_structs.yaml deleted file mode 100644 index c4da5b9a4184..000000000000 --- a/pkg/genyaml/testdata/nested_structs/nested_structs.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# Age of parent -Age: 35 -# Children of parent -Children: - - # Age of child - Age: 4 - # Name of child - Name: Jimbo - - Age: 5 - Name: Jenny -# Name of parent -Name: Mildred diff --git a/pkg/genyaml/testdata/no_tags/example_config.go b/pkg/genyaml/testdata/no_tags/example_config.go deleted file mode 100644 index 8627302549f1..000000000000 --- a/pkg/genyaml/testdata/no_tags/example_config.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package no_tags - -type Tagless struct { - // StringField comment - StringField string - // BooleanField comment - BooleanField bool - // IntegerField comment - IntegerField int -} diff --git a/pkg/genyaml/testdata/no_tags/no_tags.yaml b/pkg/genyaml/testdata/no_tags/no_tags.yaml deleted file mode 100644 index 551fbb1e6575..000000000000 --- a/pkg/genyaml/testdata/no_tags/no_tags.yaml +++ /dev/null @@ -1,6 +0,0 @@ -# BooleanField comment -BooleanField: true -# IntegerField comment -IntegerField: 1 -# StringField comment -StringField: string diff --git a/pkg/genyaml/testdata/omit_if_empty/example_config.go b/pkg/genyaml/testdata/omit_if_empty/example_config.go deleted file mode 100644 index ac9f48d28cb2..000000000000 --- a/pkg/genyaml/testdata/omit_if_empty/example_config.go +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package omit - -type OmitEmptyStrings struct { - // StringFieldOmitEmpty comment - StringFieldOmitEmpty string `json:"stringomit,omitempty"` - // StringFieldKeepEmpty comment - StringFieldKeepEmpty string `json:"stringkeep"` - // BooleanField comment - BooleanField bool `json:"boolean"` - // IntegerField comment - IntegerField int `json:"integer"` -} diff --git a/pkg/genyaml/testdata/omit_if_empty/omit_if_empty.yaml b/pkg/genyaml/testdata/omit_if_empty/omit_if_empty.yaml deleted file mode 100644 index 872023686218..000000000000 --- a/pkg/genyaml/testdata/omit_if_empty/omit_if_empty.yaml +++ /dev/null @@ -1,6 +0,0 @@ -# BooleanField comment -boolean: true -# IntegerField comment -integer: 1 -# StringFieldKeepEmpty comment -stringkeep: "" diff --git a/pkg/genyaml/testdata/pointer_types/example_config.go b/pkg/genyaml/testdata/pointer_types/example_config.go deleted file mode 100644 index 0b9ddc64c995..000000000000 --- a/pkg/genyaml/testdata/pointer_types/example_config.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package pointer_types - -type Zoo struct { - // Employees is an array of employees of the zoo - Employees []*Employee `json:"employees"` -} - -type Employee struct { - // Name of employee - Name string - // Age of employee - Age int -} diff --git a/pkg/genyaml/testdata/pointer_types/pointer_types.yaml b/pkg/genyaml/testdata/pointer_types/pointer_types.yaml deleted file mode 100644 index 5ebeee56c842..000000000000 --- a/pkg/genyaml/testdata/pointer_types/pointer_types.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# Employees is an array of employees of the zoo -employees: - - # Age of employee - Age: 22 - # Name of employee - Name: Jim - - Age: 21 - Name: Jane diff --git a/pkg/genyaml/testdata/primitive_types/example_config.go b/pkg/genyaml/testdata/primitive_types/example_config.go deleted file mode 100644 index 83b8a058b046..000000000000 --- a/pkg/genyaml/testdata/primitive_types/example_config.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package primitive_types - -type Primitives struct { - // StringField comment - StringField string `json:"string"` - // BooleanField comment - BooleanField bool `json:"boolean"` - // IntegerField comment - IntegerField int `json:"integer"` -} diff --git a/pkg/genyaml/testdata/primitive_types/primitive_types.yaml b/pkg/genyaml/testdata/primitive_types/primitive_types.yaml deleted file mode 100644 index 1078f5301fc3..000000000000 --- a/pkg/genyaml/testdata/primitive_types/primitive_types.yaml +++ /dev/null @@ -1,6 +0,0 @@ -# BooleanField comment -boolean: true -# IntegerField comment -integer: 1 -# StringField comment -string: string diff --git a/pkg/genyaml/testdata/private_members/example_config.go b/pkg/genyaml/testdata/private_members/example_config.go deleted file mode 100644 index 2f54a1c08949..000000000000 --- a/pkg/genyaml/testdata/private_members/example_config.go +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package private_members - -type Person struct { - // Username of person - Username string - // password of person - password string -} - -func NewPerson(username string, password string) *Person { - return &Person{ - Username: username, - password: password, - } -} diff --git a/pkg/genyaml/testdata/private_members/private_members.yaml b/pkg/genyaml/testdata/private_members/private_members.yaml deleted file mode 100644 index c011197fe057..000000000000 --- a/pkg/genyaml/testdata/private_members/private_members.yaml +++ /dev/null @@ -1,2 +0,0 @@ -# Username of person -Username: gamer123 diff --git a/pkg/genyaml/testdata/sequence_items/example_config.go b/pkg/genyaml/testdata/sequence_items/example_config.go deleted file mode 100644 index 64fc5481e520..000000000000 --- a/pkg/genyaml/testdata/sequence_items/example_config.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package sequence_items - -type Recipe struct { - // Ingredients is a list of things required for the recipe. - Ingredients []Ingredient `json:"ingredients"` -} - -type Ingredient struct { - // Name is the ingredient's name. - Name string `json:"name"` - // Amount is how much of this is needed. - Amount int `json:"amount"` -} diff --git a/pkg/genyaml/testdata/sequence_items/sequence_items.yaml b/pkg/genyaml/testdata/sequence_items/sequence_items.yaml deleted file mode 100644 index 8ca459f01105..000000000000 --- a/pkg/genyaml/testdata/sequence_items/sequence_items.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# Ingredients is a list of things required for the recipe. -ingredients: - - # Amount is how much of this is needed. - amount: 1 - # Name is the ingredient's name. - name: potatoes - - amount: 2 - name: eggs diff --git a/pkg/genyaml/testdata/set_path_overwrite/example_config.go b/pkg/genyaml/testdata/set_path_overwrite/example_config.go deleted file mode 100644 index 9c8354a34e07..000000000000 --- a/pkg/genyaml/testdata/set_path_overwrite/example_config.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package set_path_overwrite - -type Example1 struct { - // Example1 StringField comment - StringField string `json:"string"` - // Example1 BooleanField comment - BooleanField bool `json:"boolean"` - // Example1 IntegerField comment - IntegerField int `json:"integer"` -} diff --git a/pkg/genyaml/testdata/set_path_overwrite/set_path_overwrite.json b/pkg/genyaml/testdata/set_path_overwrite/set_path_overwrite.json deleted file mode 100644 index ade46a795168..000000000000 --- a/pkg/genyaml/testdata/set_path_overwrite/set_path_overwrite.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "Example1": { - "boolean": { - "Type": "bool", - "IsObj": false, - "Doc": "Example1 BooleanField comment" - }, - "integer": { - "Type": "int", - "IsObj": false, - "Doc": "Example1 IntegerField comment" - }, - "string": { - "Type": "string", - "IsObj": false, - "Doc": "Example1 StringField comment" - } - } -} \ No newline at end of file diff --git a/pkg/genyaml/testdata/single_path/example_config.go b/pkg/genyaml/testdata/single_path/example_config.go deleted file mode 100644 index 1dc67bfcdbaa..000000000000 --- a/pkg/genyaml/testdata/single_path/example_config.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package single_path - -type Example1 struct { - // Example1 StringField comment - StringField string `json:"string"` - // Example1 BooleanField comment - BooleanField bool `json:"boolean"` - // Example1 IntegerField comment - IntegerField int `json:"integer"` -} diff --git a/pkg/genyaml/testdata/single_path/single_path.json b/pkg/genyaml/testdata/single_path/single_path.json deleted file mode 100644 index ade46a795168..000000000000 --- a/pkg/genyaml/testdata/single_path/single_path.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "Example1": { - "boolean": { - "Type": "bool", - "IsObj": false, - "Doc": "Example1 BooleanField comment" - }, - "integer": { - "Type": "int", - "IsObj": false, - "Doc": "Example1 IntegerField comment" - }, - "string": { - "Type": "string", - "IsObj": false, - "Doc": "Example1 StringField comment" - } - } -} \ No newline at end of file