Skip to content

Commit

Permalink
fix utils function
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Apr 5, 2024
1 parent c1136da commit da220c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 4 additions & 5 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package utils

import "fmt"

// ISSN as URL
func IssnAsUrl(issn string) *string {
if issn == nil {
return nil
}
return "https://portal.issn.org/resource/ISSN/" + issn
func IssnAsUrl(issn string) string {
return fmt.Sprintf("https://portal.issn.org/resource/ISSN/%s", issn)
}
15 changes: 7 additions & 8 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package utils_test

import (
"commonmeta/utils"
"testing"
"utils"
)

func TestIssnAsUrl(t *testing.T) {
t.Parallel()
type testCase struct {
issn string
want string
input string
want string
}
testCases := []testCase{
{issn: "2146-8427", want: "https://portal.issn.org/resource/ISSN/2146-8427"},
{issn: nil, want: nil},
{input: "2146-8427", want: "https://portal.issn.org/resource/ISSN/2146-8427"},
}
for _, tc := range testCases {
got := utils.IssnAsUrl(tc.issn)
got := utils.IssnAsUrl(tc.input)
if tc.want != got {
t.Errorf("ISSN as URL(%f): want %f, got %f",
tc.issn, tc.want, got)
t.Errorf("ISSN as URL(%v): want %v, got %v",
tc.input, tc.want, got)
}
}
}

0 comments on commit da220c8

Please sign in to comment.