diff options
author | Nick White <git@njw.name> | 2022-03-21 16:26:55 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2022-03-21 16:26:55 +0000 |
commit | 63b6942f6b2649c70c30cdced6c033ff2607724f (patch) | |
tree | 7f8ff3dc741a3977e5f48c7680a0f2e749c28c94 /cmd/rescribe/gbook_test.go | |
parent | ea6f43514ea470fac399a8155155babfbabec118 (diff) |
rescribe: move getBookIdFromUrl() to gbook.go, and add tests for it
Diffstat (limited to 'cmd/rescribe/gbook_test.go')
-rw-r--r-- | cmd/rescribe/gbook_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cmd/rescribe/gbook_test.go b/cmd/rescribe/gbook_test.go new file mode 100644 index 0000000..6cd5a63 --- /dev/null +++ b/cmd/rescribe/gbook_test.go @@ -0,0 +1,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) + } + }) + } +} |