github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/fs/dump_test.go (about) 1 package fs 2 3 import ( 4 "testing" 5 6 "github.com/spf13/pflag" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 // Check it satisfies the interface 11 var _ pflag.Value = (*DumpFlags)(nil) 12 13 func TestDumpFlagsString(t *testing.T) { 14 assert.Equal(t, "", DumpFlags(0).String()) 15 assert.Equal(t, "headers", (DumpHeaders).String()) 16 assert.Equal(t, "headers,bodies", (DumpHeaders | DumpBodies).String()) 17 assert.Equal(t, "headers,bodies,requests,responses,auth,filters", (DumpHeaders | DumpBodies | DumpRequests | DumpResponses | DumpAuth | DumpFilters).String()) 18 assert.Equal(t, "headers,Unknown-0x8000", (DumpHeaders | DumpFlags(0x8000)).String()) 19 } 20 21 func TestDumpFlagsSet(t *testing.T) { 22 for _, test := range []struct { 23 in string 24 want DumpFlags 25 wantErr string 26 }{ 27 {"", DumpFlags(0), ""}, 28 {"bodies", DumpBodies, ""}, 29 {"bodies,headers,auth", DumpBodies | DumpHeaders | DumpAuth, ""}, 30 {"bodies,headers,auth", DumpBodies | DumpHeaders | DumpAuth, ""}, 31 {"headers,bodies,requests,responses,auth,filters", DumpHeaders | DumpBodies | DumpRequests | DumpResponses | DumpAuth | DumpFilters, ""}, 32 {"headers,bodies,unknown,auth", 0, "Unknown dump flag \"unknown\""}, 33 } { 34 f := DumpFlags(-1) 35 initial := f 36 err := f.Set(test.in) 37 if err != nil { 38 if test.wantErr == "" { 39 t.Errorf("Got an error when not expecting one on %q: %v", test.in, err) 40 } else { 41 assert.Contains(t, err.Error(), test.wantErr) 42 } 43 assert.Equal(t, initial, f, test.want) 44 } else { 45 if test.wantErr != "" { 46 t.Errorf("Got no error when expecting one on %q", test.in) 47 } else { 48 assert.Equal(t, test.want, f) 49 } 50 } 51 52 } 53 } 54 55 func TestDumpFlagsType(t *testing.T) { 56 f := DumpFlags(0) 57 assert.Equal(t, "DumpFlags", f.Type()) 58 }