Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion toolkit/types/cpe/marshaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (w *WFN) Scan(src interface{}) (err error) {
}

// Value implements [driver.Valuer].
func (w *WFN) Value() (driver.Value, error) {
func (w WFN) Value() (driver.Value, error) {
switch err := w.Valid(); {
case err == nil:
case errors.Is(err, ErrUnset):
Expand Down
39 changes: 39 additions & 0 deletions toolkit/types/cpe/marshaling_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
package cpe

import (
"database/sql/driver"
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestConvertValue(t *testing.T) {
w := MustUnbind(`cpe:2.3:a:foo\\bar:big\$money:2010:*:*:*:special:ipod_touch:80gb:*`)
var testcases = []struct {
name string
wfn any
want string
wantErr error
}{
{
name: "test value",
wfn: w,
want: `cpe:2.3:a:foo\\bar:big\$money:2010:*:*:*:special:ipod_touch:80gb:*`,
wantErr: nil,
},
{
name: "test pointer",
wfn: &w,
want: `cpe:2.3:a:foo\\bar:big\$money:2010:*:*:*:special:ipod_touch:80gb:*`,
wantErr: nil,
},
}
dpc := driver.DefaultParameterConverter
for _, tt := range testcases {
t.Run(tt.name, func(t *testing.T) {
val, err := dpc.ConvertValue(tt.wfn)
if err != tt.wantErr {
t.Fatal(err)
}
v := val.(string)
if v != tt.want {
t.Fatalf("wanted %q but got %q", tt.want, v)
}
fmt.Println()
})
}
}

func TestMarshal(t *testing.T) {
t.Parallel()
var names = []string{
Expand Down
Loading