fix(05): WR-04 default File.IsPublic to true without trapping false

This commit is contained in:
Jakub Zych
2026-09-19 15:34:50 +02:00
parent fb12b2237d
commit c12e6576f6
3 changed files with 99 additions and 16 deletions

View File

@@ -1,6 +1,8 @@
package attach
import (
"reflect"
"strings"
"testing"
"gocloud.dev/blob/memblob"
@@ -12,6 +14,29 @@ func TestFileTableName(t *testing.T) {
}
}
func TestFileIsPublicDefaultsTrue(t *testing.T) {
unset := File{}
if !unset.Public() {
t.Fatal("unset IsPublic must be public")
}
f, ok := reflect.TypeOf(File{}).FieldByName("IsPublic")
if !ok {
t.Fatal("missing IsPublic")
}
tag := f.Tag.Get("gorm")
if !strings.Contains(tag, "default:true") {
t.Fatalf("gorm tag = %q, want default:true", tag)
}
priv := false
if (File{IsPublic: &priv}).Public() {
t.Fatal("explicit false must not be public")
}
pub := true
if !(File{IsPublic: &pub}).Public() {
t.Fatal("explicit true must be public")
}
}
func TestFileSelfRegisters(t *testing.T) {
for _, m := range All() {
switch m.(type) {