|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "log" |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestLogWebPushConfiguration(t *testing.T) { |
| 11 | + cases := []struct { |
| 12 | + name string |
| 13 | + mode string |
| 14 | + pub string |
| 15 | + priv string |
| 16 | + want string |
| 17 | + }{ |
| 18 | + {name: "enabled", mode: "full", pub: "pub", priv: "priv", want: "web push: enabled"}, |
| 19 | + {name: "disabled", mode: "full", pub: "", priv: "", want: "web push: disabled (set SCRUMBOY_VAPID_PUBLIC_KEY and SCRUMBOY_VAPID_PRIVATE_KEY)"}, |
| 20 | + {name: "partial public only", mode: "full", pub: "pub", priv: "", want: "web push: partial config ignored"}, |
| 21 | + {name: "partial private only", mode: "full", pub: "", priv: "priv", want: "web push: partial config ignored"}, |
| 22 | + {name: "trimmed disabled", mode: "full", pub: " ", priv: "\t", want: "web push: disabled (set SCRUMBOY_VAPID_PUBLIC_KEY and SCRUMBOY_VAPID_PRIVATE_KEY)"}, |
| 23 | + {name: "anonymous with keys", mode: "anonymous", pub: "pub", priv: "priv", want: "web push: disabled (anonymous mode)"}, |
| 24 | + } |
| 25 | + |
| 26 | + for _, tc := range cases { |
| 27 | + t.Run(tc.name, func(t *testing.T) { |
| 28 | + var buf bytes.Buffer |
| 29 | + logger := log.New(&buf, "", 0) |
| 30 | + logWebPushConfiguration(logger, tc.mode, tc.pub, tc.priv) |
| 31 | + if got := strings.TrimSpace(buf.String()); got != tc.want { |
| 32 | + t.Fatalf("log output = %q, want %q", got, tc.want) |
| 33 | + } |
| 34 | + }) |
| 35 | + } |
| 36 | +} |
0 commit comments