Skip to content

Commit

Permalink
Adding validation to ensure collision of api defintions do not occur
Browse files Browse the repository at this point in the history
  • Loading branch information
xibz committed Jan 26, 2018
1 parent 3ef3d9b commit 7b2c2f3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LINTIGNOREPKGCOMMENT='service/[^/]+/doc_custom.go:.+package comment should be of
UNIT_TEST_TAGS="example codegen awsinclude"

SDK_WITH_VENDOR_PKGS=$(shell go list -tags ${UNIT_TEST_TAGS} ./... | grep -v "/vendor/src")
SDK_ONLY_PKGS=$(shell go list ./... | grep -v "/vendor/")
SDK_ONLY_PKGS=$(shell go list ./... | grep -v "/vendor/" | grep -v "/models/apis/")
SDK_UNIT_TEST_ONLY_PKGS=$(shell go list -tags ${UNIT_TEST_TAGS} ./... | grep -v "/vendor/")
SDK_GO_1_4=$(shell go version | grep "go1.4")
SDK_GO_1_5=$(shell go version | grep "go1.5")
Expand Down
34 changes: 34 additions & 0 deletions models/apis/check_collisions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package apis

import (
"os/exec"
"strings"
"testing"
)

func TestCollidingFolders(t *testing.T) {
t.Log("WEEEEEEEEEEEEEEEEEEEEEEEEE")
m := map[string]struct{}{}
folders, err := getFolderNames()
if err != nil {
t.Error(err)
}

for _, folder := range folders {
lcName := strings.ToLower(folder)
if _, ok := m[lcName]; ok {
t.Errorf("folder %q collision detected", folder)
}
m[lcName] = struct{}{}
}
}

func getFolderNames() ([]string, error) {
cmd := exec.Command("git", "ls-tree", "-d", "--name-only", "HEAD")
output, err := cmd.Output()
if err != nil {
return nil, err
}

return strings.Split(string(output), "\n"), nil
}
11 changes: 11 additions & 0 deletions private/model/cli/gen-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func main() {

// Remove old API versions from list
m := map[string]bool{}
// caches paths to ensure we are not overriding previously generated
// code.
servicePaths := map[string]struct{}{}

for i := range files {
idx := len(files) - 1 - i
parts := strings.Split(files[idx], string(filepath.Separator))
Expand Down Expand Up @@ -167,6 +171,13 @@ func main() {
continue
}

if _, ok := servicePaths[genInfo.PackageDir]; ok {
fmt.Printf("Path %q has already been generated", genInfo.PackageDir)
os.Exit(1)
}

servicePaths[genInfo.PackageDir] = struct{}{}

wg.Add(1)
go func(g *generateInfo, filename string) {
defer wg.Done()
Expand Down

0 comments on commit 7b2c2f3

Please sign in to comment.