summaryrefslogtreecommitdiff
path: root/cmd/rescribe/gbook_test.go
blob: 6cd5a6357684c46395722aec8dc4bbdf81e41dc3 (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
// 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 Test_getBookIdFromUrl(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)
			}
		})
	}
}