package main_test import ( "fmt" "os" "testing" "github.com/google/go-cmp/cmp" ) func TestMain(t *testing.T) { expected := `// Code generated by protoc-gen-go-value-scan. DO NOT EDIT. package foov1 import ( "database/sql/driver" "fmt" protojson "google.golang.org/protobuf/encoding/protojson" ) func (x Foo) Value() (driver.Value, error) { f := &x opts := protojson.MarshalOptions{} opts.UseProtoNames = false opts.EmitUnpopulated = true return opts.Marshal(f) } func (x *Foo) Scan(value interface{}) error { switch v := value.(type) { case []byte: return protojson.Unmarshal(v, x) case string: return protojson.Unmarshal([]byte(v), x) default: return fmt.Errorf("type assertion failed") } } ` // Read generated file. f, err := os.ReadFile("go/foo/v1/foo.value_scan.pb.go") if err != nil { t.Errorf("could not read generated file: %s", err.Error()) t.FailNow() } // Compare. // require.Equal(expected, string(f)) if diff := cmp.Diff(expected, string(f)); diff != "" { t.Errorf( fmt.Sprintf( "Not equal:\n Delta: %s\n", diff, ), ) t.FailNow() } }