-
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.
Adds support for Org based override of Watched Folders (#212)
* Adds support for Org based override of Watched Folders Fixes #193 ChangeLog: * Added a cleanup after test functionality. * BUG: Fixing CLI Parser small bug. * Adding CLI test for devel srvinfo * Updating go version to 1.21.3 to address secrutiy vulnerability * Addressing code review comments
- Loading branch information
1 parent
4e7f747
commit 145ffbd
Showing
27 changed files
with
273 additions
and
93 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 |
---|---|---|
|
@@ -11,7 +11,7 @@ jobs: | |
test: | ||
strategy: | ||
matrix: | ||
go: [ {version: 1.21.0, token: 1}, {version: 1.21.0, token: 0}] | ||
go: [ {version: 1.21.3, token: 1}, {version: 1.21.3, token: 0}] | ||
grafana: [ 10.1.4 ] | ||
|
||
env: | ||
|
@@ -40,11 +40,11 @@ jobs: | |
run: | | ||
echo "token IS $TEST_TOKEN_CONFIG" | ||
- name: Calc coverage | ||
if: "${{ matrix.go.version == '1.21.0' && matrix.grafana == '10.1.4' && matrix.go.token == '0' }}" | ||
if: "${{ matrix.go.version == '1.21.3' && matrix.grafana == '10.1.4' && matrix.go.token == '0' }}" | ||
run: | | ||
go test -v -covermode=atomic -coverprofile=coverage.out ./... | ||
- name: Convert coverage.out to coverage.lcov | ||
if: "${{ matrix.go.version == '1.21.0' && matrix.grafana == '10.1.4' && matrix.go.token == '0' }}" | ||
if: "${{ matrix.go.version == '1.21.3' && matrix.grafana == '10.1.4' && matrix.go.token == '0' }}" | ||
uses: jandelgado/[email protected] | ||
- name: Test | ||
if: "${{ matrix.go.token == '1' }}" | ||
|
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,50 @@ | ||
package test | ||
|
||
import ( | ||
"github.com/esnet/gdg/cmd" | ||
"github.com/esnet/gdg/cmd/support" | ||
"github.com/esnet/gdg/internal/service/mocks" | ||
"github.com/stretchr/testify/assert" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestDevelSrvInfo(t *testing.T) { | ||
var execMe = func(mock *mocks.GrafanaService, data []byte, optionMockSvc func() support.RootOption) error { | ||
expected := make(map[string]interface{}) | ||
expected["Database"] = "db" | ||
expected["Commit"] = "commit" | ||
expected["Version"] = "version" | ||
|
||
mock.On("GetServerInfo").Return(expected) | ||
err := cmd.Execute(string(data), []string{"tools", "devel", "srvinfo"}, optionMockSvc()) | ||
return err | ||
} | ||
outStr, closeReader := setupAndExecuteMockingServices(t, execMe) | ||
defer closeReader() | ||
|
||
assert.True(t, strings.Contains(outStr, "Version:")) | ||
assert.True(t, strings.Contains(outStr, "Database:")) | ||
assert.True(t, strings.Contains(outStr, "Commit:")) | ||
} | ||
|
||
func TestDevelSrvCompletion(t *testing.T) { | ||
fn := func(args []string) func(mock *mocks.GrafanaService, data []byte, optionMockSvc func() support.RootOption) error { | ||
return func(mock *mocks.GrafanaService, data []byte, optionMockSvc func() support.RootOption) error { | ||
err := cmd.Execute(string(data), args, optionMockSvc()) | ||
return err | ||
} | ||
} | ||
|
||
outStr, closeReader := setupAndExecuteMockingServices(t, fn([]string{"tools", "devel", "completion", "fish"})) | ||
assert.True(t, strings.Contains(outStr, "fish")) | ||
assert.True(t, strings.Contains(outStr, "__completion_prepare_completions")) | ||
closeReader() | ||
outStr, closeReader = setupAndExecuteMockingServices(t, fn([]string{"tools", "devel", "completion", "bash"})) | ||
assert.True(t, strings.Contains(outStr, "bash")) | ||
assert.True(t, strings.Contains(outStr, "flag_parsing_disabled")) | ||
closeReader() | ||
outStr, closeReader = setupAndExecuteMockingServices(t, fn([]string{"tools", "devel", "completion", "zsh"})) | ||
assert.True(t, strings.Contains(outStr, "shellCompDirectiveKeepOrder")) | ||
closeReader() | ||
} |
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,66 @@ | ||
package test | ||
|
||
import ( | ||
"github.com/esnet/gdg/cmd/support" | ||
"github.com/esnet/gdg/internal/service" | ||
"github.com/esnet/gdg/internal/service/mocks" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
"io" | ||
"os" | ||
"testing" | ||
) | ||
|
||
// setupAndExecuteMockingServices will create a mock for varous required entities allowing to test the CLI flag parsing | ||
// process: function that setups mocks and invokes the Execute command | ||
func setupAndExecuteMockingServices(t *testing.T, process func(mock *mocks.GrafanaService, data []byte, optionMockSvc func() support.RootOption) error) (string, func()) { | ||
testSvc := new(mocks.GrafanaService) | ||
getMockSvc := func() service.GrafanaService { | ||
return testSvc | ||
} | ||
|
||
optionMockSvc := func() support.RootOption { | ||
return func(response *support.RootCommand) { | ||
response.GrafanaSvc = getMockSvc | ||
} | ||
} | ||
|
||
r, w, cleanup := InterceptStdout() | ||
data, err := os.ReadFile("../../config/testing.yml") | ||
assert.Nil(t, err) | ||
|
||
err = process(testSvc, data, optionMockSvc) | ||
assert.Nil(t, err) | ||
defer cleanup() | ||
err = w.Close() | ||
if err != nil { | ||
log.Warn("unable to close write stream") | ||
} | ||
clean := func() { | ||
defer r.Close() | ||
} | ||
out, _ := io.ReadAll(r) | ||
outStr := string(out) | ||
return outStr, clean | ||
|
||
} | ||
|
||
// InterceptStdout is a test helper function that will redirect all stdout in and out to a different file stream. | ||
// It returns the stdout, stderr, and a function to be invoked to close the streams. | ||
func InterceptStdout() (*os.File, *os.File, func()) { | ||
backupStd := os.Stdout | ||
backupErr := os.Stderr | ||
r, w, _ := os.Pipe() | ||
//Restore streams | ||
log.SetOutput(w) | ||
cleanup := func() { | ||
os.Stdout = backupStd | ||
os.Stderr = backupErr | ||
log.SetOutput(os.Stdout) | ||
} | ||
os.Stdout = w | ||
os.Stderr = w | ||
|
||
return r, w, cleanup | ||
|
||
} |
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
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
Oops, something went wrong.