MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestPutStdinSetsClientModified

Function TestPutStdinSetsClientModified

cmd/pipe_test.go:116–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

114}
115
116func TestPutStdinSetsClientModified(t *testing.T) {
117 content := "hello from stdin"
118 cmd := testPutCmdWithStdin(strings.NewReader(content))
119
120 start := time.Now().UTC()
121 var uploadedClientModified *dropbox.DBXTime
122 mock := &mockFilesClient{
123 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
124 return nil, &files.GetMetadataAPIError{}
125 },
126 uploadFn: func(arg *files.UploadArg, r io.Reader) (*files.FileMetadata, error) {
127 uploadedClientModified = arg.ClientModified
128 data, err := io.ReadAll(r)
129 if err != nil {
130 t.Fatal(err)
131 }
132 if string(data) != content {
133 t.Fatalf("uploaded content = %q, want %q", string(data), content)
134 }
135 return &files.FileMetadata{}, nil
136 },
137 }
138 stubFilesClient(t, mock)
139
140 err := put(cmd, []string{"-", "/dest.txt"})
141 end := time.Now().UTC()
142 if err != nil {
143 t.Fatalf("put stdin error: %v", err)
144 }
145 if uploadedClientModified == nil {
146 t.Fatal("ClientModified = nil, want stdin spool modified time")
147 }
148
149 got := time.Time(*uploadedClientModified)
150 lower := start.Add(-time.Second)
151 upper := end.Add(time.Second)
152 if got.Before(lower) || got.After(upper) {
153 t.Fatalf("ClientModified = %s, want between %s and %s", got.Format(time.RFC3339Nano), lower.Format(time.RFC3339Nano), upper.Format(time.RFC3339Nano))
154 }
155 if got.Location() != time.UTC {
156 t.Fatalf("ClientModified location = %v, want UTC", got.Location())
157 }
158}
159
160func TestPutStdinIfExistsSkipDoesNotReadStdin(t *testing.T) {
161 cmd := testPutCmdWithStdin(failReadReader{t: t})

Callers

nothing calls this directly

Calls 3

testPutCmdWithStdinFunction · 0.85
stubFilesClientFunction · 0.85
putFunction · 0.85

Tested by

no test coverage detected