Skip to content

Commit

Permalink
Fix discovered json output flaws (#543)
Browse files Browse the repository at this point in the history
* Add desc[shortroot] and let desc[approot] be full dir

* Provide for two url strings, httpurl and httpsurl
  • Loading branch information
rfay committed Nov 17, 2017
1 parent 97d03df commit a157dd8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
6 changes: 4 additions & 2 deletions cmd/ddev/cmd/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func TestDescribe(t *testing.T) {
assert.True(ok)
assert.EqualValues(raw["status"], "running")
assert.EqualValues(raw["name"], v.Name)
assert.EqualValues(raw["approot"].(string), platform.RenderHomeRootedDir(v.Dir))
assert.EqualValues(raw["shortroot"].(string), platform.RenderHomeRootedDir(v.Dir))
assert.EqualValues(raw["approot"].(string), v.Dir)
cleanup()
}
}
Expand All @@ -102,7 +103,8 @@ func TestDescribeAppFunction(t *testing.T) {
assert.NoError(err)
assert.EqualValues(desc["status"], platform.SiteRunning)
assert.EqualValues(app.GetName(), desc["name"])
assert.EqualValues(platform.RenderHomeRootedDir(v.Dir), desc["approot"].(string))
assert.EqualValues(platform.RenderHomeRootedDir(v.Dir), desc["shortroot"].(string))
assert.EqualValues(v.Dir, desc["approot"].(string))

out, _ := json.Marshal(desc)
assert.Contains(string(out), app.URL())
Expand Down
6 changes: 4 additions & 2 deletions cmd/ddev/cmd/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ func TestDevList(t *testing.T) {
// Check to see that we can find our item
if item["name"] == v.Name {
found = true
assert.Contains(item["url"], app.HostName())
assert.Contains(item["httpurl"], app.HostName())
assert.Contains(item["httpsurl"], app.HostName())
assert.EqualValues(app.GetType(), item["type"])
assert.EqualValues(platform.RenderHomeRootedDir(app.AppRoot()), item["approot"])
assert.EqualValues(platform.RenderHomeRootedDir(app.AppRoot()), item["shortroot"])
assert.EqualValues(app.AppRoot(), item["approot"])
break
}
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/plugins/platform/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,23 @@ func (l *LocalApp) Describe() (map[string]interface{}, error) {
appDesc := make(map[string]interface{})

var https bool
urlString := fmt.Sprintf("http://%s", l.HostName())
var httpsURLString string
httpURLString := fmt.Sprintf("http://%s", l.HostName())
webCon, err := l.FindContainerByType("web")
if err == nil {
https = dockerutil.CheckForHTTPS(webCon)
}
if https {
urlString = fmt.Sprintf("%s\nhttps://%s", urlString, l.HostName())
httpsURLString = fmt.Sprintf("https://%s", l.HostName())
}

appDesc["name"] = l.GetName()
appDesc["status"] = l.SiteStatus()
appDesc["type"] = l.GetType()
appDesc["approot"] = shortRoot
appDesc["url"] = urlString
appDesc["approot"] = l.AppRoot()
appDesc["shortroot"] = shortRoot
appDesc["httpurl"] = httpURLString
appDesc["httpsurl"] = httpsURLString

db, err := l.FindContainerByType("db")
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/platform/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,9 @@ func TestDescribe(t *testing.T) {
assert.NoError(err)
assert.EqualValues(desc["status"], platform.SiteRunning)
assert.EqualValues(app.GetName(), desc["name"])
assert.EqualValues(platform.RenderHomeRootedDir(app.AppRoot()), desc["approot"])
assert.EqualValues(platform.RenderHomeRootedDir(app.AppRoot()), desc["shortroot"])
assert.EqualValues(app.AppRoot(), desc["approot"])

// Now stop it and test behavior.
err = app.Stop()
assert.NoError(err)
Expand Down
8 changes: 6 additions & 2 deletions pkg/plugins/platform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ func RenderAppRow(table *uitable.Table, row map[string]interface{}) {
status = color.CyanString(status)
}

urls := row["httpurl"].(string)
if row["httpsurl"] != "" {
urls = urls + "\n" + row["httpsurl"].(string)
}
table.AddRow(
row["name"],
row["type"],
row["approot"],
row["url"],
row["shortroot"],
urls,
status,
)

Expand Down

0 comments on commit a157dd8

Please sign in to comment.