summaryrefslogtreecommitdiff
path: root/cmd/rescribe/gbook_test.go
blob: f7df595c41cffa53ce801ea520a2dcc6528c0d26 (plain)
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
// Copyright 2022 Nick White.
// Use of this source code is governed by the GPLv3
// license that can be found in the LICENSE file.

package main

import (
	"testing"
)

func TestGetBookIdFromUrl(t *testing.T) {
	cases := []struct {
		url string
		id  string
	}{
		{"https://books.google.it/books?id=QjQepCuN8JYC", "QjQepCuN8JYC"},
		{"https://www.google.it/books/edition/_/VJbr-Oe2au0C", "VJbr-Oe2au0C"},
	}

	for _, c := range cases {
		t.Run(c.url, func(t *testing.T) {
			id, err := getBookIdFromUrl(c.url)
			if err != nil {
				t.Fatalf("Error running test: %v", err)
			}
			if id != c.id {
				t.Fatalf("Expected %s, got %s", c.id, id)
			}
		})
	}
}

func FuzzGetBookIdFromUrl(f *testing.F) {
	cases := []string {
		"https://books.google.it/books?id=QjQepCuN8JYC",
		"https://www.google.it/books/edition/_/VJbr-Oe2au0C",
	}

	for _, c := range cases {
		f.Add(c)
	}

	f.Fuzz(func(t *testing.T, url string) {
		getBookIdFromUrl(url)
	})
}