How to use IsTrue method of test Package

Best Go-testdeep code snippet using test.IsTrue

privileges_test.go

Source:privileges_test.go Github

copy

Full Screen

...90func (s *testPrivilegeSuite) TestCheckDBPrivilege(c *C) {91 rootSe := newSession(c, s.store, s.dbName)92 mustExec(c, rootSe, `CREATE USER 'testcheck'@'localhost';`)93 se := newSession(c, s.store, s.dbName)94 c.Assert(se.Auth(&auth.UserIdentity{Username: "testcheck", Hostname: "localhost"}, nil, nil), IsTrue)95 pc := privilege.GetPrivilegeManager(se)96 c.Assert(pc.RequestVerification("test", "", "", mysql.SelectPriv), IsFalse)97 mustExec(c, rootSe, `GRANT SELECT ON *.* TO 'testcheck'@'localhost';`)98 c.Assert(pc.RequestVerification("test", "", "", mysql.SelectPriv), IsTrue)99 c.Assert(pc.RequestVerification("test", "", "", mysql.UpdatePriv), IsFalse)100 mustExec(c, rootSe, `GRANT Update ON test.* TO 'testcheck'@'localhost';`)101 c.Assert(pc.RequestVerification("test", "", "", mysql.UpdatePriv), IsTrue)102}103func (s *testPrivilegeSuite) TestCheckTablePrivilege(c *C) {104 rootSe := newSession(c, s.store, s.dbName)105 mustExec(c, rootSe, `CREATE USER 'test1'@'localhost';`)106 se := newSession(c, s.store, s.dbName)107 c.Assert(se.Auth(&auth.UserIdentity{Username: "test1", Hostname: "localhost"}, nil, nil), IsTrue)108 pc := privilege.GetPrivilegeManager(se)109 c.Assert(pc.RequestVerification("test", "test", "", mysql.SelectPriv), IsFalse)110 mustExec(c, rootSe, `GRANT SELECT ON *.* TO 'test1'@'localhost';`)111 c.Assert(pc.RequestVerification("test", "test", "", mysql.SelectPriv), IsTrue)112 c.Assert(pc.RequestVerification("test", "test", "", mysql.UpdatePriv), IsFalse)113 mustExec(c, rootSe, `GRANT Update ON test.* TO 'test1'@'localhost';`)114 c.Assert(pc.RequestVerification("test", "test", "", mysql.UpdatePriv), IsTrue)115 c.Assert(pc.RequestVerification("test", "test", "", mysql.IndexPriv), IsFalse)116 mustExec(c, rootSe, `GRANT Index ON test.test TO 'test1'@'localhost';`)117 c.Assert(pc.RequestVerification("test", "test", "", mysql.IndexPriv), IsTrue)118}119func (s *testPrivilegeSuite) TestShowGrants(c *C) {120 se := newSession(c, s.store, s.dbName)121 ctx, _ := se.(sessionctx.Context)122 mustExec(c, se, `CREATE USER 'show'@'localhost' identified by '123';`)123 mustExec(c, se, `GRANT Index ON *.* TO 'show'@'localhost';`)124 pc := privilege.GetPrivilegeManager(se)125 gs, err := pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})126 c.Assert(err, IsNil)127 c.Assert(gs, HasLen, 1)128 c.Assert(gs[0], Equals, `GRANT Index ON *.* TO 'show'@'localhost'`)129 mustExec(c, se, `GRANT Select ON *.* TO 'show'@'localhost';`)130 gs, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})131 c.Assert(err, IsNil)132 c.Assert(gs, HasLen, 1)133 c.Assert(gs[0], Equals, `GRANT Select,Index ON *.* TO 'show'@'localhost'`)134 // The order of privs is the same with AllGlobalPrivs135 mustExec(c, se, `GRANT Update ON *.* TO 'show'@'localhost';`)136 gs, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})137 c.Assert(err, IsNil)138 c.Assert(gs, HasLen, 1)139 c.Assert(gs[0], Equals, `GRANT Select,Update,Index ON *.* TO 'show'@'localhost'`)140 // All privileges141 mustExec(c, se, `GRANT ALL ON *.* TO 'show'@'localhost';`)142 gs, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})143 c.Assert(err, IsNil)144 c.Assert(gs, HasLen, 1)145 c.Assert(gs[0], Equals, `GRANT ALL PRIVILEGES ON *.* TO 'show'@'localhost'`)146 // Add db scope privileges147 mustExec(c, se, `GRANT Select ON test.* TO 'show'@'localhost';`)148 gs, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})149 c.Assert(err, IsNil)150 c.Assert(gs, HasLen, 2)151 expected := []string{`GRANT ALL PRIVILEGES ON *.* TO 'show'@'localhost'`,152 `GRANT Select ON test.* TO 'show'@'localhost'`}153 c.Assert(testutil.CompareUnorderedStringSlice(gs, expected), IsTrue)154 mustExec(c, se, `GRANT Index ON test1.* TO 'show'@'localhost';`)155 gs, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})156 c.Assert(err, IsNil)157 c.Assert(gs, HasLen, 3)158 expected = []string{`GRANT ALL PRIVILEGES ON *.* TO 'show'@'localhost'`,159 `GRANT Select ON test.* TO 'show'@'localhost'`,160 `GRANT Index ON test1.* TO 'show'@'localhost'`}161 c.Assert(testutil.CompareUnorderedStringSlice(gs, expected), IsTrue)162 mustExec(c, se, `GRANT ALL ON test1.* TO 'show'@'localhost';`)163 gs, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})164 c.Assert(err, IsNil)165 c.Assert(gs, HasLen, 3)166 expected = []string{`GRANT ALL PRIVILEGES ON *.* TO 'show'@'localhost'`,167 `GRANT Select ON test.* TO 'show'@'localhost'`,168 `GRANT ALL PRIVILEGES ON test1.* TO 'show'@'localhost'`}169 c.Assert(testutil.CompareUnorderedStringSlice(gs, expected), IsTrue)170 // Add table scope privileges171 mustExec(c, se, `GRANT Update ON test.test TO 'show'@'localhost';`)172 gs, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})173 c.Assert(err, IsNil)174 c.Assert(gs, HasLen, 4)175 expected = []string{`GRANT ALL PRIVILEGES ON *.* TO 'show'@'localhost'`,176 `GRANT Select ON test.* TO 'show'@'localhost'`,177 `GRANT ALL PRIVILEGES ON test1.* TO 'show'@'localhost'`,178 `GRANT Update ON test.test TO 'show'@'localhost'`}179 c.Assert(testutil.CompareUnorderedStringSlice(gs, expected), IsTrue)180 // Expected behavior: Usage still exists after revoking all privileges181 mustExec(c, se, `REVOKE ALL PRIVILEGES ON *.* FROM 'show'@'localhost'`)182 mustExec(c, se, `REVOKE Select on test.* FROM 'show'@'localhost'`)183 mustExec(c, se, `REVOKE ALL ON test1.* FROM 'show'@'localhost'`)184 mustExec(c, se, `REVOKE UPDATE on test.test FROM 'show'@'localhost'`)185 gs, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})186 c.Assert(err, IsNil)187 c.Assert(gs, HasLen, 1)188 c.Assert(gs[0], Equals, `GRANT USAGE ON *.* TO 'show'@'localhost'`)189 // Usage should not exist after dropping the user190 // Which we need privileges to do so!191 ctx.GetSessionVars().User = &auth.UserIdentity{Username: "root", Hostname: "localhost"}192 mustExec(c, se, `DROP USER 'show'@'localhost'`)193 // This should now return an error194 _, err = pc.ShowGrants(se, &auth.UserIdentity{Username: "show", Hostname: "localhost"})195 c.Assert(err, NotNil)196 // cant show grants for non-existent197 errNonexistingGrant := terror.ClassPrivilege.New(mysql.ErrNonexistingGrant, mysql.MySQLErrName[mysql.ErrNonexistingGrant])198 c.Assert(terror.ErrorEqual(err, errNonexistingGrant), IsTrue)199}200func (s *testPrivilegeSuite) TestDropTablePriv(c *C) {201 se := newSession(c, s.store, s.dbName)202 ctx, _ := se.(sessionctx.Context)203 mustExec(c, se, `CREATE TABLE todrop(c int);`)204 // ctx.GetSessionVars().User = "root@localhost"205 c.Assert(se.Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil), IsTrue)206 mustExec(c, se, `CREATE USER 'drop'@'localhost';`)207 mustExec(c, se, `GRANT Select ON test.todrop TO 'drop'@'localhost';`)208 // ctx.GetSessionVars().User = "drop@localhost"209 c.Assert(se.Auth(&auth.UserIdentity{Username: "drop", Hostname: "localhost"}, nil, nil), IsTrue)210 mustExec(c, se, `SELECT * FROM todrop;`)211 _, err := se.Execute(context.Background(), "DROP TABLE todrop;")212 c.Assert(err, NotNil)213 se = newSession(c, s.store, s.dbName)214 ctx.GetSessionVars().User = &auth.UserIdentity{Username: "root", Hostname: "localhost"}215 mustExec(c, se, `GRANT Drop ON test.todrop TO 'drop'@'localhost';`)216 se = newSession(c, s.store, s.dbName)217 ctx.GetSessionVars().User = &auth.UserIdentity{Username: "drop", Hostname: "localhost"}218 mustExec(c, se, `DROP TABLE todrop;`)219}220func (s *testPrivilegeSuite) TestSetPasswdStmt(c *C) {221 se := newSession(c, s.store, s.dbName)222 // high privileged user setting password for other user (passes)223 mustExec(c, se, "CREATE USER 'superuser'")224 mustExec(c, se, "CREATE USER 'nobodyuser'")225 mustExec(c, se, "GRANT ALL ON *.* TO 'superuser'")226 c.Assert(se.Auth(&auth.UserIdentity{Username: "superuser", Hostname: "localhost", AuthUsername: "superuser", AuthHostname: "%"}, nil, nil), IsTrue)227 mustExec(c, se, "SET PASSWORD for 'nobodyuser' = 'newpassword'")228 mustExec(c, se, "SET PASSWORD for 'nobodyuser' = ''")229 // low privileged user trying to set password for other user (fails)230 c.Assert(se.Auth(&auth.UserIdentity{Username: "nobodyuser", Hostname: "localhost", AuthUsername: "nobodyuser", AuthHostname: "%"}, nil, nil), IsTrue)231 _, err := se.Execute(context.Background(), "SET PASSWORD for 'superuser' = 'newpassword'")232 c.Assert(err, NotNil)233}234func (s *testPrivilegeSuite) TestSelectViewSecurity(c *C) {235 se := newSession(c, s.store, s.dbName)236 ctx, _ := se.(sessionctx.Context)237 mustExec(c, se, `CREATE TABLE viewsecurity(c int);`)238 // ctx.GetSessionVars().User = "root@localhost"239 c.Assert(se.Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil), IsTrue)240 mustExec(c, se, `CREATE USER 'selectusr'@'localhost';`)241 mustExec(c, se, `GRANT CREATE VIEW ON test.* TO 'selectusr'@'localhost';`)242 mustExec(c, se, `GRANT SELECT ON test.viewsecurity TO 'selectusr'@'localhost';`)243 // ctx.GetSessionVars().User = "selectusr@localhost"244 c.Assert(se.Auth(&auth.UserIdentity{Username: "selectusr", Hostname: "localhost"}, nil, nil), IsTrue)245 mustExec(c, se, `SELECT * FROM test.viewsecurity;`)246 mustExec(c, se, `CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW test.selectviewsecurity as select * FROM test.viewsecurity;`)247 se = newSession(c, s.store, s.dbName)248 ctx.GetSessionVars().User = &auth.UserIdentity{Username: "root", Hostname: "localhost"}249 mustExec(c, se, "SELECT * FROM test.selectviewsecurity")250 mustExec(c, se, `REVOKE Select ON test.viewsecurity FROM 'selectusr'@'localhost';`)251 _, err := se.Execute(context.Background(), "select * from test.selectviewsecurity")252 c.Assert(err.Error(), Equals, core.ErrViewInvalid.GenWithStackByArgs("test", "selectviewsecurity").Error())253}254func (s *testPrivilegeSuite) TestRoleAdminSecurity(c *C) {255 se := newSession(c, s.store, s.dbName)256 mustExec(c, se, `CREATE USER 'r1'@'localhost';`)257 mustExec(c, se, `CREATE USER 'r2'@'localhost';`)258 mustExec(c, se, `GRANT ALL ON *.* to r1@localhost`)259 c.Assert(se.Auth(&auth.UserIdentity{Username: "r1", Hostname: "localhost"}, nil, nil), IsTrue)260 mustExec(c, se, `create role r_test1@localhost`)261 c.Assert(se.Auth(&auth.UserIdentity{Username: "r2", Hostname: "localhost"}, nil, nil), IsTrue)262 _, err := se.Execute(context.Background(), `create role r_test2@localhost`)263 c.Assert(terror.ErrorEqual(err, core.ErrSpecificAccessDenied), IsTrue)264}265func (s *testPrivilegeSuite) TestCheckAuthenticate(c *C) {266 se := newSession(c, s.store, s.dbName)267 mustExec(c, se, `CREATE USER 'u1'@'localhost';`)268 mustExec(c, se, `CREATE USER 'u2'@'localhost' identified by 'abc';`)269 mustExec(c, se, `CREATE USER 'u3@example.com'@'localhost';`)270 mustExec(c, se, `CREATE USER u4@localhost;`)271 c.Assert(se.Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil), IsTrue)272 c.Assert(se.Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil), IsFalse)273 salt := []byte{85, 92, 45, 22, 58, 79, 107, 6, 122, 125, 58, 80, 12, 90, 103, 32, 90, 10, 74, 82}274 authentication := []byte{24, 180, 183, 225, 166, 6, 81, 102, 70, 248, 199, 143, 91, 204, 169, 9, 161, 171, 203, 33}275 c.Assert(se.Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, authentication, salt), IsTrue)276 c.Assert(se.Auth(&auth.UserIdentity{Username: "u3@example.com", Hostname: "localhost"}, nil, nil), IsTrue)277 c.Assert(se.Auth(&auth.UserIdentity{Username: "u4", Hostname: "localhost"}, nil, nil), IsTrue)278 se1 := newSession(c, s.store, s.dbName)279 mustExec(c, se1, "drop user 'u1'@'localhost'")280 mustExec(c, se1, "drop user 'u2'@'localhost'")281 mustExec(c, se1, "drop user 'u3@example.com'@'localhost'")282 mustExec(c, se1, "drop user u4@localhost")283 c.Assert(se.Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil), IsFalse)284 c.Assert(se.Auth(&auth.UserIdentity{Username: "u2", Hostname: "localhost"}, nil, nil), IsFalse)285 c.Assert(se.Auth(&auth.UserIdentity{Username: "u3@example.com", Hostname: "localhost"}, nil, nil), IsFalse)286 c.Assert(se.Auth(&auth.UserIdentity{Username: "u4", Hostname: "localhost"}, nil, nil), IsFalse)287 se2 := newSession(c, s.store, s.dbName)288 mustExec(c, se2, "create role 'r1'@'localhost'")289 mustExec(c, se2, "create role 'r2'@'localhost'")290 mustExec(c, se2, "create role 'r3@example.com'@'localhost'")291 c.Assert(se.Auth(&auth.UserIdentity{Username: "r1", Hostname: "localhost"}, nil, nil), IsFalse)292 c.Assert(se.Auth(&auth.UserIdentity{Username: "r2", Hostname: "localhost"}, nil, nil), IsFalse)293 c.Assert(se.Auth(&auth.UserIdentity{Username: "r3@example.com", Hostname: "localhost"}, nil, nil), IsFalse)294 mustExec(c, se1, "drop user 'r1'@'localhost'")295 mustExec(c, se1, "drop user 'r2'@'localhost'")296 mustExec(c, se1, "drop user 'r3@example.com'@'localhost'")297}298func (s *testPrivilegeSuite) TestUseDb(c *C) {299 se := newSession(c, s.store, s.dbName)300 // high privileged user301 mustExec(c, se, "CREATE USER 'usesuper'")302 mustExec(c, se, "CREATE USER 'usenobody'")303 mustExec(c, se, "GRANT ALL ON *.* TO 'usesuper'")304 c.Assert(se.Auth(&auth.UserIdentity{Username: "usesuper", Hostname: "localhost", AuthUsername: "usesuper", AuthHostname: "%"}, nil, nil), IsTrue)305 mustExec(c, se, "use mysql")306 // low privileged user307 c.Assert(se.Auth(&auth.UserIdentity{Username: "usenobody", Hostname: "localhost", AuthUsername: "usenobody", AuthHostname: "%"}, nil, nil), IsTrue)308 _, err := se.Execute(context.Background(), "use mysql")309 c.Assert(err, NotNil)310 // try again after privilege granted311 c.Assert(se.Auth(&auth.UserIdentity{Username: "usesuper", Hostname: "localhost", AuthUsername: "usesuper", AuthHostname: "%"}, nil, nil), IsTrue)312 mustExec(c, se, "GRANT SELECT ON mysql.* TO 'usenobody'")313 c.Assert(se.Auth(&auth.UserIdentity{Username: "usenobody", Hostname: "localhost", AuthUsername: "usenobody", AuthHostname: "%"}, nil, nil), IsTrue)314 _, err = se.Execute(context.Background(), "use mysql")315 c.Assert(err, IsNil)316}317func (s *testPrivilegeSuite) TestSetGlobal(c *C) {318 se := newSession(c, s.store, s.dbName)319 mustExec(c, se, `CREATE USER setglobal_a@localhost`)320 mustExec(c, se, `CREATE USER setglobal_b@localhost`)321 mustExec(c, se, `GRANT SUPER ON *.* to setglobal_a@localhost`)322 c.Assert(se.Auth(&auth.UserIdentity{Username: "setglobal_a", Hostname: "localhost"}, nil, nil), IsTrue)323 mustExec(c, se, `set global innodb_commit_concurrency=16`)324 c.Assert(se.Auth(&auth.UserIdentity{Username: "setglobal_b", Hostname: "localhost"}, nil, nil), IsTrue)325 _, err := se.Execute(context.Background(), `set global innodb_commit_concurrency=16`)326 c.Assert(terror.ErrorEqual(err, core.ErrSpecificAccessDenied), IsTrue)327}328func (s *testPrivilegeSuite) TestCreateDropUser(c *C) {329 se := newSession(c, s.store, s.dbName)330 mustExec(c, se, `CREATE USER tcd1, tcd2`)331 mustExec(c, se, `GRANT ALL ON *.* to tcd2`)332 // should fail333 c.Assert(se.Auth(&auth.UserIdentity{Username: "tcd1", Hostname: "localhost", AuthUsername: "tcd1", AuthHostname: "%"}, nil, nil), IsTrue)334 _, err := se.Execute(context.Background(), `CREATE USER acdc`)335 c.Assert(terror.ErrorEqual(err, core.ErrSpecificAccessDenied), IsTrue)336 _, err = se.Execute(context.Background(), `DROP USER tcd2`)337 c.Assert(terror.ErrorEqual(err, core.ErrSpecificAccessDenied), IsTrue)338 // should pass339 c.Assert(se.Auth(&auth.UserIdentity{Username: "tcd2", Hostname: "localhost", AuthUsername: "tcd2", AuthHostname: "%"}, nil, nil), IsTrue)340 mustExec(c, se, `DROP USER tcd1`)341 mustExec(c, se, `CREATE USER tcd1`)342}343func (s *testPrivilegeSuite) TestShowCreateTable(c *C) {344 se := newSession(c, s.store, s.dbName)345 mustExec(c, se, `CREATE USER tsct1, tsct2`)346 mustExec(c, se, `GRANT select ON mysql.* to tsct2`)347 // should fail348 c.Assert(se.Auth(&auth.UserIdentity{Username: "tsct1", Hostname: "localhost", AuthUsername: "tsct1", AuthHostname: "%"}, nil, nil), IsTrue)349 _, err := se.Execute(context.Background(), `SHOW CREATE TABLE mysql.user`)350 c.Assert(terror.ErrorEqual(err, core.ErrTableaccessDenied), IsTrue)351 // should pass352 c.Assert(se.Auth(&auth.UserIdentity{Username: "tsct2", Hostname: "localhost", AuthUsername: "tsct2", AuthHostname: "%"}, nil, nil), IsTrue)353 mustExec(c, se, `SHOW CREATE TABLE mysql.user`)354}355func (s *testPrivilegeSuite) TestAnalyzeTable(c *C) {356 se := newSession(c, s.store, s.dbName)357 // high privileged user358 mustExec(c, se, "CREATE USER 'asuper'")359 mustExec(c, se, "CREATE USER 'anobody'")360 mustExec(c, se, "GRANT ALL ON *.* TO 'asuper'")361 mustExec(c, se, "CREATE DATABASE atest")362 mustExec(c, se, "use atest")363 mustExec(c, se, "CREATE TABLE t1 (a int)")364 c.Assert(se.Auth(&auth.UserIdentity{Username: "asuper", Hostname: "localhost", AuthUsername: "asuper", AuthHostname: "%"}, nil, nil), IsTrue)365 mustExec(c, se, "analyze table mysql.user")366 // low privileged user367 c.Assert(se.Auth(&auth.UserIdentity{Username: "anobody", Hostname: "localhost", AuthUsername: "anobody", AuthHostname: "%"}, nil, nil), IsTrue)368 _, err := se.Execute(context.Background(), "analyze table t1")369 c.Assert(terror.ErrorEqual(err, core.ErrTableaccessDenied), IsTrue)370 c.Assert(err.Error(), Equals, "[planner:1142]INSERT command denied to user 'anobody'@'%' for table 't1'")371 _, err = se.Execute(context.Background(), "select * from t1")372 c.Assert(err.Error(), Equals, "[planner:1142]SELECT command denied to user 'localhost'@'anobody' for table 't1'")373 // try again after SELECT privilege granted374 c.Assert(se.Auth(&auth.UserIdentity{Username: "asuper", Hostname: "localhost", AuthUsername: "asuper", AuthHostname: "%"}, nil, nil), IsTrue)375 mustExec(c, se, "GRANT SELECT ON atest.* TO 'anobody'")376 c.Assert(se.Auth(&auth.UserIdentity{Username: "anobody", Hostname: "localhost", AuthUsername: "anobody", AuthHostname: "%"}, nil, nil), IsTrue)377 _, err = se.Execute(context.Background(), "analyze table t1")378 c.Assert(terror.ErrorEqual(err, core.ErrTableaccessDenied), IsTrue)379 c.Assert(err.Error(), Equals, "[planner:1142]INSERT command denied to user 'anobody'@'%' for table 't1'")380 // Add INSERT privilege and it should work.381 c.Assert(se.Auth(&auth.UserIdentity{Username: "asuper", Hostname: "localhost", AuthUsername: "asuper", AuthHostname: "%"}, nil, nil), IsTrue)382 mustExec(c, se, "GRANT INSERT ON atest.* TO 'anobody'")383 c.Assert(se.Auth(&auth.UserIdentity{Username: "anobody", Hostname: "localhost", AuthUsername: "anobody", AuthHostname: "%"}, nil, nil), IsTrue)384 _, err = se.Execute(context.Background(), "analyze table t1")385 c.Assert(err, IsNil)386}387func (s *testPrivilegeSuite) TestInformationSchema(c *C) {388 // This test tests no privilege check for INFORMATION_SCHEMA database.389 se := newSession(c, s.store, s.dbName)390 mustExec(c, se, `CREATE USER 'u1'@'localhost';`)391 c.Assert(se.Auth(&auth.UserIdentity{Username: "u1", Hostname: "localhost"}, nil, nil), IsTrue)392 mustExec(c, se, `select * from information_schema.tables`)393 mustExec(c, se, `select * from information_schema.key_column_usage`)394}395func (s *testPrivilegeSuite) TestAdminCommand(c *C) {396 se := newSession(c, s.store, s.dbName)397 c.Assert(se.Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil), IsTrue)398 mustExec(c, se, `CREATE USER 'test_admin'@'localhost';`)399 mustExec(c, se, `CREATE TABLE t(a int)`)400 c.Assert(se.Auth(&auth.UserIdentity{Username: "test_admin", Hostname: "localhost"}, nil, nil), IsTrue)401 _, err := se.Execute(context.Background(), "ADMIN SHOW DDL JOBS")402 c.Assert(strings.Contains(err.Error(), "privilege check fail"), IsTrue)403 _, err = se.Execute(context.Background(), "ADMIN CHECK TABLE t")404 c.Assert(strings.Contains(err.Error(), "privilege check fail"), IsTrue)405 c.Assert(se.Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil), IsTrue)406 _, err = se.Execute(context.Background(), "ADMIN SHOW DDL JOBS")407 c.Assert(err, IsNil)408}409func (s *testPrivilegeSuite) TestGetEncodedPassword(c *C) {410 se := newSession(c, s.store, s.dbName)411 mustExec(c, se, `CREATE USER 'test_encode_u'@'localhost' identified by 'root';`)412 pc := privilege.GetPrivilegeManager(se)413 c.Assert(pc.GetEncodedPassword("test_encode_u", "localhost"), Equals, "*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B")414}415func mustExec(c *C, se session.Session, sql string) {416 _, err := se.Execute(context.Background(), sql)417 c.Assert(err, IsNil)418}419func newStore(c *C, dbPath string) (*domain.Domain, kv.Storage) {...

Full Screen

Full Screen

new_test.go

Source:new_test.go Github

copy

Full Screen

1package jsonvalue2import (3 "testing"4)5func testNewXxx(t *testing.T) {6 cv("NewString", func() { testNewString(t) })7 cv("NewBool", func() { testNewBool(t) })8 cv("NewNull", func() { testNewNull(t) })9 cv("NewIntXxx/UintXxx", func() { testNewInteger(t) })10 cv("NewFloat64/32", func() { testNewFloat(t) })11 cv("empty object/array", func() { testEmptyObjectArray(t) })12 cv("misc value", func() { testMiscValue(t) })13 cv("MustMarshal error", func() { testMustMarshalError(t) })14 cv("ValueError error", func() { testValueError(t) })15}16func testNewString(t *testing.T) {17 s := "你好,世界"18 v := NewString(s)19 so(v.String(), eq, s)20 so(v.ValueType(), eq, String)21}22func testNewBool(t *testing.T) {23 v := NewBool(true)24 so(v.Bool(), isTrue)25 so(v.IsBoolean(), isTrue)26 so(v.ValueType(), eq, Boolean)27 v = NewBool(false)28 so(v.Bool(), isFalse)29 so(v.IsBoolean(), isTrue)30 so(v.ValueType(), eq, Boolean)31}32func testNewNull(t *testing.T) {33 v := NewNull()34 so(v.IsNull(), isTrue)35 so(v.ValueType(), eq, Null)36}37func testNewInteger(t *testing.T) {38 i := int64(-1234567)39 v := NewInt(int(i))40 so(v.Int(), eq, int(i))41 so(v.ValueType(), eq, Number)42 v = NewUint(uint(i))43 so(v.Uint(), eq, uint(i))44 so(v.ValueType(), eq, Number)45 v = NewInt32(int32(i))46 so(v.Int32(), eq, int32(i))47 so(v.ValueType(), eq, Number)48 v = NewUint32(uint32(i))49 so(v.Uint32(), eq, uint32(i))50 so(v.ValueType(), eq, Number)51 v = NewInt64(int64(i))52 so(v.Int64(), eq, int64(i))53 so(v.ValueType(), eq, Number)54 v = NewUint64(uint64(i))55 so(v.Uint64(), eq, uint64(i))56 so(v.ValueType(), eq, Number)57}58func testNewFloat(t *testing.T) {59 s := "3.1415926535"60 f := 3.141592653561 v := NewFloat64f(f, 'f', 10)62 so(v.String(), eq, s)63 so(v.ValueType(), eq, Number)64 v = NewFloat64f(f, '?', 11)65 so(v.String(), eq, s)66 so(v.ValueType(), eq, Number)67 v = NewFloat64f(f, 'g', 3)68 so(v.String(), eq, "3.14")69 so(v.ValueType(), eq, Number)70 s = "3.1415927"71 v = NewFloat32(float32(f))72 so(v.String(), eq, s)73 so(v.ValueType(), eq, Number)74 v = NewFloat32f(float32(f), 'f', 5)75 so(v.String(), eq, "3.14159")76 so(v.ValueType(), eq, Number)77 v = NewFloat32f(float32(f), 'e', 5)78 so(v.String(), eq, "3.14159e+00")79 so(v.ValueType(), eq, Number)80 v = NewFloat32f(float32(f), '?', 5)81 so(v.String(), eq, "3.1416")82 so(v.ValueType(), eq, Number)83}84func testEmptyObjectArray(t *testing.T) {85 v := NewObject()86 b, _ := v.Marshal()87 so(string(b), eq, "{}")88 so(v.ValueType(), eq, Object)89 v = NewArray()90 b = v.MustMarshal()91 so(string(b), eq, "[]")92 so(v.ValueType(), eq, Array)93}94func testMiscValue(t *testing.T) {95 cv("parse array", func() {96 raw := "\r\n[1, 2, 3 ]\t\b"97 v, err := UnmarshalString(raw)98 so(err, isNil)99 so(v.IsArray(), isTrue)100 })101 cv("parse object", func() {102 raw := `{ }`103 v, err := UnmarshalString(raw)104 so(err, isNil)105 so(v.IsObject(), isTrue)106 })107 cv("parse string", func() {108 raw := ` "hello, world" `109 v, err := UnmarshalString(raw)110 so(err, isNil)111 so(v.IsString(), isTrue)112 so(v.Int(), isZero)113 so(v.Uint(), isZero)114 so(v.Int64(), isZero)115 so(v.Uint64(), isZero)116 so(v.Int32(), isZero)117 so(v.Uint32(), isZero)118 so(v.Float64(), isZero)119 so(v.Float32(), isZero)120 so(v.IsFloat(), isFalse)121 so(v.IsInteger(), isFalse)122 })123 cv("parse string with special character", func() {124 raw := `"\"\\\/\f\t\r\n\b\u0030\uD87E\uDC04"`125 v, err := UnmarshalString(raw)126 so(err, isNil)127 so(v.IsString(), isTrue)128 })129 cv("parse null", func() {130 raw := `null`131 v, err := UnmarshalString(raw)132 so(err, isNil)133 so(v.IsNull(), isTrue)134 })135 cv("parse bool (true)", func() {136 raw := `true`137 v, err := UnmarshalString(raw)138 so(err, isNil)139 so(v.IsBoolean(), isTrue)140 so(v.Bool(), isTrue)141 })142 cv("parse bool (false)", func() {143 raw := `false`144 v, err := UnmarshalString(raw)145 so(err, isNil)146 so(v.IsBoolean(), isTrue)147 so(v.Bool(), isFalse)148 })149 cv("parse negative float", func() {150 raw := `-12345.12345`151 v, err := UnmarshalString(raw)152 so(err, isNil)153 so(v.IsNumber(), isTrue)154 so(v.IsFloat(), isTrue)155 so(v.IsNegative(), isTrue)156 so(v.GreaterThanInt64Max(), isFalse)157 })158 cv("parse exponential form float", func() {159 raw := `-1.25e3`160 v, err := UnmarshalString(raw)161 so(err, isNil)162 so(v.IsFloat(), isTrue)163 so(v.IsNegative(), isTrue)164 so(v.Float32(), eq, -1250)165 raw = `1.25E-1`166 v, err = UnmarshalString(raw)167 so(err, isNil)168 so(v.IsFloat(), isTrue)169 so(v.IsNegative(), isFalse)170 so(v.Float32(), eq, 0.125)171 })172 cv("parse negative integer", func() {173 raw := `-12345`174 v, err := UnmarshalString(raw)175 so(err, isNil)176 so(v.IsNumber(), isTrue)177 so(v.IsFloat(), isFalse)178 so(v.IsNegative(), isTrue)179 so(v.GreaterThanInt64Max(), isFalse)180 })181 cv("parse positive integer", func() {182 raw := `12345`183 v, err := UnmarshalString(raw)184 so(err, isNil)185 so(v.IsNumber(), isTrue)186 so(v.IsFloat(), isFalse)187 so(v.IsPositive(), isTrue)188 so(v.GreaterThanInt64Max(), isFalse)189 })190 cv("parse big uint64", func() {191 raw := `18446744073709551615` // 0xFFFFFFFFFFFFFFFF192 v, err := UnmarshalString(raw)193 so(err, isNil)194 so(v.IsNumber(), isTrue)195 so(v.IsFloat(), isFalse)196 so(v.IsPositive(), isTrue)197 so(v.GreaterThanInt64Max(), isTrue)198 })199 cv("parse object in array", func() {200 raw := `[{}]`201 v, err := UnmarshalString(raw)202 so(err, isNil)203 so(v.IsArray(), isTrue)204 c, err := v.Get(0)205 so(err, isNil)206 so(c.IsObject(), isTrue)207 })208 cv("parse array in object", func() {209 raw := `{"array":[]}`210 v, err := UnmarshalString(raw)211 so(err, isNil)212 so(v.IsObject(), isTrue)213 c, err := v.Get("array")214 so(err, isNil)215 so(c.IsArray(), isTrue)216 })217 cv("parse float in object", func() {218 raw := `{"float":123.4567}`219 v, err := UnmarshalString(raw)220 so(err, isNil)221 so(v.IsObject(), isTrue)222 c, err := v.Get("float")223 so(err, isNil)224 so(c.IsFloat(), isTrue)225 })226 cv("parse integer in object", func() {227 raw := `{"int":123}`228 v, err := UnmarshalString(raw)229 so(err, isNil)230 so(v.IsObject(), isTrue)231 c, err := v.Get("int")232 so(err, isNil)233 so(c.IsInteger(), isTrue)234 })235 cv("parse int in object", func() {236 raw := `{"int":123}`237 v, err := UnmarshalString(raw)238 so(err, isNil)239 so(v.IsObject(), isTrue)240 c, err := v.Get("int")241 so(err, isNil)242 so(c.Int(), eq, 123)243 })244 cv("parse uint in object", func() {245 raw := `{"uint":123}`246 v, err := UnmarshalString(raw)247 so(err, isNil)248 so(v.IsObject(), isTrue)249 c, err := v.Get("uint")250 so(err, isNil)251 so(c.Uint(), eq, 123)252 })253 cv("parse int64 in object", func() {254 raw := `{"uint":123}`255 v, err := UnmarshalString(raw)256 so(err, isNil)257 so(v.IsObject(), isTrue)258 c, err := v.Get("uint")259 so(err, isNil)260 so(c.Int64(), eq, 123)261 })262 cv("parse uint64 in object", func() {263 raw := `{"uint":123}`264 v, err := UnmarshalString(raw)265 so(err, isNil)266 so(v.IsObject(), isTrue)267 c, err := v.Get("uint")268 so(err, isNil)269 so(c.Uint64(), eq, 123)270 })271 cv("parse int32 in object", func() {272 raw := `{"int":123}`273 v, err := UnmarshalString(raw)274 so(err, isNil)275 so(v.IsObject(), isTrue)276 c, err := v.Get("int")277 so(err, isNil)278 so(c.Int32(), eq, 123)279 })280 cv("parse uint32 in object", func() {281 raw := `{"uint":123}`282 v, err := UnmarshalString(raw)283 so(err, isNil)284 so(v.IsObject(), isTrue)285 c, err := v.Get("uint")286 so(err, isNil)287 so(c.Uint32(), eq, 123)288 })289 cv("parse float32 in object", func() {290 raw := `{"float":123.456}`291 v, err := UnmarshalString(raw)292 so(err, isNil)293 so(v.IsObject(), isTrue)294 c, err := v.Get("float")295 so(err, isNil)296 so(c.Float32(), eq, 123.456)297 })298 cv("parse float64 in object", func() {299 raw := `{"float":123.456}`300 v, err := UnmarshalString(raw)301 so(err, isNil)302 so(v.IsObject(), isTrue)303 c, err := v.Get("float")304 so(err, isNil)305 so(c.Float64(), eq, 123.456)306 })307 cv("parse negative in object", func() {308 raw := `{"negative":-123}`309 v, err := UnmarshalString(raw)310 so(err, isNil)311 so(v.IsObject(), isTrue)312 c, err := v.Get("negative")313 so(err, isNil)314 so(c.IsNegative(), isTrue)315 })316 cv("parse positive in object", func() {317 raw := `{"positive":123}`318 v, err := UnmarshalString(raw)319 so(err, isNil)320 so(v.IsObject(), isTrue)321 c, err := v.Get("positive")322 so(err, isNil)323 so(c.IsPositive(), isTrue)324 })325 cv("parse greater than int64 in object", func() {326 raw := `{"int":9223372036854775808}`327 v, err := UnmarshalString(raw)328 so(err, isNil)329 so(v.IsObject(), isTrue)330 c, err := v.Get("int")331 so(err, isNil)332 so(c.GreaterThanInt64Max(), isTrue)333 })334 cv("create an initialized JSON object", func() {335 v := NewObject(map[string]any{336 "null": nil,337 "string": "string",338 "true": true,339 "int": int(-1),340 "uint": uint(1),341 "int8": int8(-2),342 "uint8": uint8(2),343 "int16": int16(-3),344 "uint16": uint16(3),345 "int32": int32(-4),346 "uint32": uint32(4),347 "int64": int64(-5),348 "uint64": uint64(5),349 "float32": float32(-1.1),350 "float64": float64(-2.2),351 })352 so(v.GetNull("null"), isNil)353 str, err := v.GetString("string")354 so(err, isNil)355 so(str, eq, "string")356 bl, err := v.GetBool("true")357 so(err, isNil)358 so(bl, isTrue)359 checkInt := func(k string, target int) {360 i, err := v.GetInt(k)361 so(err, isNil)362 so(i, eq, target)363 }364 checkInt("int", -1)365 checkInt("uint", 1)366 checkInt("int8", -2)367 checkInt("uint8", 2)368 checkInt("int16", -3)369 checkInt("uint16", 3)370 checkInt("int32", -4)371 checkInt("uint32", 4)372 checkInt("int64", -5)373 checkInt("uint64", 5)374 f32, err := v.GetFloat32("float32")375 so(err, isNil)376 so(f32, eq, float32(-1.1))377 f64, err := v.GetFloat64("float64")378 so(err, isNil)379 so(f64, eq, float64(-2.2))380 })381}382func testMustMarshalError(t *testing.T) {383 shouldPanic(func() {384 v := &V{}385 v.MustMarshal()386 })387 shouldPanic(func() {388 v := &V{}389 v.MustMarshalString()390 })391}392func testValueError(t *testing.T) {393 var err error394 var raw string395 var v *V396 cv("invalid jsonvalue.V", func() {397 v = &V{}398 so(v.String(), eq, "")399 })400 cv("number in string", func() {401 v, err = UnmarshalString(`"12.ABCD"`)402 so(err, isNil)403 so(v.Int(), isZero)404 v, err = UnmarshalString(`"-12ABCD"`)405 so(err, isNil)406 so(v.Int(), isZero)407 v, err = UnmarshalString(`{}`)408 so(err, isNil)409 so(v.Int(), isZero)410 v, err = UnmarshalString(`"1234"`)411 so(err, isNil)412 so(v.Int(), eq, 1234)413 so(v.IsNumber(), isFalse)414 so(v.IsFloat(), isFalse)415 so(v.IsInteger(), isFalse)416 so(v.IsNegative(), isFalse)417 so(v.IsPositive(), isFalse)418 so(v.GreaterThanInt64Max(), isFalse)419 })420 cv("nil string input", func() {421 _, err = UnmarshalString("")422 so(err, isErr)423 })424 cv("nil bytes input", func() {425 _, err = Unmarshal(nil)426 so(err, isErr)427 })428 cv("illegal char", func() {429 _, err = UnmarshalString(`\\`)430 so(err, isErr)431 })432 cv("no start chars", func() {433 _, err = UnmarshalString(` `)434 so(err, isErr)435 })436 cv("illegal float number", func() {437 _, err = UnmarshalString(`1.a`)438 so(err, isErr)439 _, err = UnmarshalString(`1.`)440 so(err, isErr)441 _, err = UnmarshalString(`.1`)442 so(err, isErr)443 })444 cv("illegal negative interger", func() {445 _, err = UnmarshalString(`-1a`)446 so(err, isErr)447 })448 cv("illegal positive interger", func() {449 _, err = UnmarshalString(`11a`)450 so(err, isErr)451 })452 cv("illegal true", func() {453 _, err = UnmarshalString(`trUE`)454 so(err, isErr)455 })456 cv("illegal false", func() {457 _, err = UnmarshalString(`fAlse`)458 so(err, isErr)459 })460 cv("illegal null", func() {461 _, err = UnmarshalString(`nUll`)462 so(err, isErr)463 })464 cv("illegal string", func() {465 _, err = UnmarshalString(`"too many quote""`)466 so(err, isErr)467 })468 cv("too short string", func() {469 _, err = UnmarshalString(`"`)470 so(err, isErr)471 })472 cv("illegal escaping", func() {473 _, err = UnmarshalString(`"\"`)474 so(err, isErr)475 })476 cv("illegal bool in object", func() {477 _, err = UnmarshalString(`{"bool":tRue}`)478 so(err, isErr)479 })480 cv("illegal bool in array", func() {481 _, err = UnmarshalString(`[tRue]`)482 so(err, isErr)483 })484 cv("illegal array", func() {485 _, err = UnmarshalString(`["incompleteString]`)486 so(err, isErr)487 })488 cv("illegal array without ]", func() {489 _, err = UnmarshalString(`[ `)490 so(err, isErr)491 })492 cv("illegal object in array without }", func() {493 _, err = UnmarshalString(`[{ ]`)494 so(err, isErr)495 })496 cv("illegal array in array without ]", func() {497 _, err = UnmarshalString(`[[ 224 ]`)498 so(err, isErr)499 })500 cv("another illegal array in array without ]", func() {501 _, err = UnmarshalString(`[ [ `)502 so(err, isErr)503 })504 cv("illegal number in array without ]", func() {505 _, err = UnmarshalString(`[224.. ]`)506 so(err, isErr)507 })508 cv("illegal number in array without decimal part", func() {509 _, err = UnmarshalString(`[224.]`)510 so(err, isErr)511 })512 cv("another illegal number in array without ]", func() {513 _, err = UnmarshalString(`[-18446744073709551615 ]`)514 so(err, isErr)515 })516 cv("illegal false in array ", func() {517 _, err = UnmarshalString(`[fASLE ]`)518 so(err, isErr)519 })520 cv("illegal true in array ", func() {521 _, err = UnmarshalString(`[tRUE ]`)522 so(err, isErr)523 })524 cv("illegal null in array ", func() {525 _, err = UnmarshalString(`[nULL ]`)526 so(err, isErr)527 })528 cv("illegal character in array ", func() {529 _, err = UnmarshalString(`[W]`)530 so(err, isErr)531 })532 cv("marshaling uninitialized value", func() {533 v = &V{}534 _, err = v.MarshalString()535 so(err, isErr)536 _, err = v.Marshal()537 so(err, isErr)538 })539 cv("marshaling with option", func() {540 v = NewObject()541 v.SetNull().At("null")542 raw, _ = v.MarshalString()543 so(raw, eq, `{"null":null}`)544 raw, _ = v.MarshalString(Opt{OmitNull: true})545 so(raw, eq, `{}`)546 raw, _ = v.MarshalString(OptOmitNull(true))547 so(raw, eq, `{}`)548 rawB, _ := v.Marshal(Opt{OmitNull: true})549 so(string(rawB), eq, `{}`)550 rawB, _ = v.Marshal(OptOmitNull(true))551 so(string(rawB), eq, `{}`)552 })553 cv("illegal kvs in object", func() {554 _, err = UnmarshalString(`{true}`) // missing key555 so(err, isErr)556 _, err = UnmarshalString(`{:"value"}`) // missing key557 so(err, isErr)558 _, err = UnmarshalString(`{"key" true}`) // missing colon559 so(err, isErr)560 _, err = UnmarshalString(`{"key":}`) // missing value561 so(err, isErr)562 _, err = UnmarshalString(`{"key":"value" `) // missing }563 so(err, isErr)564 _, err = UnmarshalString(`{"key":"value"`) // missing }565 so(err, isErr)566 _, err = UnmarshalString(`{"key":,}`) // missing value567 so(err, isErr)568 _, err = UnmarshalString(`{"key"::"value"}`) // duplicate colon569 so(err, isErr)570 _, err = UnmarshalString(`{{}}`) // missing key571 so(err, isErr)572 _, err = UnmarshalString(`{"object":{ILLEGAL}}`) // invalid object in object573 so(err, isErr)574 _, err = UnmarshalString(`{"array":[ILLEGAL]}`) // invalid array in object575 so(err, isErr)576 _, err = UnmarshalString(`{[]}`) // missing key577 so(err, isErr)578 _, err = UnmarshalString(`{[}`) // missing ]579 so(err, isErr)580 _, err = UnmarshalString(`{12345}`) // missing key581 so(err, isErr)582 _, err = UnmarshalString(`{"big_int":-18446744073709551615}`) // missing key583 so(err, isErr)584 _, err = UnmarshalString(`{"key" "value"}`) // missing colon585 so(err, isErr)586 _, err = UnmarshalString(`{"key":"\"}`) // invalid string in object587 so(err, isErr)588 _, err = UnmarshalString(`{"key\u":"value"}`) // invalid key in object589 so(err, isErr)590 _, err = UnmarshalString(`{false}`) // missing key591 so(err, isErr)592 _, err = UnmarshalString(`{"false":fAlse}`) // illegal value593 so(err, isErr)594 _, err = UnmarshalString(`{null}`) // missing key595 so(err, isErr)596 _, err = UnmarshalString(`{"null":nUll}`) // illegal value597 so(err, isErr)598 _, err = UnmarshalString(`{true}`) // missing key599 so(err, isErr)600 _, err = UnmarshalString(`{"true":tRue}`) // illegal value601 so(err, isErr)602 })603}...

Full Screen

Full Screen

equal_test.go

Source:equal_test.go Github

copy

Full Screen

1package jsonvalue2import (3 "fmt"4 "testing"5)6func testEqual(t *testing.T) {7 cv("test simple types", func() { testEqualSimpleTypes(t) })8 cv("test number type", func() { testEqualNumbers(t) })9 cv("test object type", func() { testEqualObject(t) })10 cv("test array type", func() { testEqualArray(t) })11}12func testEqualSimpleTypes(t *testing.T) {13 cv("invalid type", func() {14 var v1, v2 *V15 so(v1.Equal(v2), isFalse)16 v1 = &V{}17 so(v1.Equal(v2), isFalse)18 v2 = &V{}19 so(v1.Equal(v2), isFalse)20 })21 cv("string", func() {22 v1 := New("Hello!")23 v2 := New("Hello")24 so(v1.Equal(v2), isFalse)25 v2 = New(v2.String() + "!")26 so(v1.Equal(v2), isTrue)27 })28 cv("boolean", func() {29 v1 := New(true)30 v2 := New(false)31 so(v1.Equal(v2), isFalse)32 v2 = New(true)33 so(v1.Equal(v2), isTrue)34 v1 = New(false)35 so(v1.Equal(v2), isFalse)36 v2 = New(false)37 so(v1.Equal(v2), isTrue)38 })39 cv("null", func() {40 v1 := New(nil)41 v2 := New(nil)42 so(v1.Equal(v2), isTrue)43 })44 cv("diff type", func() {45 v1 := NewObject()46 v2 := NewArray()47 so(v1.Equal(v2), isFalse)48 })49}50func testEqualNumbers(t *testing.T) {51 cv("float", func() {52 longFloat := fmt.Sprintf("%.30f", 20.20)53 v1, err := UnmarshalString(longFloat)54 so(err, isNil)55 v2 := New(20.20)56 t.Log("float:", longFloat)57 t.Log("v1:", v1)58 t.Log("v2:", v2)59 so(string(v1.srcByte), eq, longFloat)60 so(v1.String(), eq, longFloat)61 so(v1.String(), ne, v2.String())62 so(v1.Equal(v2), isFalse)63 v1 = New(20.20)64 so(v1.Equal(v2), isTrue)65 })66 cv("positive int", func() {67 v1 := MustUnmarshalString("10.0")68 v2 := MustUnmarshalString("10")69 so(v1.Equal(v2), isTrue)70 })71}72func testEqualObject(t *testing.T) {73 cv("general", func() {74 v1 := MustUnmarshalString(`{"obj":{},"arr":[]}`)75 v2 := MustUnmarshalString(`{"arr":[],"obj":{}}`)76 so(v1.Equal(v2), isTrue)77 v1 = MustUnmarshalString(`{"num":-1.0}`)78 v2 = MustUnmarshalString(`{"num":-1}`)79 so(v1.Equal(v2), isTrue)80 v1 = MustUnmarshalString(`{"obj":{"msg":"Hello, world!"}}`)81 v2 = MustUnmarshalString(`{"obj":{"msg":"Hello, world!"}}`)82 so(v1.Equal(v2), isTrue)83 v1 = MustUnmarshalString(`{"obj":{"msg":"Hello, world!"}}`)84 v2 = MustUnmarshalString(`{"obj":{"Msg":"Hello, world!"}}`)85 so(v1.Equal(v2), isFalse)86 v1 = MustUnmarshalString(`{"int":0,"str":""}`)87 v2 = MustUnmarshalString(`{"int":0}`)88 so(v1.Equal(v2), isFalse)89 })90}91func testEqualArray(t *testing.T) {92 cv("general", func() {93 v1 := MustUnmarshalString(`[1,2,3,4]`)94 v2 := MustUnmarshalString(`[1,2,3,4.0]`)95 so(v1.Equal(v2), isTrue)96 v1 = MustUnmarshalString(`[{"msg":"Hello, world"},2,3,4]`)97 v2 = MustUnmarshalString(`[{"msg":"Hello, world"},2,3,4]`)98 so(v1.Equal(v2), isTrue)99 v1 = MustUnmarshalString(`[{"msg":"Hello, world"},2,3,4]`)100 v2 = MustUnmarshalString(`[{"Msg":"Hello, world"},2,3,4]`)101 so(v1.Equal(v2), isFalse)102 v1 = MustUnmarshalString(`[2,{"msg":"Hello, world"},3,4]`)103 v2 = MustUnmarshalString(`[{"msg":"Hello, world"},2,3,4]`)104 so(v1.Equal(v2), isFalse)105 v1 = MustUnmarshalString(`[0,0]`)106 v2 = MustUnmarshalString(`[0]`)107 so(v1.Equal(v2), isFalse)108 })109}...

Full Screen

Full Screen

IsTrue

Using AI Code Generation

copy

Full Screen

1import (2func Walk(t *tree.Tree, ch chan int) {3 if t.Left != nil {4 Walk(t.Left, ch)5 }6 if t.Right != nil {7 Walk(t.Right, ch)8 }9}10func Same(t1, t2 *tree.Tree) bool {11 ch1 := make(chan int)12 ch2 := make(chan int)13 go Walk(t1, ch1)14 go Walk(t2, ch2)15 for i := 0; i < 10; i++ {16 if <-ch1 != <-ch2 {17 }18 }19}20func main() {21 fmt.Println(Same(tree.New(1), tree.New(1)))22 fmt.Println(Same(tree.New(1), tree.New(2)))23}

Full Screen

Full Screen

IsTrue

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(test.IsTrue("Hello World"))4}5import (6func main() {7 fmt.Println(test.IsTrue("Hello World"))8}9func IsTrue(str string) bool {10 if str == "Hello World" {11 }12}13func IsTrue(str string) bool {14 if str == "Hello World" {15 }16}17func IsTrue(str string) bool {18 if str == "Hello World" {19 }20}21func IsTrue(str string) bool {22 if str == "Hello World" {23 }24}25func IsTrue(str string) bool {26 if str == "Hello World" {27 }28}29func IsTrue(str string) bool {30 if str == "Hello World" {31 }32}33func IsTrue(str string) bool {34 if str == "Hello World" {35 }36}37func IsTrue(str string) bool {38 if str == "Hello World" {39 }40}41func IsTrue(str string) bool {42 if str == "Hello World" {43 }44}

Full Screen

Full Screen

IsTrue

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(test.IsTrue("true"))4 fmt.Println(test.IsTrue("false"))5}6Go has a very simple, clean and concise way to import packages. There is no need to use the keywords import, public, private, protected, static or final. Go has a very simple, clean and concise way to import packages. There is no need to use the keywords import, public, private, protected,

Full Screen

Full Screen

IsTrue

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var t = new(testing.T)4 t.Log("Log message")5 t.Error("Error message")6 t.Fatal("Fatal message")7 t.Fail()8 fmt.Println(t.Failed())9 t.FailNow()10 t.Log("Log message")11}12import (13func main() {14 var t = new(testing.T)15 t.Log("Log message")16 t.Error("Error message")17 t.Fatal("Fatal message")18 t.Fail()19 fmt.Println(t.Failed())20 t.FailNow()21 t.Log("Log message")22}23import (24func main() {25 var t = new(testing.T)26 t.Log("Log message")27 t.Error("Error message")28 t.Fatal("Fatal message")29 t.Fail()30 fmt.Println(t.Failed())31 t.FailNow()32 t.Log("Log message")33}34import (35func main() {36 var t = new(testing.T)37 t.Log("Log message")38 t.Error("Error message")39 t.Fatal("Fatal message")40 t.Fail()41 fmt.Println(t.Failed())42 t.FailNow()43 t.Log("Log message")44}45import (46func main() {47 var t = new(testing.T)48 t.Log("Log message")49 t.Error("Error message")50 t.Fatal("Fatal message")51 t.Fail()52 fmt.Println(t.Failed())53 t.FailNow()54 t.Log("Log message")55}56import (57func main() {58 var t = new(testing.T)59 t.Log("Log message")60 t.Error("Error message")61 t.Fatal("Fatal message")62 t.Fail()63 fmt.Println(t.Failed())64 t.FailNow()65 t.Log("

Full Screen

Full Screen

IsTrue

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(test.IsTrue())4}5if test.IsTrue() {6 fmt.Println("true")7} else {8 fmt.Println("false")9}

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