// TestCachedStorage_readDB test the implementation of the readDB function.
TestCachedStorage_readDB test the implementation of the readDB function.
// TestCachedStorage_readDB test the implementation of the readDB function .
func TestCachedStorage_readDB(t *testing.T) {
	db, cleanup := testDB()
	defer cleanup()
	state := &neopb.ExploitState{
		ExploitId: "1",
		Version:   1,
		Config: &neopb.ExploitConfiguration{
			Entrypoint: "./kek",
			IsArchive:  false,
		},
	}
	cs, err := NewStorage(db)
	if err != nil {
		t.Fatalf("NewStorage() failed with unexpected error = %v", err)
	}
	if err := cs.bdb.Update(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte(stateBucketKey))
		stateBytes, err := proto.Marshal(state)
		if err != nil {
			t.Fatalf("proto.Marshall(): failed with error: %v", err)
		}
		stateKey := []byte(fmt.Sprintf("%s:%d", state.ExploitId, state.Version))
		if err := b.Put(stateKey, stateBytes); err != nil {
			return fmt.Errorf("setting state in db: %w", err)
		}
		return nil
	}); err != nil {
		t.Fatalf("db.Update() failed with error = %v", err)
	}
	if err := cs.readDB(); err != nil {
		t.Fatalf("readDB() failed with unexpected error = %v", err)
	}
	if diff := cmp.Diff(state, cs.stateCache["1"], protocmp.Transform()); diff != "" {
		t.Errorf("readDB(): unexpected diff for exploit with id = 1")
	}
}
func TestCachedStorage_readDB ( t * testing . T ) { db , cleanup := testDB ( ) defer cleanup ( ) state := & neopb . ExploitState { ExploitId : " " , Version : 1 , Config : & neopb . ExploitConfiguration { Entrypoint : " " , IsArchive : false , } , } cs , err := NewStorage ( db ) if err != nil { t . Fatalf ( " " , err ) } if err := cs . bdb . Update ( func ( tx * bolt . Tx ) error { b := tx . Bucket ( [ ] byte ( stateBucketKey ) ) stateBytes , err := proto . Marshal ( state ) if err != nil { t . Fatalf ( " " , err ) } stateKey := [ ] byte ( fmt . Sprintf ( " " , state . ExploitId , state . Version ) ) if err := b . Put ( stateKey , stateBytes ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil } ) ; err != nil { t . Fatalf ( " " , err ) } if err := cs . readDB ( ) ; err != nil { t . Fatalf ( " " , err ) } if diff := cmp . Diff ( state , cs . stateCache [ " " ] , protocmp . Transform ( ) ) ; diff != " " { t . Errorf ( " " ) } }
TestCachedStorage_readDB test the implementation of the readDB function.
TestCachedStorage_readDB test the implementation of the readDB function .