Skip to content

Commit

Permalink
adding tests for domains (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
luthermonson committed Aug 31, 2023
1 parent 521d18f commit a2abbc3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
53 changes: 53 additions & 0 deletions access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,56 @@ func TestACL(t *testing.T) {
assert.Nil(t, err)
assert.Len(t, acls, 1)
}

func TestNewDomain(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()

assert.Nil(t, client.NewDomain("test", "t"))
}

func TestDomain_Update(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()

// no realm name
domain := Domain{
client: client,
}

assert.Error(t, domain.Update())
domain.Realm = "test"
assert.Nil(t, domain.Update())
}

func TestDomain_Delete(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()

// no realm name
domain := Domain{
client: client,
}

assert.Error(t, domain.Delete())
domain.Realm = "test"
assert.Nil(t, domain.Delete())
}

func TestDomain_Sync(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()

// no realm name
domain := Domain{
client: client,
}

assert.Error(t, domain.Sync(DomainSyncOptions{}))
domain.Realm = "test"
assert.Nil(t, domain.Sync(DomainSyncOptions{}))
}
4 changes: 4 additions & 0 deletions proxmox.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ func (c *Client) handleResponse(res *http.Response, v interface{}) error {
return fmt.Errorf("bad request: %s - %s", res.Status, string(body))
}

// if nil passed dont bother to do any unmarshalling
if nil == v {
return nil
}
// account for everything being in a data key
var datakey map[string]json.RawMessage
if err := json.Unmarshal(body, &datakey); err != nil {
Expand Down
19 changes: 19 additions & 0 deletions tests/mocks/pve7x/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,23 @@ func access() {
]
}`)

gock.New(config.C.URI).
Post("^/access/domains").
Reply(200).
JSON(``)

gock.New(config.C.URI).
Put("^/access/domains/test$").
Reply(200).
JSON(``)

gock.New(config.C.URI).
Delete("^/access/domains/test$").
Reply(200).
JSON(``)

gock.New(config.C.URI).
Post("^/access/domains/test$").
Reply(200).
JSON(``)
}

0 comments on commit a2abbc3

Please sign in to comment.