-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate --directory/-d flag in favor of os.Stat (#259)
* Deprecate --directory/-d flag in favor of os.Stat * Add tests for grizzly.Pull
- Loading branch information
Showing
11 changed files
with
123 additions
and
19 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
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
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,70 @@ | ||
package grizzly_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/grafana/grizzly/pkg/grafana" | ||
"github.com/grafana/grizzly/pkg/grizzly" | ||
. "github.com/grafana/grizzly/pkg/internal/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPull(t *testing.T) { | ||
os.Setenv("GRAFANA_URL", GetUrl()) | ||
|
||
grizzly.ConfigureProviderRegistry( | ||
[]grizzly.Provider{ | ||
&grafana.Provider{}, | ||
}) | ||
|
||
ticker := PingService(GetUrl()) | ||
defer ticker.Stop() | ||
|
||
opts := grizzly.Opts{ | ||
Targets: []string{ | ||
"Datasource/392IktgGk", | ||
}, | ||
} | ||
|
||
t.Run("with existing file", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
path := filepath.Join(t.TempDir(), filepath.Base(t.Name())) | ||
f, err := os.Create(path) | ||
require.NoError(t, err) | ||
require.NoError(t, f.Close()) | ||
|
||
err = grizzly.Pull(path, opts) | ||
assert.Error(t, err) | ||
assert.ErrorContains(t, err, "pull <resource-path> must be a directory") | ||
}) | ||
|
||
t.Run("with existing folder", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
path := filepath.Join(t.TempDir(), filepath.Base(t.Name())) | ||
err := os.MkdirAll(path, 0755) | ||
require.NoError(t, err) | ||
|
||
err = grizzly.Pull(path, opts) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, numOfFiles(path)) | ||
}) | ||
|
||
t.Run("with non-existing folder", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
path := filepath.Join(t.TempDir(), filepath.Base(t.Name())) | ||
err := grizzly.Pull(path, opts) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, numOfFiles(path)) | ||
}) | ||
} | ||
|
||
func numOfFiles(path string) int { | ||
files, _ := os.ReadDir(path) | ||
return len(files) | ||
} |
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