-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_update_test.go
More file actions
74 lines (64 loc) · 1.79 KB
/
source_update_test.go
File metadata and controls
74 lines (64 loc) · 1.79 KB
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
70
71
72
73
74
package unstructured
import (
"errors"
"net/http"
"strconv"
"testing"
"time"
)
func TestUpdateSource(t *testing.T) {
t.Parallel()
client, mux := testclient(t)
id := "a15d4161-77a0-4e08-b65e-86f398ce15ad"
mux.UpdateSource = func(w http.ResponseWriter, r *http.Request) {
if val := r.PathValue("id"); val != id {
http.Error(w, "source ID "+val+" not found", http.StatusNotFound)
return
}
response := []byte(`{` +
` "config": {` +
` "client_id": "foo",` +
` "tenant": "foo",` +
` "authority_url": "foo",` +
` "user_pname": "foo",` +
` "client_cred": "foo",` +
` "recursive": false,` +
` "path": "foo"` +
` },` +
` "created_at": "2023-09-15T01:06:53.146Z",` +
` "id": "a15d4161-77a0-4e08-b65e-86f398ce15ad",` +
` "name": "test_source_name",` +
` "type": "onedrive"` +
`}`)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
w.WriteHeader(http.StatusOK)
w.Write(response)
}
source, err := client.UpdateSource(testContext(t), UpdateSourceRequest{
ID: id,
Config: &OneDriveConnectorConfig{
ClientID: "foo",
Tenant: "foo",
AuthorityURL: "foo",
UserPName: "foo",
ClientCred: "foo",
Recursive: Bool(false),
Path: String("foo"),
},
})
if err != nil {
t.Fatalf("failed to update source: %v", err)
}
if err := errors.Join(
eq("updated_source.id", source.ID, id),
eq("updated_source.name", source.Name, "test_source_name"),
equal("updated_source.created_at", source.CreatedAt, time.Date(2023, 9, 15, 1, 6, 53, 146000000, time.UTC)),
); err != nil {
t.Error(err)
}
cfg, ok := source.Config.(*OneDriveConnectorConfig)
if !ok {
t.Errorf("expected source config to be %T, got %T", cfg, source.Config)
}
}