Skip to content

Commit 9ebaeda

Browse files
committed
test(live): cover consumer other contacts
1 parent c1c22c8 commit 9ebaeda

3 files changed

Lines changed: 145 additions & 4 deletions

File tree

scripts/live-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Skip keys (base):
3232
gmail-attachments, gmail-track, gmail-watch, chat, drive, docs, sheets, slides,
3333
photos-picker,
3434
calendar, calendar-enterprise, calendar-respond, calendar-team, calendar-users,
35-
tasks, contacts, people, groups, keep, classroom
35+
tasks, contacts, contacts-directory, contacts-other, people, groups, keep, classroom
3636
3737
Env:
3838
GOG_LIVE_EMAIL_TEST=steipete+gogtest@gmail.com

scripts/live-tests/contacts.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
set -euo pipefail
44

5+
run_contacts_other_tests() {
6+
if skip "contacts-other"; then
7+
echo "==> contacts other (skipped)"
8+
return 0
9+
fi
10+
11+
local other_json other_query
12+
echo "==> contacts other list"
13+
other_json=$(gog contacts other list --json --max 1)
14+
other_query=$(extract_field "$other_json" email)
15+
if [ -z "$other_query" ]; then
16+
other_query="gogcli-smoke-$TS@example.com"
17+
fi
18+
run_required "contacts-other" "contacts other search" \
19+
gog contacts other search "$other_query" --json --max 1 >/dev/null
20+
}
21+
522
run_contacts_tests() {
623
if skip "contacts"; then
724
echo "==> contacts (skipped)"
@@ -26,11 +43,10 @@ run_contacts_tests() {
2643

2744
if is_consumer_account "$ACCOUNT"; then
2845
echo "==> contacts directory (skipped; Workspace only)"
29-
echo "==> contacts other (skipped; Workspace only)"
3046
else
3147
run_optional "contacts-directory" "contacts directory list" gog contacts directory list --json --max 1 >/dev/null
3248
run_optional "contacts-directory" "contacts directory search" gog contacts directory search "gogcli" --json --max 1 >/dev/null
33-
run_optional "contacts-other" "contacts other list" gog contacts other list --json --max 1 >/dev/null
34-
run_optional "contacts-other" "contacts other search" gog contacts other search "gogcli" --json --max 1 >/dev/null
3549
fi
50+
51+
run_contacts_other_tests
3652
}

scripts/live_contacts_test.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package main
2+
3+
import (
4+
"os/exec"
5+
"path/filepath"
6+
"runtime"
7+
"strings"
8+
"testing"
9+
)
10+
11+
func TestContactsLiveOtherContactsRunsForConsumerAccounts(t *testing.T) {
12+
if runtime.GOOS == "windows" {
13+
t.Skip("bash live-test harness is not supported on Windows")
14+
}
15+
16+
root, err := filepath.Abs("..")
17+
if err != nil {
18+
t.Fatalf("resolve repository root: %v", err)
19+
}
20+
21+
tests := []struct {
22+
name string
23+
otherJSON string
24+
wantQuery string
25+
}{
26+
{
27+
name: "existing other contact",
28+
otherJSON: `{"contacts":[{"email":"friend@example.com"}]}`,
29+
wantQuery: "friend@example.com",
30+
},
31+
{
32+
name: "empty other contacts",
33+
otherJSON: `{"contacts":[]}`,
34+
wantQuery: "gogcli-smoke-20260613000000@example.com",
35+
},
36+
}
37+
38+
for _, tt := range tests {
39+
t.Run(tt.name, func(t *testing.T) {
40+
script := `
41+
set -euo pipefail
42+
ROOT_DIR="$1"
43+
OTHER_JSON="$2"
44+
PY=python3
45+
SKIP=""
46+
TS=20260613000000
47+
LIVE_TMP=$(mktemp -d)
48+
TRACE_FILE="$LIVE_TMP/trace"
49+
trap 'rm -rf "$LIVE_TMP"' EXIT
50+
source "$ROOT_DIR/scripts/live-tests/common.sh"
51+
source "$ROOT_DIR/scripts/live-tests/contacts.sh"
52+
gog() {
53+
printf '%s\n' "$*" >>"$TRACE_FILE"
54+
case "$*" in
55+
"contacts other list"*)
56+
printf '%s\n' "$OTHER_JSON"
57+
;;
58+
"contacts other search"*)
59+
printf '{"contacts":[]}\n'
60+
;;
61+
*)
62+
return 1
63+
;;
64+
esac
65+
}
66+
run_contacts_other_tests
67+
cat "$TRACE_FILE"
68+
`
69+
70+
output, err := exec.CommandContext(t.Context(), "bash", "-c", script, "bash", root, tt.otherJSON).CombinedOutput()
71+
if err != nil {
72+
t.Fatalf("run contacts live-test path: %v\n%s", err, output)
73+
}
74+
75+
text := string(output)
76+
if !strings.Contains(text, "contacts other list --json --max 1") {
77+
t.Fatalf("output missing other contacts list:\n%s", text)
78+
}
79+
80+
if !strings.Contains(text, "contacts other search "+tt.wantQuery+" --json --max 1") {
81+
t.Fatalf("output missing expected other contacts search:\n%s", text)
82+
}
83+
})
84+
}
85+
}
86+
87+
func TestContactsLiveOtherContactsSkipAvoidsAPI(t *testing.T) {
88+
if runtime.GOOS == "windows" {
89+
t.Skip("bash live-test harness is not supported on Windows")
90+
}
91+
92+
root, err := filepath.Abs("..")
93+
if err != nil {
94+
t.Fatalf("resolve repository root: %v", err)
95+
}
96+
97+
script := `
98+
set -euo pipefail
99+
ROOT_DIR="$1"
100+
PY=python3
101+
SKIP="contacts-other"
102+
TS=20260613000000
103+
source "$ROOT_DIR/scripts/live-tests/common.sh"
104+
source "$ROOT_DIR/scripts/live-tests/contacts.sh"
105+
gog() {
106+
echo "unexpected API call" >&2
107+
return 1
108+
}
109+
run_contacts_other_tests
110+
`
111+
112+
output, err := exec.CommandContext(t.Context(), "bash", "-c", script, "bash", root).CombinedOutput()
113+
if err != nil {
114+
t.Fatalf("run contacts live-test skip path: %v\n%s", err, output)
115+
}
116+
117+
text := string(output)
118+
if !strings.Contains(text, "contacts other (skipped)") {
119+
t.Fatalf("output missing other contacts skip:\n%s", text)
120+
}
121+
122+
if strings.Contains(text, "unexpected API call") {
123+
t.Fatalf("skip path invoked the API:\n%s", text)
124+
}
125+
}

0 commit comments

Comments
 (0)