Skip to content

Commit

Permalink
Use tedsuo/rata and jessevdk/go-flags
Browse files Browse the repository at this point in the history
[#117750485]

Signed-off-by: Chris Hendrix <chendrix@pivotal.io>
  • Loading branch information
XenoPhex authored and Chris Hendrix committed Apr 19, 2016
1 parent e50c08e commit 1f263e4
Show file tree
Hide file tree
Showing 54 changed files with 5,613 additions and 786 deletions.
47 changes: 0 additions & 47 deletions app/app.go

This file was deleted.

13 changes: 0 additions & 13 deletions app/app_suite_test.go

This file was deleted.

69 changes: 0 additions & 69 deletions app/app_test.go

This file was deleted.

6 changes: 0 additions & 6 deletions bin/test
Expand Up @@ -29,12 +29,6 @@
echo -e "\n Testing packages..."
CF_HOME=$(pwd)/fixtures ginkgo -r -race -cover -failOnPending -randomizeAllSpecs $@

echo -e "\n Vetting packages for potential issues..."
for file in $(find {app,models,parser,server,test_helpers} \( -name "*.go" -not -iname "*test.go" \))
do
go tool vet -all -shadow=true $file
done

echo -e "\n Running build script to confirm everything compiles..."
bin/build
)
File renamed without changes.
11 changes: 0 additions & 11 deletions fixtures/parser/bad.yml

This file was deleted.

19 changes: 0 additions & 19 deletions fixtures/parser/test.yml

This file was deleted.

76 changes: 74 additions & 2 deletions main.go
@@ -1,7 +1,79 @@
package main

import "github.com/cloudfoundry-incubator/cli-plugin-repo/app"
import (
"fmt"
"os"

"net/http"

"github.com/cloudfoundry-incubator/cli-plugin-repo/models"
"github.com/cloudfoundry-incubator/cli-plugin-repo/parser"
"github.com/cloudfoundry-incubator/cli-plugin-repo/server"
"github.com/jessevdk/go-flags"
"github.com/tedsuo/rata"
)

type CLIPR struct {
Port int `short:"p" long:"port" default:"8080" description:"Port that the plugin repo listens on"`
RepoIndexPath string `short:"f" long:"filepath" default:"repo-index.yml" description:"Path to repo-index file"`
}

func main() {
app.Start()
cmd := &CLIPR{}

parser := flags.NewParser(cmd, flags.Default)
parser.NamespaceDelimiter = "-"

args, err := parser.Parse()
if err != nil {
os.Exit(1)
}

err = cmd.Execute(args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func (cmd *CLIPR) Execute(args []string) error {
logger := os.Stdout //turn this into a logger soon

model := models.NewPlugins(logger)

yamlParser := parser.NewYamlParser("repo-index.yml", logger, model)
handles := server.NewServerHandles(yamlParser, logger)

handlers := map[string]http.Handler{
Index: http.FileServer(http.Dir("ui")),
List: http.HandlerFunc(handles.ListPlugins),
}

router, err := rata.NewRouter(Routes, handlers)

if err != nil {
return err
}

err = http.ListenAndServe(cmd.bindAddr(), router)

return err
}

func (cmd *CLIPR) bindAddr() string {
return fmt.Sprintf(":%d", cmd.Port)
}

const (
Index = "Index"
List = "List"
)

var Routes = rata.Routes([]rata.Route{
{Path: "/", Method: "GET", Name: Index},
{Path: "/js/:file", Method: "GET", Name: Index},
{Path: "/css/:file", Method: "GET", Name: Index},
{Path: "/font/:file", Method: "GET", Name: Index},
{Path: "/images/:file", Method: "GET", Name: Index},
{Path: "/list", Method: "GET", Name: List},
})
18 changes: 3 additions & 15 deletions main_test.go
Expand Up @@ -39,7 +39,7 @@ var _ = Describe("Integration", func() {
BeforeEach(func() {
port = strconv.Itoa(8080 + GinkgoParallelNode())
session, err = gexec.Start(
exec.Command(buildPath, "-p", port, "-n", "127.0.0.1"),
exec.Command(buildPath, "-p", port),
GinkgoWriter,
GinkgoWriter,
)
Expand All @@ -53,25 +53,13 @@ var _ = Describe("Integration", func() {
})

Describe("/", func() {
It("redirects / to /ui/", func() {
client := http.DefaultClient
response, err := client.Get("http://127.0.0.1:" + port)

Expect(err).NotTo(HaveOccurred())
Expect(response).To(BeSuccessful())

Expect(response.Request.URL.Path).To(Equal("/ui/"))
})
})

Describe("/ui", func() {
It("returns HTML we expect", func() {
client := http.DefaultClient
response, err := client.Get("http://127.0.0.1:" + port + "/ui")
response, err := client.Get("http://127.0.0.1:" + port)
Expect(err).NotTo(HaveOccurred())
Expect(response).To(BeSuccessful())

b, err := ioutil.ReadFile("fixtures/ui.html")
b, err := ioutil.ReadFile("fixtures/index.html")
Expect(err).NotTo(HaveOccurred())

defer response.Body.Close()
Expand Down
52 changes: 0 additions & 52 deletions models/fakes/fake_plugin_model.go

This file was deleted.

0 comments on commit 1f263e4

Please sign in to comment.