-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added testing unit for command list from device groups
- Loading branch information
Showing
4 changed files
with
76 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"count": 1, | ||
"total_pages": 1, | ||
"schema_version": 3, | ||
"links": { | ||
"previous": null, | ||
"next": null | ||
}, | ||
"results": [ | ||
{ | ||
"id": 2257, | ||
"name": "Mob1le", | ||
"user_agent": "Mobile|Android|iPhone" | ||
} | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
pkg/cmd/device_groups/list/.fixtures/resp_without_items.json
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,10 @@ | ||
{ | ||
"count": 0, | ||
"total_pages": 1, | ||
"schema_version": 3, | ||
"links": { | ||
"previous": null, | ||
"next": null | ||
}, | ||
"results": [] | ||
} |
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,47 @@ | ||
package list | ||
|
||
import ( | ||
"github.com/aziontech/azion-cli/pkg/httpmock" | ||
"github.com/aziontech/azion-cli/pkg/testutils" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestList(t *testing.T) { | ||
t.Run("command list with successes", func(t *testing.T) { | ||
mock := &httpmock.Registry{} | ||
|
||
mock.Register( | ||
httpmock.REST("GET", "edge_applications/1673635846/device_groups"), | ||
httpmock.JSONFromFile(".fixtures/resp.json"), | ||
) | ||
|
||
f, stdout, _ := testutils.NewFactory(mock) | ||
cmd := NewCmd(f) | ||
|
||
cmd.SetArgs([]string{"-a", "1673635846"}) | ||
|
||
_, err := cmd.ExecuteC() | ||
require.NoError(t, err) | ||
assert.Equal(t, "ID NAME \n2257 Mob1le \n", stdout.String()) | ||
}) | ||
|
||
t.Run("command list response without items", func(t *testing.T) { | ||
mock := &httpmock.Registry{} | ||
|
||
mock.Register( | ||
httpmock.REST("GET", "edge_applications/1673635847/device_groups"), | ||
httpmock.JSONFromFile(".fixtures/resp_without_items.json"), | ||
) | ||
|
||
f, stdout, _ := testutils.NewFactory(mock) | ||
cmd := NewCmd(f) | ||
|
||
cmd.SetArgs([]string{"-a", "1673635847"}) | ||
|
||
_, err := cmd.ExecuteC() | ||
require.NoError(t, err) | ||
assert.Equal(t, "ID NAME \n", stdout.String()) | ||
}) | ||
} |