Skip to content

Commit

Permalink
🐛 Add validation for the main.go file present in root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
prafull01 committed Oct 16, 2020
1 parent c993a2a commit d21d892
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/model/resource/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package resource

import (
"fmt"
"os"
"path"
"regexp"
"strings"
Expand All @@ -33,6 +34,8 @@ const (
groupRequired = "group cannot be empty"
versionRequired = "version cannot be empty"
kindRequired = "kind cannot be empty"
// DefaultMainPath is default file path of main.go
DefaultMainPath = "main.go"
)

var (
Expand Down Expand Up @@ -133,6 +136,11 @@ func (opts *Options) ValidateV2() error {
return fmt.Errorf("invalid Kind: %#v", validationErrors)
}

// check if main.go is present in the root directory
if _, err := os.Stat(DefaultMainPath); os.IsNotExist(err) {
return fmt.Errorf("%s file should present in the root directory", DefaultMainPath)
}

// TODO: validate plural strings if provided

return nil
Expand Down Expand Up @@ -183,6 +191,11 @@ func (opts *Options) Validate() error {
return fmt.Errorf("invalid Kind: %#v", validationErrors)
}

// check if main.go is present in the root directory
if _, err := os.Stat(DefaultMainPath); os.IsNotExist(err) {
return fmt.Errorf("%s file should present in the root directory", DefaultMainPath)
}

// TODO: validate plural strings if provided

return nil
Expand Down

0 comments on commit d21d892

Please sign in to comment.