Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ToSlice #76

Merged
merged 1 commit into from
May 23, 2021
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.44
0.0.45
2 changes: 1 addition & 1 deletion commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var listCmd = &cobra.Command{
} else {
projects = project.FindAll(rootDir)
}
out, _ := json.MarshalIndent(projects.ToSlice(), "", "\t")
out, _ := json.MarshalIndent(projects.ToSlice(noDependency), "", "\t")
fmt.Println(string(out))
},
}
Expand Down
4 changes: 2 additions & 2 deletions project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,14 @@ func (p *Project) runBuild(version string) error {
return p.run(p.BuildScript, p.env(setVersion(version)))
}

func (projs Projects) ToSlice() []map[string]interface{} {
func (projs Projects) ToSlice(noDep bool) []map[string]interface{} {
out := make([]map[string]interface{}, 0)
for _, p := range projs {
addition := map[string]interface{}{
"directory": p.BaseDir,
"environment": p.env(generateVersion()),
"name": p.Name,
"update": *p.updated,
"update": p.WasUpdated(noDep),
"version": p.Version(),
}
if len(p.DependsOn) != 0 {
Expand Down
11 changes: 11 additions & 0 deletions project/project_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package project

import (
"encoding/json"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -115,6 +116,16 @@ func TestRun(t *testing.T) {
}
}

func TestToSlice(t *testing.T) {
expected := "[{\"directory\":\"\",\"environment\":{\"GALLY_PROJECT_NAME\":\"hello\",\"GALLY_PROJECT_ROOT\":\"\",\"GALLY_PROJECT_TAG\":\"hello@unknown\",\"GALLY_PROJECT_VERSION\":\"unknown\",\"GALLY_PROJECT_WORKDIR\":\"\",\"GALLY_ROOT\":\"\",\"GALLY_TAG\":\"hello@unknown\"},\"name\":\"hello\",\"update\":false,\"version\":\"unknown\"}]"
p := Projects{"hello": &Project{Name: "hello"}}
j, _ := json.Marshal(p.ToSlice(true))
if string(j) != expected {
t.Errorf("output must be equal to %q but is equal to %q", expected, string(j))
t.FailNow()
}
}

func TestRunBuild(t *testing.T) {
c := Project{BuildScript: "echo go building $GALLY_PROJECT_VERSION!"}
out := captureOutput(func() {
Expand Down