File: users_test.go

package info (click to toggle)
golang-github-zorkian-go-datadog-api 2.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,612 kB
  • sloc: makefile: 28; sh: 13
file content (69 lines) | stat: -rw-r--r-- 1,850 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package datadog

import (
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestGetUser(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		response, err := ioutil.ReadFile("./tests/fixtures/users_response.json")
		if err != nil {
			t.Fatal(err)
		}
		w.Write(response)
	}))
	defer ts.Close()

	datadogClient := Client{
		baseUrl:    ts.URL,
		HttpClient: http.DefaultClient,
	}

	user, err := datadogClient.GetUser("test@datadoghq.com")
	if err != nil {
		t.Fatal(err)
	}

	expectedHandle := "test@datadoghq.com"
	if handle := user.GetHandle(); handle != expectedHandle {
		t.Fatalf("expect handle %s. Got %s", expectedHandle, handle)
	}

	expectedName := "test user"
	if name := user.GetName(); name != expectedName {
		t.Fatalf("expect name %s. Got %s", expectedName, name)
	}

	expectedEmail := "test@datadoghq.com"
	if email := user.GetEmail(); email != expectedEmail {
		t.Fatalf("expect email %s. Got %s", expectedEmail, email)
	}

	expectedAccessRole := "st"
	if accessRole := user.GetAccessRole(); accessRole != expectedAccessRole {
		t.Fatalf("expect access role %s. Got %s", expectedAccessRole, accessRole)
	}

	expectedIsAdmin := false
	if isAdmin := user.GetIsAdmin(); isAdmin != expectedIsAdmin {
		t.Fatalf("expect is_admin %t. Got %v", expectedIsAdmin, isAdmin)
	}

	expectedIsVerified := true
	if isVerified := user.GetVerified(); isVerified != expectedIsVerified {
		t.Fatalf("expect is_verified %t. Got %v", expectedIsVerified, isVerified)
	}

	expectedIsDisabled := false
	if isVerified := user.GetDisabled(); isVerified != expectedIsDisabled {
		t.Fatalf("expect is_disabled %t. Got %v", expectedIsDisabled, isVerified)
	}

	expectedRole := ""
	if role := user.GetRole(); role != expectedRole {
		t.Fatalf("expect role %s. Got %s", expectedRole, role)
	}
}