-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework access to use options, added permissions
- Loading branch information
1 parent
205042b
commit 29c54ea
Showing
10 changed files
with
579 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package proxmox | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/luthermonson/go-proxmox/tests/mocks" | ||
) | ||
|
||
func TestTicket(t *testing.T) { | ||
mocks.On(mockConfig) | ||
defer mocks.Off() | ||
|
||
// todo current mocks are hardcoded with test data, make configurable via mock config | ||
client := mockClient(WithCredentials( | ||
&Credentials{ | ||
Username: "root@pam", | ||
Password: "1234", | ||
})) | ||
|
||
session, err := client.Ticket(client.credentials) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "root@pam", session.Username) | ||
assert.Equal(t, "pve-cluster", session.ClusterName) | ||
} | ||
|
||
func TestPermissions(t *testing.T) { | ||
mocks.On(mockConfig) | ||
defer mocks.Off() | ||
client := mockClient() | ||
|
||
perms, err := client.Permissions(nil) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 8, len(perms)) | ||
assert.Equal(t, 1, perms["/"]["Datastore.Allocate"]) | ||
|
||
// test path option | ||
perms, err = client.Permissions(&PermissionsOptions{ | ||
Path: "path", | ||
}) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 1, perms["path"]["permission"]) | ||
|
||
// test userid | ||
perms, err = client.Permissions(&PermissionsOptions{ | ||
UserID: "userid", | ||
}) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 2, perms["path"]["permission"]) | ||
|
||
// test both path and userid | ||
perms, err = client.Permissions(&PermissionsOptions{ | ||
UserID: "userid", | ||
Path: "path", | ||
}) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 3, perms["path"]["permission"]) | ||
} |
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 |
---|---|---|
@@ -1,32 +1 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/luthermonson/go-proxmox" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLogin(t *testing.T) { | ||
client := ClientFromEnv() | ||
_, err := client.Version() | ||
assert.True(t, proxmox.IsNotAuthorized(err)) | ||
|
||
err = client.Login(td.username, td.password) | ||
assert.Nil(t, err) | ||
|
||
version, err := client.Version() | ||
assert.Nil(t, err) | ||
assert.NotEmpty(t, version.Version) | ||
} | ||
|
||
func TestAPIToken(t *testing.T) { | ||
client := ClientFromEnv() | ||
_, err := client.Version() | ||
assert.True(t, proxmox.IsNotAuthorized(err)) | ||
|
||
client.APIToken(td.tokenID, td.secret) | ||
version, err := client.Version() | ||
assert.Nil(t, err) | ||
assert.NotNil(t, version.Version) | ||
} |
Oops, something went wrong.