Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions models/apis/check_collisions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// +build awsinclude

package apis

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

func TestCollidingFolders(t *testing.T) {
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
}
3 changes: 3 additions & 0 deletions models/apis/stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// +build awsinclude

package apis
13 changes: 12 additions & 1 deletion private/model/cli/gen-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func main() {

for svcName := range excludeServices {
if strings.Contains(os.Getenv("SERVICES"), svcName) {
fmt.Printf("Service %s is not supported\n", svcName)
fmt.Fprintf(os.Stderr, "Service %s is not supported\n", svcName)
os.Exit(1)
}
}
Expand All @@ -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.Fprintf(os.Stderr, "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