package assetserver import ( "reflect" "testing" ) const realHTML = ` test3
Please enter your name below �
` func genMeta(content string) []byte { return []byte("") } func genOptions(runtime bool, bindings bool) *Options { return &Options{ disableRuntimeInjection: runtime, disableIPCInjection: bindings, } } func Test_extractOptions(t *testing.T) { tests := []struct { name string htmldata []byte want *Options wantError bool }{ {"empty", []byte(""), &Options{}, false}, {"bad data", []byte("<"), &Options{}, false}, {"bad options", genMeta("noauto"), genOptions(false, false), false}, {"realhtml", []byte(realHTML), genOptions(true, true), false}, {"noautoinject", genMeta("noautoinject"), genOptions(true, true), false}, {"noautoinjectipc", genMeta("noautoinjectipc"), genOptions(false, true), false}, {"noautoinjectruntime", genMeta("noautoinjectruntime"), genOptions(true, false), false}, {"spaces", genMeta(" noautoinjectruntime "), genOptions(true, false), false}, {"multiple", genMeta("noautoinjectruntime,noautoinjectipc"), genOptions(true, true), false}, {"multiple spaces", genMeta(" noautoinjectruntime, noautoinjectipc "), genOptions(true, true), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := extractOptions(tt.htmldata) if !tt.wantError && err != nil { t.Errorf("did not want error but got it") } if !reflect.DeepEqual(got, tt.want) { t.Errorf("extractOptions() = %v, want %v", got, tt.want) } }) } }