strip_test.v

2.4 KB · raw

1//! Stripping one save must not disturb another save that shares manifests.23module exchange45import os6import src.history7import src.snapshot8import src.storage910fn strip_test_repo(name string) !storage.Store {11	dir := os.join_path(os.temp_dir(), 'koh3_strip_${os.getpid()}_${name}')12	os.rmdir_all(dir) or {}13	os.mkdir_all(dir)!14	mut store := storage.create(dir)!15	os.write_file(os.join_path(dir, '.kohignore'), '*.log\n')!16	return store17}1819fn strip_test_put(root string, rel string, text string) ! {20	full := os.join_path(root, rel)21	os.mkdir_all(os.dir(full))!22	os.write_file(full, text)!23}2425fn strip_test_save(store &storage.Store, message string) !history.Save {26	return history.save_worktree(store, store.root, snapshot.load(store.root), history.SaveInput{27		message: message28	})!29}3031fn strip_test_folder(store &storage.Store, root string, name string) !string {32	for entry in store.manifest_entries(root)! {33		if entry.name == name && entry.kind == storage.folder_kind {34			return entry.manifest35		}36	}37	return error('no folder ${name}')38}3940fn test_stripping_one_save_leaves_a_sharing_save_untouched() {41	mut store := strip_test_repo('isolation')!42	defer {43		store.close()44		os.rmdir_all(store.root) or {}45	}46	strip_test_put(store.root, 'a/keep', 'keep')!47	strip_test_put(store.root, 'a/secret', 'secret')!48	strip_test_put(store.root, 'b/x', 'x')!49	first := strip_test_save(store, 'first')!50	strip_test_put(store.root, 'a/secret', 'secret two')!51	second := strip_test_save(store, 'second')!52	first_saved := history.by_id(store, first.id) or { panic('first save is missing') }53	second_saved := history.by_id(store, second.id) or { panic('second save is missing') }54	first_root := first_saved.manifest55	second_root := second_saved.manifest56	assert first_root != second_root57	shared_b := strip_test_folder(store, second_root, 'b')!58	first_b := strip_test_folder(store, first_root, 'b')!59	assert first_b == shared_b60	strip_local(store, 'a/secret', first.id)!61	first_paths := history.files_of(store, first.id)!62	assert first_paths.map(it.path) == ['.kohignore', 'a/keep', 'b/x']63	second_paths := history.files_of(store, second.id)!64	assert second_paths.map(it.path) == ['.kohignore', 'a/keep', 'a/secret', 'b/x']65	assert store.manifest_body(second_root)!.contains('"name":"b"')66	assert store.manifest_body(shared_b)!.contains('"name":"x"')67	gone := store.has_object(storage.hash_hex('secret'.bytes()))!68	assert !gone69}