@@ -73,6 +73,83 @@ func TestSaveState(t *testing.T) {
7373 })
7474}
7575
76+ // go test -timeout 30s ./client -count 1 -run ^TestDeleteState$
77+ func TestDeleteState (t * testing.T ) {
78+ ctx := context .Background ()
79+ data := "test"
80+ store := "test"
81+ key := "key1"
82+
83+ t .Run ("delete not exist data" , func (t * testing.T ) {
84+ err := testClient .DeleteState (ctx , store , key )
85+ assert .Nil (t , err )
86+ })
87+ t .Run ("delete not exist data with etag and meta" , func (t * testing.T ) {
88+ err := testClient .DeleteStateWithETag (ctx , store , key , "100" , map [string ]string {"meta1" : "value1" },
89+ & StateOptions {Concurrency : StateConcurrencyFirstWrite , Consistency : StateConsistencyEventual })
90+ assert .Nil (t , err )
91+ })
92+
93+ t .Run ("save data" , func (t * testing.T ) {
94+ err := testClient .SaveState (ctx , store , key , []byte (data ))
95+ assert .Nil (t , err )
96+ })
97+ t .Run ("confirm data saved" , func (t * testing.T ) {
98+ item , err := testClient .GetState (ctx , store , key )
99+ assert .Nil (t , err )
100+ assert .NotNil (t , item )
101+ assert .NotEmpty (t , item .Etag )
102+ assert .Equal (t , item .Key , key )
103+ assert .Equal (t , string (item .Value ), data )
104+ })
105+
106+ t .Run ("delete exist data" , func (t * testing.T ) {
107+ err := testClient .DeleteState (ctx , store , key )
108+ assert .Nil (t , err )
109+ })
110+ t .Run ("confirm data deleted" , func (t * testing.T ) {
111+ item , err := testClient .GetState (ctx , store , key )
112+ assert .Nil (t , err )
113+ assert .NotNil (t , item )
114+ assert .NotEmpty (t , item .Etag )
115+ assert .Equal (t , item .Key , key )
116+ assert .Nil (t , item .Value )
117+ })
118+
119+ t .Run ("save data again with etag, meta" , func (t * testing.T ) {
120+ err := testClient .SaveStateItems (ctx , store , & SetStateItem {
121+ Key : key ,
122+ Value : []byte (data ),
123+ Etag : "100" ,
124+ Metadata : map [string ]string {"meta1" : "value1" },
125+ Options : & StateOptions {Concurrency : StateConcurrencyFirstWrite , Consistency : StateConsistencyEventual },
126+ })
127+ assert .Nil (t , err )
128+ })
129+ t .Run ("confirm data saved" , func (t * testing.T ) {
130+ item , err := testClient .GetStateWithConsistency (ctx , store , key , map [string ]string {"meta1" : "value1" }, StateConsistencyEventual )
131+ assert .Nil (t , err )
132+ assert .NotNil (t , item )
133+ assert .NotEmpty (t , item .Etag )
134+ assert .Equal (t , item .Key , key )
135+ assert .Equal (t , string (item .Value ), data )
136+ })
137+
138+ t .Run ("delete exist data with etag and meta" , func (t * testing.T ) {
139+ err := testClient .DeleteStateWithETag (ctx , store , key , "100" , map [string ]string {"meta1" : "value1" },
140+ & StateOptions {Concurrency : StateConcurrencyFirstWrite , Consistency : StateConsistencyEventual })
141+ assert .Nil (t , err )
142+ })
143+ t .Run ("confirm data deleted" , func (t * testing.T ) {
144+ item , err := testClient .GetStateWithConsistency (ctx , store , key , map [string ]string {"meta1" : "value1" }, StateConsistencyEventual )
145+ assert .Nil (t , err )
146+ assert .NotNil (t , item )
147+ assert .NotEmpty (t , item .Etag )
148+ assert .Equal (t , item .Key , key )
149+ assert .Nil (t , item .Value )
150+ })
151+ }
152+
76153// go test -timeout 30s ./client -count 1 -run ^TestStateTransactions$
77154func TestStateTransactions (t * testing.T ) {
78155 ctx := context .Background ()
0 commit comments