@@ -100,10 +100,13 @@ describe("BaiduFileSystem", () => {
100100 expect ( String ( ( requestSpy . mock . calls [ 2 ] [ 1 ] as RequestInit ) . body ) ) . toContain ( "rtype=0" ) ;
101101 } ) ;
102102
103- it ( "writer should surface Baidu createOnly rejection as conflict" , async ( ) => {
103+ it ( "writer should surface Baidu createOnly exists rejection as conflict" , async ( ) => {
104104 const fs = new BaiduFileSystem ( "/apps" , "token" ) ;
105105 vi . spyOn ( fs , "list" ) . mockResolvedValue ( [ ] ) ;
106- vi . spyOn ( fs , "request" ) . mockResolvedValueOnce ( { errno : - 8 , errmsg : "file exists" } ) ;
106+ vi . spyOn ( fs , "request" ) . mockResolvedValueOnce ( {
107+ errno : - 8 ,
108+ errmsg : "file exists" ,
109+ } ) ;
107110
108111 const writer = await fs . create ( "test.txt" , { createOnly : true } ) ;
109112
@@ -113,6 +116,38 @@ describe("BaiduFileSystem", () => {
113116 } ) ;
114117 } ) ;
115118
119+ it ( "writer should surface Baidu createOnly duplicate name rejection as conflict" , async ( ) => {
120+ const fs = new BaiduFileSystem ( "/apps" , "token" ) ;
121+ vi . spyOn ( fs , "list" ) . mockResolvedValue ( [ ] ) ;
122+ vi . spyOn ( fs , "request" ) . mockResolvedValueOnce ( {
123+ errno : 31061 ,
124+ errmsg : "duplicate name" ,
125+ } ) ;
126+
127+ const writer = await fs . create ( "test.txt" , { createOnly : true } ) ;
128+
129+ await expect ( writer . write ( "content" ) ) . rejects . toMatchObject ( {
130+ provider : "baidu" ,
131+ conflict : true ,
132+ code : "31061" ,
133+ } ) ;
134+ } ) ;
135+
136+ it ( "writer should not classify non-exists Baidu createOnly errno as conflict" , async ( ) => {
137+ const fs = new BaiduFileSystem ( "/apps" , "token" ) ;
138+ vi . spyOn ( fs , "list" ) . mockResolvedValue ( [ ] ) ;
139+ vi . spyOn ( fs , "request" ) . mockResolvedValueOnce ( {
140+ errno : 111 ,
141+ errmsg : "quota exceeded" ,
142+ } ) ;
143+
144+ const writer = await fs . create ( "test.txt" , { createOnly : true } ) ;
145+
146+ await expect ( writer . write ( "content" ) ) . rejects . not . toMatchObject ( {
147+ conflict : true ,
148+ } ) ;
149+ } ) ;
150+
116151 it ( "writer should reject expectedDigest when remote digest changed" , async ( ) => {
117152 const fs = new BaiduFileSystem ( "/apps" , "token" ) ;
118153 vi . spyOn ( fs , "list" ) . mockResolvedValue ( [
0 commit comments