-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4ee4c3
commit cd0b11e
Showing
24 changed files
with
2,935 additions
and
43 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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/esnet/gdg/cmd/support" | ||
"github.com/esnet/gdg/internal/service" | ||
"github.com/esnet/gdg/internal/service/mocks" | ||
"github.com/esnet/gdg/internal/version" | ||
"github.com/stretchr/testify/assert" | ||
"io" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func interceptStdout() (*os.File, *os.File, func()) { | ||
backupStd := os.Stdout | ||
backupErr := os.Stderr | ||
r, w, _ := os.Pipe() | ||
//Restore streams | ||
cleanup := func() { | ||
os.Stdout = backupStd | ||
os.Stderr = backupErr | ||
} | ||
os.Stdout = w | ||
os.Stderr = w | ||
|
||
return r, w, cleanup | ||
|
||
} | ||
|
||
func TestVersionCommand(t *testing.T) { | ||
testSvc := new(mocks.GrafanaService) | ||
getMockSvc := func() service.GrafanaService { | ||
return testSvc | ||
} | ||
|
||
optionMockSvc := func() support.RootOption { | ||
return func(response *support.RootCommand) { | ||
response.GrafanaSvc = getMockSvc | ||
} | ||
} | ||
path, _ := os.Getwd() | ||
fmt.Println(path) | ||
r, w, cleanup := interceptStdout() | ||
data, err := os.ReadFile("../config/testing.yml") | ||
assert.Nil(t, err) | ||
|
||
err = Execute(string(data), []string{"version"}, optionMockSvc()) | ||
assert.Nil(t, err) | ||
defer cleanup() | ||
w.Close() | ||
out, _ := io.ReadAll(r) | ||
outStr := string(out) | ||
assert.True(t, strings.Contains(outStr, "Build Date:")) | ||
assert.True(t, strings.Contains(outStr, "Git Commit:")) | ||
assert.True(t, strings.Contains(outStr, "Version:")) | ||
assert.True(t, strings.Contains(outStr, version.Version)) | ||
assert.True(t, strings.Contains(outStr, "Date:")) | ||
assert.True(t, strings.Contains(outStr, "Go Version:")) | ||
assert.True(t, strings.Contains(outStr, "OS / Arch:")) | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.