github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/commands_loader/commands_loader_test.go (about)

     1  package commands_loader_test
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"strings"
     8  
     9  	"github.com/cloudfoundry/cli/cf/command_registry"
    10  	"github.com/cloudfoundry/cli/commands_loader"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("CommandsLoader", func() {
    16  	It("references all command packages so all commands can be registered in command_registry", func() {
    17  
    18  		commands_loader.Load()
    19  
    20  		count := walkDirAndCountCommand("../cf/commands")
    21  		count = count
    22  		Ω(command_registry.Commands.TotalCommands()).To(Equal(count))
    23  	})
    24  })
    25  
    26  func walkDirAndCountCommand(path string) int {
    27  	cmdCount := 0
    28  
    29  	filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
    30  		if err != nil {
    31  			fmt.Println("Error walking commands directories:", err)
    32  			return err
    33  		}
    34  
    35  		if !info.IsDir() {
    36  			if strings.HasSuffix(info.Name(), ".go") && !strings.HasSuffix(info.Name(), "_test.go") {
    37  				cmdCount += 1
    38  			}
    39  		}
    40  		return nil
    41  	})
    42  
    43  	return cmdCount
    44  }