forked from kool-dev/kool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve info: kool, docker, docker-compose version/paths
- Loading branch information
1 parent
d1fb2ae
commit d007884
Showing
3 changed files
with
80 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 1,73 @@ | ||
package commands | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"kool-dev/kool/core/builder" | ||
"kool-dev/kool/core/environment" | ||
"sort" | ||
"kool-dev/kool/core/shell" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const testingEnv string = ` | ||
KOOL_FILTER_TESTING=1 | ||
KOOL_TESTING=1 | ||
` | ||
|
||
func setup(f *KoolInfo) { | ||
f.envStorage.Set("KOOL_FILTER_TESTING", "1") | ||
f.envStorage.Set("KOOL_TESTING", "1") | ||
} | ||
|
||
func TestInfo(t *testing.T) { | ||
f := &KoolInfo{ | ||
*newDefaultKoolService(), | ||
func fakeKoolInfo() *KoolInfo { | ||
return &KoolInfo{ | ||
*newFakeKoolService(), | ||
environment.NewFakeEnvStorage(), | ||
&builder.FakeCommand{}, | ||
&builder.FakeCommand{}, | ||
} | ||
} | ||
|
||
func TestInfo(t *testing.T) { | ||
f := fakeKoolInfo() | ||
|
||
setup(f) | ||
|
||
output, err := execInfoCommand(NewInfoCmd(f)) | ||
output, err := execInfoCommand(NewInfoCmd(f), f) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expected := strings.Trim(testingEnv, "\n") | ||
|
||
if output != expected { | ||
t.Errorf("Expected '%s', got '%s'", expected, output) | ||
for _, expected := range []string{"KOOL_FILTER_TESTING=1", "KOOL_TESTING=1"} { | ||
if !strings.Contains(output, expected) { | ||
t.Errorf("Expected '%s', got '%s'", expected, output) | ||
} | ||
} | ||
} | ||
|
||
func TestFilteredInfo(t *testing.T) { | ||
f := &KoolInfo{ | ||
*newDefaultKoolService(), | ||
environment.NewFakeEnvStorage(), | ||
} | ||
f := fakeKoolInfo() | ||
|
||
setup(f) | ||
|
||
cmd := NewInfoCmd(f) | ||
cmd.SetArgs([]string{"FILTER"}) | ||
|
||
output, err := execInfoCommand(cmd) | ||
output, err := execInfoCommand(cmd, f) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expected := "KOOL_FILTER_TESTING=1" | ||
|
||
if output != expected { | ||
if !strings.Contains(output, expected) { | ||
t.Errorf("Expected '%s', got '%s'", expected, output) | ||
} | ||
} | ||
|
||
func execInfoCommand(cmd *cobra.Command) (output string, err error) { | ||
b := bytes.NewBufferString("") | ||
cmd.SetOut(b) | ||
|
||
func execInfoCommand(cmd *cobra.Command, f *KoolInfo) (output string, err error) { | ||
if err = cmd.Execute(); err != nil { | ||
return | ||
} | ||
|
||
var out []byte | ||
if out, err = io.ReadAll(b); err != nil { | ||
return | ||
} | ||
|
||
envs := strings.Split(strings.Trim(string(out), "\n"), "\n") | ||
sort.Strings(envs) | ||
|
||
output = strings.Join(envs, "\n") | ||
output = strings.Join(f.shell.(*shell.FakeShell).OutLines, "\n") | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters