How to use TestHelper method of is Package

Best Is code snippet using is.TestHelper

purge_mgr_test.go

Source:purge_mgr_test.go Github

copy

Full Screen

1/*2Copyright IBM Corp. All Rights Reserved.3SPDX-License-Identifier: Apache-2.04*/5package pvtstatepurgemgmt6import (7	"os"8	"testing"9	"github.com/hyperledger/fabric/common/flogging"10	"github.com/hyperledger/fabric/core/ledger/kvledger/bookkeeping"11	"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/privacyenabledstate"12	"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"13	"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"14	"github.com/hyperledger/fabric/core/ledger/pvtdatapolicy"15	btltestutil "github.com/hyperledger/fabric/core/ledger/pvtdatapolicy/testutil"16	"github.com/hyperledger/fabric/core/ledger/util"17	"github.com/spf13/viper"18	"github.com/stretchr/testify/assert"19)20func TestMain(m *testing.M) {21	flogging.ActivateSpec("pvtstatepurgemgmt,privacyenabledstate=debug")22	viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/kvledger/pvtstatepurgemgmt")23	os.Exit(m.Run())24}25func TestPurgeMgr(t *testing.T) {26	dbEnvs := []privacyenabledstate.TestEnv{27		&privacyenabledstate.LevelDBCommonStorageTestEnv{},28		&privacyenabledstate.CouchDBCommonStorageTestEnv{},29	}30	for _, dbEnv := range dbEnvs {31		t.Run(dbEnv.GetName(), func(t *testing.T) { testPurgeMgr(t, dbEnv) })32	}33}34func testPurgeMgr(t *testing.T, dbEnv privacyenabledstate.TestEnv) {35	ledgerid := "testledger-perge-mgr"36	btlPolicy := btltestutil.SampleBTLPolicy(37		map[[2]string]uint64{38			{"ns1", "coll1"}: 1,39			{"ns1", "coll2"}: 2,40			{"ns2", "coll3"}: 4,41			{"ns2", "coll4"}: 4,42		},43	)44	testHelper := &testHelper{}45	testHelper.init(t, ledgerid, btlPolicy, dbEnv)46	defer testHelper.cleanup()47	block1Updates := privacyenabledstate.NewUpdateBatch()48	block1Updates.PubUpdates.Put("ns1", "pubkey1", []byte("pubvalue1-1"), version.NewHeight(1, 1))49	putPvtAndHashUpdates(t, block1Updates, "ns1", "coll1", "pvtkey1", []byte("pvtvalue1-1"), version.NewHeight(1, 1))50	putPvtAndHashUpdates(t, block1Updates, "ns1", "coll2", "pvtkey2", []byte("pvtvalue2-1"), version.NewHeight(1, 1))51	putPvtAndHashUpdates(t, block1Updates, "ns2", "coll3", "pvtkey3", []byte("pvtvalue3-1"), version.NewHeight(1, 1))52	putPvtAndHashUpdates(t, block1Updates, "ns2", "coll4", "pvtkey4", []byte("pvtvalue4-1"), version.NewHeight(1, 1))53	testHelper.commitUpdatesForTesting(1, block1Updates)54	testHelper.checkPvtdataExists("ns1", "coll1", "pvtkey1", []byte("pvtvalue1-1"))55	testHelper.checkPvtdataExists("ns1", "coll2", "pvtkey2", []byte("pvtvalue2-1"))56	testHelper.checkPvtdataExists("ns2", "coll3", "pvtkey3", []byte("pvtvalue3-1"))57	testHelper.checkPvtdataExists("ns2", "coll4", "pvtkey4", []byte("pvtvalue4-1"))58	block2Updates := privacyenabledstate.NewUpdateBatch()59	putPvtAndHashUpdates(t, block2Updates, "ns1", "coll2", "pvtkey2", []byte("pvtvalue2-2"), version.NewHeight(2, 1))60	deletePvtAndHashUpdates(t, block2Updates, "ns2", "coll4", "pvtkey4", version.NewHeight(2, 1))61	testHelper.commitUpdatesForTesting(2, block2Updates)62	testHelper.checkPvtdataExists("ns1", "coll1", "pvtkey1", []byte("pvtvalue1-1"))63	testHelper.checkPvtdataExists("ns1", "coll2", "pvtkey2", []byte("pvtvalue2-2"))64	testHelper.checkPvtdataExists("ns2", "coll3", "pvtkey3", []byte("pvtvalue3-1"))65	testHelper.checkPvtdataDoesNotExist("ns1", "coll4", "pvtkey4")66	noPvtdataUpdates := privacyenabledstate.NewUpdateBatch()67	testHelper.commitUpdatesForTesting(3, noPvtdataUpdates)68	testHelper.checkPvtdataDoesNotExist("ns1", "coll1", "pvtkey1")69	testHelper.checkPvtdataExists("ns1", "coll2", "pvtkey2", []byte("pvtvalue2-2"))70	testHelper.checkPvtdataExists("ns2", "coll3", "pvtkey3", []byte("pvtvalue3-1"))71	testHelper.checkPvtdataDoesNotExist("ns1", "coll4", "pvtkey4")72	testHelper.commitUpdatesForTesting(4, noPvtdataUpdates)73	testHelper.checkPvtdataDoesNotExist("ns1", "coll1", "pvtkey1")74	testHelper.checkPvtdataExists("ns1", "coll2", "pvtkey2", []byte("pvtvalue2-2"))75	testHelper.checkPvtdataExists("ns2", "coll3", "pvtkey3", []byte("pvtvalue3-1"))76	testHelper.checkPvtdataDoesNotExist("ns1", "coll4", "pvtkey4")77	testHelper.commitUpdatesForTesting(5, noPvtdataUpdates)78	testHelper.checkPvtdataDoesNotExist("ns1", "coll1", "pvtkey1")79	testHelper.checkPvtdataDoesNotExist("ns1", "coll2", "pvtkey2")80	testHelper.checkPvtdataExists("ns2", "coll3", "pvtkey3", []byte("pvtvalue3-1"))81	testHelper.checkPvtdataDoesNotExist("ns1", "coll4", "pvtkey4")82	testHelper.commitUpdatesForTesting(6, noPvtdataUpdates)83	testHelper.checkPvtdataDoesNotExist("ns1", "coll1", "pvtkey1")84	testHelper.checkPvtdataDoesNotExist("ns1", "coll2", "pvtkey2")85	testHelper.checkPvtdataDoesNotExist("ns2", "coll3", "pvtkey3")86	testHelper.checkPvtdataDoesNotExist("ns1", "coll4", "pvtkey4")87}88func TestPurgeMgrForCommittingPvtDataOfOldBlocks(t *testing.T) {89	dbEnvs := []privacyenabledstate.TestEnv{90		&privacyenabledstate.LevelDBCommonStorageTestEnv{},91		&privacyenabledstate.CouchDBCommonStorageTestEnv{},92	}93	for _, dbEnv := range dbEnvs {94		t.Run(dbEnv.GetName(), func(t *testing.T) { testPurgeMgrForCommittingPvtDataOfOldBlocks(t, dbEnv) })95	}96}97func testPurgeMgrForCommittingPvtDataOfOldBlocks(t *testing.T, dbEnv privacyenabledstate.TestEnv) {98	ledgerid := "testledger-purge-mgr-pvtdata-oldblocks"99	btlPolicy := btltestutil.SampleBTLPolicy(100		map[[2]string]uint64{101			{"ns1", "coll1"}: 1,102		},103	)104	testHelper := &testHelper{}105	testHelper.init(t, ledgerid, btlPolicy, dbEnv)106	defer testHelper.cleanup()107	// committing block 1108	block1Updates := privacyenabledstate.NewUpdateBatch()109	// pvt data pvtkey1 is missing but the pvtkey2 is present.110	// pvtkey1 and pvtkey2 both would get expired and purged while committing block 3111	putHashUpdates(block1Updates, "ns1", "coll1", "pvtkey1", []byte("pvtvalue1-1"), version.NewHeight(1, 1))112	putPvtAndHashUpdates(t, block1Updates, "ns1", "coll1", "pvtkey2", []byte("pvtvalue1-2"), version.NewHeight(1, 1))113	testHelper.commitUpdatesForTesting(1, block1Updates)114	// pvtkey1 should not exist but pvtkey2 should exist115	testHelper.checkOnlyPvtKeyDoesNotExist("ns1", "coll1", "pvtkey1")116	testHelper.checkPvtdataExists("ns1", "coll1", "pvtkey2", []byte("pvtvalue1-2"))117	// committing block 2118	block2Updates := privacyenabledstate.NewUpdateBatch()119	testHelper.commitUpdatesForTesting(2, block2Updates)120	// Commit pvtkey1 via commit of missing data and this should be added to toPurge list as it121	// should be removed while committing block 3122	block1PvtData := privacyenabledstate.NewUpdateBatch()123	putPvtUpdates(block1PvtData, "ns1", "coll1", "pvtkey1", []byte("pvtvalue1-1"), version.NewHeight(1, 1))124	testHelper.commitPvtDataOfOldBlocksForTesting(block1PvtData)125	// both pvtkey1 and pvtkey1 should exist126	testHelper.checkPvtdataExists("ns1", "coll1", "pvtkey1", []byte("pvtvalue1-1"))127	testHelper.checkPvtdataExists("ns1", "coll1", "pvtkey2", []byte("pvtvalue1-2"))128	// committing block 3129	block3Updates := privacyenabledstate.NewUpdateBatch()130	testHelper.commitUpdatesForTesting(3, block3Updates)131	// both pvtkey1 and pvtkey1 should not exist132	testHelper.checkPvtdataDoesNotExist("ns1", "coll1", "pvtkey1")133	testHelper.checkPvtdataDoesNotExist("ns1", "coll1", "pvtkey2")134}135func TestKeyUpdateBeforeExpiryBlock(t *testing.T) {136	dbEnv := &privacyenabledstate.LevelDBCommonStorageTestEnv{}137	ledgerid := "testledger-perge-mgr"138	btlPolicy := btltestutil.SampleBTLPolicy(139		map[[2]string]uint64{140			{"ns", "coll"}: 1, // expiry block = committing block + 2141		},142	)143	helper := &testHelper{}144	helper.init(t, ledgerid, btlPolicy, dbEnv)145	defer helper.cleanup()146	// block-1 updates: Update only hash of the pvt key147	block1Updates := privacyenabledstate.NewUpdateBatch()148	putHashUpdates(block1Updates, "ns", "coll", "pvtkey", []byte("pvtvalue-1"), version.NewHeight(1, 1))149	helper.commitUpdatesForTesting(1, block1Updates)150	expInfo, _ := helper.purgeMgr.(*purgeMgr).expKeeper.retrieve(3)151	assert.Len(t, expInfo, 1)152	// block-2 update: Update both hash and pvt data153	block2Updates := privacyenabledstate.NewUpdateBatch()154	putPvtAndHashUpdates(t, block2Updates, "ns", "coll", "pvtkey", []byte("pvtvalue-2"), version.NewHeight(2, 1))155	helper.commitUpdatesForTesting(2, block2Updates)156	helper.checkExpiryEntryExistsForBlockNum(3, 1)157	helper.checkExpiryEntryExistsForBlockNum(4, 1)158	// block-3 update: no Updates159	noPvtdataUpdates := privacyenabledstate.NewUpdateBatch()160	helper.commitUpdatesForTesting(3, noPvtdataUpdates)161	helper.checkPvtdataExists("ns", "coll", "pvtkey", []byte("pvtvalue-2"))162	helper.checkNoExpiryEntryExistsForBlockNum(3)163	helper.checkExpiryEntryExistsForBlockNum(4, 1)164	// block-4 update: no Updates165	noPvtdataUpdates = privacyenabledstate.NewUpdateBatch()166	helper.commitUpdatesForTesting(4, noPvtdataUpdates)167	helper.checkPvtdataDoesNotExist("ns", "coll", "pvtkey")168	helper.checkNoExpiryEntryExistsForBlockNum(4)169}170func TestOnlyHashUpdateInExpiryBlock(t *testing.T) {171	dbEnv := &privacyenabledstate.LevelDBCommonStorageTestEnv{}172	ledgerid := "testledger-perge-mgr"173	btlPolicy := btltestutil.SampleBTLPolicy(174		map[[2]string]uint64{175			{"ns", "coll"}: 1, // expiry block = committing block + 2176		},177	)178	helper := &testHelper{}179	helper.init(t, ledgerid, btlPolicy, dbEnv)180	defer helper.cleanup()181	// block-1 updates: Add pvt data182	block1Updates := privacyenabledstate.NewUpdateBatch()183	putPvtAndHashUpdates(t, block1Updates,184		"ns", "coll", "pvtkey", []byte("pvtvalue-1"), version.NewHeight(1, 1))185	helper.commitUpdatesForTesting(1, block1Updates)186	helper.checkExpiryEntryExistsForBlockNum(3, 1)187	// block-2 update: No Updates188	noPvtdataUpdates := privacyenabledstate.NewUpdateBatch()189	helper.commitUpdatesForTesting(2, noPvtdataUpdates)190	helper.checkPvtdataExists(191		"ns", "coll", "pvtkey", []byte("pvtvalue-1"))192	helper.checkExpiryEntryExistsForBlockNum(3, 1)193	// block-3 update: Update hash only194	block3Updates := privacyenabledstate.NewUpdateBatch()195	putHashUpdates(block3Updates,196		"ns", "coll", "pvtkey", []byte("pvtvalue-3"), version.NewHeight(3, 1))197	helper.commitUpdatesForTesting(3, block3Updates)198	helper.checkOnlyKeyHashExists("ns", "coll", "pvtkey")199	helper.checkNoExpiryEntryExistsForBlockNum(3)200	helper.checkExpiryEntryExistsForBlockNum(5, 1)201	// block-4 update: no Updates202	noPvtdataUpdates = privacyenabledstate.NewUpdateBatch()203	helper.commitUpdatesForTesting(4, noPvtdataUpdates)204	helper.checkExpiryEntryExistsForBlockNum(5, 1)205	// block-5 update: no Updates206	noPvtdataUpdates = privacyenabledstate.NewUpdateBatch()207	helper.commitUpdatesForTesting(5, noPvtdataUpdates)208	helper.checkPvtdataDoesNotExist("ns", "coll", "pvtkey")209	helper.checkNoExpiryEntryExistsForBlockNum(5)210}211func TestOnlyHashDeleteBeforeExpiryBlock(t *testing.T) {212	dbEnv := &privacyenabledstate.LevelDBCommonStorageTestEnv{}213	ledgerid := "testledger-perge-mgr"214	btlPolicy := btltestutil.SampleBTLPolicy(215		map[[2]string]uint64{216			{"ns", "coll"}: 1, // expiry block = committing block + 2217		},218	)219	testHelper := &testHelper{}220	testHelper.init(t, ledgerid, btlPolicy, dbEnv)221	defer testHelper.cleanup()222	// block-1 updates: add pvt key223	block1Updates := privacyenabledstate.NewUpdateBatch()224	putPvtAndHashUpdates(t, block1Updates,225		"ns", "coll", "pvtkey", []byte("pvtvalue-1"), version.NewHeight(1, 1))226	testHelper.commitUpdatesForTesting(1, block1Updates)227	// block-2 update: delete Hash only228	block2Updates := privacyenabledstate.NewUpdateBatch()229	deleteHashUpdates(block2Updates, "ns", "coll", "pvtkey", version.NewHeight(2, 1))230	testHelper.commitUpdatesForTesting(2, block2Updates)231	testHelper.checkOnlyPvtKeyExists("ns", "coll", "pvtkey", []byte("pvtvalue-1"))232	// block-3 update: no updates233	noPvtdataUpdates := privacyenabledstate.NewUpdateBatch()234	testHelper.commitUpdatesForTesting(3, noPvtdataUpdates)235	testHelper.checkPvtdataDoesNotExist("ns", "coll", "pvtkey")236}237type testHelper struct {238	t              *testing.T239	bookkeepingEnv *bookkeeping.TestEnv240	dbEnv          privacyenabledstate.TestEnv241	db             privacyenabledstate.DB242	purgeMgr       PurgeMgr243	purgerUsedOnce bool244}245func (h *testHelper) init(t *testing.T, ledgerid string, btlPolicy pvtdatapolicy.BTLPolicy, dbEnv privacyenabledstate.TestEnv) {246	h.t = t247	h.bookkeepingEnv = bookkeeping.NewTestEnv(t)248	dbEnv.Init(t)249	h.dbEnv = dbEnv250	h.db = h.dbEnv.GetDBHandle(ledgerid)251	var err error252	if h.purgeMgr, err = InstantiatePurgeMgr(ledgerid, h.db, btlPolicy, h.bookkeepingEnv.TestProvider); err != nil {253		t.Fatalf("err:%s", err)254	}255}256func (h *testHelper) cleanup() {257	h.bookkeepingEnv.Cleanup()258	h.dbEnv.Cleanup()259}260func (h *testHelper) commitUpdatesForTesting(blkNum uint64, updates *privacyenabledstate.UpdateBatch) {261	h.purgeMgr.PrepareForExpiringKeys(blkNum)262	assert.NoError(h.t, h.purgeMgr.DeleteExpiredAndUpdateBookkeeping(updates.PvtUpdates, updates.HashUpdates))263	assert.NoError(h.t, h.db.ApplyPrivacyAwareUpdates(updates, version.NewHeight(blkNum, 1)))264	h.db.ClearCachedVersions()265	h.purgeMgr.BlockCommitDone()266}267func (h *testHelper) commitPvtDataOfOldBlocksForTesting(updates *privacyenabledstate.UpdateBatch) {268	assert.NoError(h.t, h.purgeMgr.UpdateBookkeepingForPvtDataOfOldBlocks(updates.PvtUpdates))269	assert.NoError(h.t, h.db.ApplyPrivacyAwareUpdates(updates, nil))270}271func (h *testHelper) checkPvtdataExists(ns, coll, key string, value []byte) {272	vv, _ := h.fetchPvtdataFronDB(ns, coll, key)273	vv, hashVersion := h.fetchPvtdataFronDB(ns, coll, key)274	assert.NotNil(h.t, vv)275	assert.Equal(h.t, value, vv.Value)276	assert.Equal(h.t, vv.Version, hashVersion)277}278func (h *testHelper) checkPvtdataDoesNotExist(ns, coll, key string) {279	vv, hashVersion := h.fetchPvtdataFronDB(ns, coll, key)280	assert.Nil(h.t, vv)281	assert.Nil(h.t, hashVersion)282}283func (h *testHelper) checkOnlyPvtKeyExists(ns, coll, key string, value []byte) {284	vv, hashVersion := h.fetchPvtdataFronDB(ns, coll, key)285	assert.NotNil(h.t, vv)286	assert.Nil(h.t, hashVersion)287	assert.Equal(h.t, value, vv.Value)288}289func (h *testHelper) checkOnlyPvtKeyDoesNotExist(ns, coll, key string) {290	kv, err := h.db.GetPrivateData(ns, coll, key)291	assert.Nil(h.t, err)292	assert.Nil(h.t, kv)293}294func (h *testHelper) checkOnlyKeyHashExists(ns, coll, key string) {295	vv, hashVersion := h.fetchPvtdataFronDB(ns, coll, key)296	assert.Nil(h.t, vv)297	assert.NotNil(h.t, hashVersion)298}299func (h *testHelper) fetchPvtdataFronDB(ns, coll, key string) (kv *statedb.VersionedValue, hashVersion *version.Height) {300	var err error301	kv, err = h.db.GetPrivateData(ns, coll, key)302	assert.NoError(h.t, err)303	hashVersion, err = h.db.GetKeyHashVersion(ns, coll, util.ComputeStringHash(key))304	assert.NoError(h.t, err)305	return306}307func (h *testHelper) checkExpiryEntryExistsForBlockNum(expiringBlk uint64, expectedNumEntries int) {308	expInfo, err := h.purgeMgr.(*purgeMgr).expKeeper.retrieve(expiringBlk)309	assert.NoError(h.t, err)310	assert.Len(h.t, expInfo, expectedNumEntries)311}312func (h *testHelper) checkNoExpiryEntryExistsForBlockNum(expiringBlk uint64) {313	expInfo, err := h.purgeMgr.(*purgeMgr).expKeeper.retrieve(expiringBlk)314	assert.NoError(h.t, err)315	assert.Len(h.t, expInfo, 0)316}...

Full Screen

Full Screen

cmdtestlib.go

Source:cmdtestlib.go Github

copy

Full Screen

...19)20var coverprofileCounters map[string]int = make(map[string]int)21var mainHelper *testlib.MainHelper22type testHelper struct {23	*api4.TestHelper24	config            *model.Config25	tempDir           string26	configFilePath    string27	disableAutoConfig bool28}29// Setup creates an instance of testHelper.30func Setup() *testHelper {31	dir, err := ioutil.TempDir("", "testHelper")32	if err != nil {33		panic("failed to create temporary directory: " + err.Error())34	}35	api4TestHelper := api4.Setup()36	testHelper := &testHelper{37		TestHelper:     api4TestHelper,38		tempDir:        dir,39		configFilePath: filepath.Join(dir, "config-helper.json"),40	}41	config := &model.Config{}42	config.SetDefaults()43	testHelper.SetConfig(config)44	return testHelper45}46// InitBasic simply proxies to api4.InitBasic, while still returning a testHelper.47func (h *testHelper) InitBasic() *testHelper {48	h.TestHelper.InitBasic()49	return h50}51// TemporaryDirectory returns the temporary directory created for user by the test helper.52func (h *testHelper) TemporaryDirectory() string {53	return h.tempDir54}55// Config returns the configuration passed to a running command.56func (h *testHelper) Config() *model.Config {57	return h.config.Clone()58}59// ConfigPath returns the path to the temporary config file passed to a running command.60func (h *testHelper) ConfigPath() string {61	return h.configFilePath62}63// SetConfig replaces the configuration passed to a running command.64func (h *testHelper) SetConfig(config *model.Config) {65	config.SqlSettings = *mainHelper.GetSqlSettings()66	// Disable strict password requirements for test67	*config.PasswordSettings.MinimumLength = 568	*config.PasswordSettings.Lowercase = false69	*config.PasswordSettings.Uppercase = false70	*config.PasswordSettings.Symbol = false71	*config.PasswordSettings.Number = false72	h.config = config73	if err := ioutil.WriteFile(h.configFilePath, []byte(config.ToJson()), 0600); err != nil {74		panic("failed to write file " + h.configFilePath + ": " + err.Error())75	}76}77// SetAutoConfig configures whether the --config flag is automatically passed to a running command.78func (h *testHelper) SetAutoConfig(autoConfig bool) {79	h.disableAutoConfig = !autoConfig80}81// TearDown cleans up temporary files and assets created during the life of the test helper.82func (h *testHelper) TearDown() {83	h.TestHelper.TearDown()84	os.RemoveAll(h.tempDir)85}86func (h *testHelper) execArgs(t *testing.T, args []string) []string {87	ret := []string{"-test.v", "-test.run", "ExecCommand"}88	if coverprofile := flag.Lookup("test.coverprofile").Value.String(); coverprofile != "" {89		dir := filepath.Dir(coverprofile)90		base := filepath.Base(coverprofile)91		baseParts := strings.SplitN(base, ".", 2)92		name := strings.Replace(t.Name(), "/", "_", -1)93		coverprofileCounters[name] = coverprofileCounters[name] + 194		baseParts[0] = fmt.Sprintf("%v-%v-%v", baseParts[0], name, coverprofileCounters[name])95		ret = append(ret, "-test.coverprofile", filepath.Join(dir, strings.Join(baseParts, ".")))96	}97	ret = append(ret, "--", "--disableconfigwatch")...

Full Screen

Full Screen

test_helper.go

Source:test_helper.go Github

copy

Full Screen

...22	lgr    ledger.PeerLedger23	lgrid  string24	assert *assert.Assertions25}26// newTestHelperCreateLgr creates a new ledger and retruns a 'testhelper' for the ledger27func newTestHelperCreateLgr(id string, t *testing.T) *testhelper {28	genesisBlk, err := constructTestGenesisBlock(id)29	assert.NoError(t, err)30	lgr, err := ledgermgmt.CreateLedger(genesisBlk)31	assert.NoError(t, err)32	client, committer, verifier := newClient(lgr, t), newCommitter(lgr, t), newVerifier(lgr, t)33	return &testhelper{client, committer, verifier, lgr, id, assert.New(t)}34}35// newTestHelperOpenLgr opens an existing ledger and retruns a 'testhelper' for the ledger36func newTestHelperOpenLgr(id string, t *testing.T) *testhelper {37	lgr, err := ledgermgmt.OpenLedger(id)38	assert.NoError(t, err)39	client, committer, verifier := newClient(lgr, t), newCommitter(lgr, t), newVerifier(lgr, t)40	return &testhelper{client, committer, verifier, lgr, id, assert.New(t)}41}42// cutBlockAndCommitWithPvtdata gathers all the transactions simulated by the test code (by calling43// the functions available in the 'client') and cuts the next block and commits to the ledger44func (h *testhelper) cutBlockAndCommitWithPvtdata() *ledger.BlockAndPvtData {45	defer func() { h.simulatedTrans = nil }()46	return h.committer.cutBlockAndCommitWithPvtdata(h.simulatedTrans...)47}48func (h *testhelper) cutBlockAndCommitExpectError() (*ledger.BlockAndPvtData, error) {49	defer func() { h.simulatedTrans = nil }()50	return h.committer.cutBlockAndCommitExpectError(h.simulatedTrans...)...

Full Screen

Full Screen

TestHelper

Using AI Code Generation

copy

Full Screen

1is.TestHelper()2is.TestHelper()3is.TestHelper()4is.TestHelper()5is.TestHelper()6is.TestHelper()7is.TestHelper()8is.TestHelper()9is.TestHelper()10is.TestHelper()11is.TestHelper()12is.TestHelper()13is.TestHelper()14is.TestHelper()15is.TestHelper()16is.TestHelper()17is.TestHelper()18is.TestHelper()19is.TestHelper()20is.TestHelper()21is.TestHelper()22is.TestHelper()23is.TestHelper()24is.TestHelper()25is.TestHelper()26is.TestHelper()27is.TestHelper()28is.TestHelper()29is.TestHelper()

Full Screen

Full Screen

TestHelper

Using AI Code Generation

copy

Full Screen

1import (2func TestHelper(t *testing.T) {3    assert.Equal(t, 123, 123, "123 and 123 should be equal")4}5import (6func TestHelper(t *testing.T) {7    assert.Equal(t, 123, 123, "123 and 123 should be equal")8}9import (10func TestHelper(t *testing.T) {11    assert.Equal(t, 123, 123, "123 and 123 should be equal")12}13--- PASS: TestHelper (0.00s)14--- PASS: TestHelper (0.00s)15--- PASS: TestHelper (0.00s)16--- PASS: TestHelper (0.00s)

Full Screen

Full Screen

TestHelper

Using AI Code Generation

copy

Full Screen

1import (2type TestHelper struct {3}4func (h *TestHelper) Error(args ...interface{}) {5    h.t.Error(args...)6}7func (h *TestHelper) Fail() {8    h.t.Fail()9}10func (h *TestHelper) FailNow() {11    h.t.FailNow()12}13func (h *TestHelper) Failed() bool {14    return h.t.Failed()15}16func (h *TestHelper) Fatal(args ...interface{}) {17    h.t.Fatal(args...)18}19func (h *TestHelper) Log(args ...interface{}) {20    h.t.Log(args...)21}22func (h *TestHelper) Parallel() {23    h.t.Parallel()24}25func (h *TestHelper) Skip(args ...interface{}) {26    h.t.Skip(args...)27}28func (h *TestHelper) SkipNow() {29    h.t.SkipNow()30}31func (h *TestHelper) Skipped() bool {32    return h.t.Skipped()33}34func (h *TestHelper) Helper() {35    h.t.Helper()36}37func TestHelper(t *testing.T) {38    h := &TestHelper{t}39    h.Helper()40    fmt.Println("TestHelper")41}42--- PASS: TestHelper (0.00s)

Full Screen

Full Screen

TestHelper

Using AI Code Generation

copy

Full Screen

1import (2func TestHelper(t *testing.T) {3	t.Helper()4	fmt.Println("I am helper method")5}6func main() {7	fmt.Println("I am main method")8	TestHelper(t)9}10import (11func TestHelper(t testing.TB) {12	t.Helper()13	fmt.Println("I am helper method")14}15func main() {16	fmt.Println("I am main method")17	TestHelper(t)18}19import (20func TestHelper(t testing.TB) {21	t.Helper()22	fmt.Println("I am helper method")23}24func main() {25	fmt.Println("I am main method")26	TestHelper(t)27}28import (

Full Screen

Full Screen

TestHelper

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	fmt.Println("Hello, world.")4	helper.TestHelper()5}6import "fmt"7func TestHelper() {8	fmt.Println("TestHelper called")9}

Full Screen

Full Screen

TestHelper

Using AI Code Generation

copy

Full Screen

1import (2func TestHelper(t *testing.T) {3    fmt.Println("TestHelper")4    pretty.Println("TestHelper")5}6import (7func TestHelper(t *testing.T) {8    fmt.Println("TestHelper")9    pretty.Println("TestHelper")10}11import (12func TestHelper(t *testing.T) {13    fmt.Println("TestHelper")14    pretty.Println("TestHelper")15}16import (17func TestHelper(t *testing.T) {18    fmt.Println("TestHelper")19    pretty.Println("TestHelper")20}21import (22func TestHelper(t *testing.T) {23    fmt.Println("TestHelper")24    pretty.Println("TestHelper")25}26import (27func TestHelper(t *testing.T) {28    fmt.Println("TestHelper")29    pretty.Println("TestHelper")30}31import (32func TestHelper(t *testing.T) {33    fmt.Println("TestHelper")34    pretty.Println("TestHelper")35}36import (37func TestHelper(t *testing.T) {38    fmt.Println("TestHelper")39    pretty.Println("

Full Screen

Full Screen

TestHelper

Using AI Code Generation

copy

Full Screen

1import "1_test.go"2func TestHelper(t *testing.T) {3    t.Helper()4    t.Log("in test helper")5}6func TestMain(m *testing.M) {7    os.Exit(m.Run())8}9func Test1(t *testing.T) {10    TestHelper(t)11    t.Log("in test 1")12}13--- PASS: Test1 (0.00s)14import "testing"15func TestHelper(t *testing.T) {16    t.Helper()17    t.Log("in test helper")18}19func Test1(t *testing.T) {20    TestHelper(t)21    t.Log("in test 1")22}23--- PASS: Test1 (0.00s)

Full Screen

Full Screen

TestHelper

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	fmt.Println("Hello, playground")4	testhelper.TestHelper()5}6import "fmt"7func TestHelper() {8	fmt.Println("Test helper")9}10import (11func main() {12	fmt.Println("Hello, playground")13	testhelper.TestHelper()14}15import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful