How to use expectTrue method of main Package

Best Syzkaller code snippet using main.expectTrue

authenticator_test.go

Source:authenticator_test.go Github

copy

Full Screen

1package main2import (3 "encoding/csv"4 "io/ioutil"5 "log"6 "os"7 "regexp"8 "syscall"9 "testing"10 "time"11)12const (13 keepGeneratedFiles = false // useful for debugging.14)15func ExpectTrue(t *testing.T, condition bool, message string) {16 if !condition {17 t.Errorf("Expected to succeed, but didn't: %s", message)18 }19}20func ExpectFalse(t *testing.T, condition bool, message string) {21 if condition {22 t.Errorf("Expected to fail, but didn't: %s", message)23 }24}25func ExpectResult(t *testing.T, auth AuthResult, msg string,26 expected_auth AuthResult, expected_re string, fail_prefix string) {27 matcher := regexp.MustCompile(expected_re)28 matches := matcher.MatchString(msg)29 if !matches {30 t.Errorf("%s: Expected '%s' to match '%s'",31 fail_prefix, msg, expected_re)32 }33 if auth != expected_auth {34 t.Errorf("%s: Expected %d, got %d", fail_prefix, expected_auth, auth)35 }36}37// Looks like I can't pass output of multiple return function as parameter-tuple.38// So doing this manually here.39func ExpectAuthResult(t *testing.T, auth Authenticator,40 code string, target Target,41 expected_auth AuthResult, expected_re string) {42 auth_result, msg := auth.AuthUser(code, target)43 ExpectResult(t, auth_result, msg, expected_auth, expected_re,44 code+","+string(target))45}46// Strip message from bool/string tuple and just return the bool47func eatmsg(ok bool, msg string) bool {48 if msg != "" {49 log.Printf("TEST: ignore msg '%s'", msg)50 }51 return ok52}53// File based authenticator we're working with. Seeded with one root-user54func CreateSimpleFileAuth(authFile *os.File, clock Clock) Authenticator {55 // Seed with one member56 authFile.WriteString("# Comment\n")57 authFile.WriteString("# This is a comment,with,multi,comma,foo,bar,x\n")58 rootUser := User{59 Name: "root",60 ContactInfo: "root@nb",61 UserLevel: "member"}62 rootUser.SetAuthCode("root123")63 writer := csv.NewWriter(authFile)64 rootUser.WriteCSV(writer)65 writer.Flush()66 authFile.Close()67 auth := NewFileBasedAuthenticator(authFile.Name(), NewApplicationBus())68 auth.clock = clock69 return auth70}71func TestAddUser(t *testing.T) {72 authFile, _ := ioutil.TempFile("", "test-add-user")73 auth := CreateSimpleFileAuth(authFile, RealClock{})74 if !keepGeneratedFiles {75 defer syscall.Unlink(authFile.Name())76 }77 found := auth.FindUser("doe123")78 ExpectTrue(t, found == nil, "Didn't expect non-existent code to work")79 u := User{80 Name: "Jon Doe",81 UserLevel: LevelUser}82 //ExpectFalse(t, u.SetAuthCode("short"), "Adding too short code")83 ExpectFalse(t, u.SetAuthCode("sho"), "Adding too short code")84 ExpectTrue(t, u.SetAuthCode("doe123"), "Adding long enough auth code")85 // Can't add with bogus member86 ExpectFalse(t, eatmsg(auth.AddNewUser("non-existent member", u)),87 "Adding new user with non-existent code.")88 // Proper member adding user.89 ExpectTrue(t, eatmsg(auth.AddNewUser("root123", u)),90 "Add user with valid member account")91 // Now, freshly added, we should be able to find the user.92 found = auth.FindUser("doe123")93 if found == nil || found.Name != "Jon Doe" {94 t.Errorf("Didn't find user for code")95 }96 // Let's attempt to set a user with the same code97 ExpectFalse(t, eatmsg(auth.AddNewUser("root123", u)),98 "Adding user with code already in use.")99 u.Name = "Another,user;[]funny\"characters '" // Stress-test CSV :)100 u.SetAuthCode("other123")101 ExpectTrue(t, eatmsg(auth.AddNewUser("root123", u)),102 "Adding another user with unique code.")103 u.Name = "ExpiredUser"104 u.SetAuthCode("expired123")105 u.ValidTo = time.Now().Add(-1 * time.Hour)106 ExpectTrue(t, eatmsg(auth.AddNewUser("root123", u)), "Adding user")107 // Attempt to add a user with a non-member auth code108 u.Name = "Shouldnotbeadded"109 u.SetAuthCode("shouldfail")110 ExpectFalse(t, eatmsg(auth.AddNewUser("doe123", u)),111 "John Doe may not add users")112 // Permission testing: see if regular users or philanthropist can113 // add users (which they shouldn't)114 // Let's add an Philanthropist as well.115 u.Name = "Joe Philanthropist"116 u.UserLevel = LevelPhilanthropist117 u.SetAuthCode("phil123")118 auth.AddNewUser("root123", u)119 // Permission testing:120 ExpectFalse(t, eatmsg(auth.AddNewUser("doe123", u)),121 "Attempt to add user by non-member")122 ExpectFalse(t, eatmsg(auth.AddNewUser("phil123", u)),123 "Attempt to add user by non-member")124 // Ok, now let's see if an new authenticator can make sense of the125 // file we appended to.126 auth = NewFileBasedAuthenticator(authFile.Name(), NewApplicationBus())127 ExpectTrue(t, auth.FindUser("root123") != nil, "Finding root123")128 ExpectTrue(t, auth.FindUser("doe123") != nil, "Finding doe123")129 ExpectTrue(t, auth.FindUser("other123") != nil, "Finding other123")130 ExpectTrue(t, auth.FindUser("expired123") != nil, "Finding expired123")131}132func TestUpdateUser(t *testing.T) {133 authFile, _ := ioutil.TempFile("", "test-update-user")134 auth := CreateSimpleFileAuth(authFile, RealClock{})135 if !keepGeneratedFiles {136 defer syscall.Unlink(authFile.Name())137 }138 u := User{139 Name: "Jon Doe",140 UserLevel: LevelUser}141 u.SetAuthCode("doe123")142 auth.AddNewUser("root123", u)143 u.Name = "Unchanged User"144 u.SetAuthCode("unchanged123")145 auth.AddNewUser("root123", u)146 u.Name = "Jon Philanthropist"147 u.UserLevel = LevelPhilanthropist148 u.SetAuthCode("phil123")149 auth.AddNewUser("root123", u)150 ExpectTrue(t, auth.FindUser("doe123") != nil, "Old doe123")151 ExpectTrue(t, auth.FindUser("unchanged123") != nil, "Unchanged User")152 ExpectFalse(t, auth.FindUser("newdoe123") != nil, "Not yet newdoe123")153 // Regular user can't update154 ExpectFalse(t, eatmsg(auth.UpdateUser("doe123", "doe123", func(user *User) bool { return true })),155 "Regular user attempted to update")156 // .. but Philanthropist is allowed.157 ExpectTrue(t, eatmsg(auth.UpdateUser("phil123", "doe123", func(user *User) bool { return true })),158 "Philanthropist should be able to update")159 // Now let the root user modify user identified by doe123160 auth.UpdateUser("root123", "doe123", func(user *User) bool {161 user.SetAuthCode("newdoe123")162 user.ContactInfo = "hello@world"163 return true164 })165 ExpectFalse(t, auth.FindUser("doe123") != nil, "New, doe123 not valid anymore")166 updatedUser := auth.FindUser("newdoe123")167 ExpectTrue(t, updatedUser != nil, "Finding newdoe123")168 ExpectTrue(t, updatedUser.ContactInfo == "hello@world", "Finding newdoe123")169 // This guy should still be there and found.170 ExpectTrue(t, auth.FindUser("unchanged123") != nil, "Unchanged User")171 // Now let's see if everything is properly persisted172 auth = NewFileBasedAuthenticator(authFile.Name(), NewApplicationBus())173 ExpectTrue(t, auth.FindUser("root123") != nil, "Reread: Finding root123")174 ExpectTrue(t, auth.FindUser("unchanged123") != nil, "Reread: Finding unchanged123")175 ExpectTrue(t, auth.FindUser("newdoe123") != nil, "Reread: Finding newdoe123")176 updatedUser = auth.FindUser("newdoe123")177 ExpectTrue(t, updatedUser.ContactInfo == "hello@world", "Reread: contact newdoe123")178}179func TestDeleteUser(t *testing.T) {180 authFile, _ := ioutil.TempFile("", "test-delete-user")181 auth := CreateSimpleFileAuth(authFile, RealClock{})182 if !keepGeneratedFiles {183 defer syscall.Unlink(authFile.Name())184 }185 u := User{186 Name: "Jon Doe",187 UserLevel: LevelUser}188 u.SetAuthCode("doe123")189 auth.AddNewUser("root123", u)190 u.Name = "Unchanged User"191 u.SetAuthCode("unchanged123")192 auth.AddNewUser("root123", u)193 ExpectTrue(t, auth.FindUser("doe123") != nil, "Old doe123")194 ExpectTrue(t, auth.FindUser("unchanged123") != nil, "Unchanged User")195 // Now let the root user delete user identified by doe123196 auth.DeleteUser("root123", "doe123")197 ExpectFalse(t, auth.FindUser("doe123") != nil, "New, doe123 not valid anymore")198 // This guy should still be there and found.199 ExpectTrue(t, auth.FindUser("unchanged123") != nil, "Unchanged User")200 auth = NewFileBasedAuthenticator(authFile.Name(), NewApplicationBus())201 ExpectTrue(t, auth.FindUser("root123") != nil, "Reread: Finding root123")202 ExpectTrue(t, auth.FindUser("unchanged123") != nil, "Reread: Finding unchanged")203 ExpectFalse(t, auth.FindUser("doe123") != nil, "Reread: Finding doe123")204}205func TestTimeLimits(t *testing.T) {206 authFile, _ := ioutil.TempFile("", "timing-tests")207 mockClock := &MockClock{}208 auth := CreateSimpleFileAuth(authFile, mockClock)209 if !keepGeneratedFiles {210 defer syscall.Unlink(authFile.Name())211 }212 someMidnight, _ := time.Parse("2006-01-02", "2014-10-10") // midnight213 nightTime_3h := someMidnight.Add(3 * time.Hour) // 03:00214 earlyMorning_7h := someMidnight.Add(7 * time.Hour) // 09:00215 hackerDaytime_13h := someMidnight.Add(13 * time.Hour) // 16:00216 closingTime_22h := someMidnight.Add(23 * time.Hour) // 22:00217 lateStayUsers_23h := someMidnight.Add(23*time.Hour + 30*time.Minute) // 23:00218 // After 30 days, non-contact users expire.219 // So fast forward 31 days, 16:00 in the afternoon.220 anonExpiry_30d := someMidnight.Add(30*24*time.Hour + 16*time.Hour)221 // We 'register' the users a day before222 mockClock.now = someMidnight.Add(-12 * time.Hour)223 // Adding various users.224 u := User{225 Name: "Some Member",226 ContactInfo: "member@noisebridge.net",227 UserLevel: LevelMember}228 u.SetAuthCode("member123")229 auth.AddNewUser("root123", u)230 u = User{231 Name: "Some User",232 ContactInfo: "user@noisebridge.net",233 UserLevel: LevelUser}234 u.SetAuthCode("user123")235 auth.AddNewUser("root123", u)236 u = User{237 Name: "Some Fulltime User",238 ContactInfo: "ftuser@noisebridge.net",239 UserLevel: LevelFulltimeUser}240 u.SetAuthCode("fulltimeuser123")241 auth.AddNewUser("root123", u)242 u = User{243 Name: "A Philanthropist",244 ContactInfo: "Philanthropist@noisebridge.net",245 UserLevel: LevelPhilanthropist}246 u.SetAuthCode("philanthropist123")247 auth.AddNewUser("root123", u)248 u = User{249 Name: "User on Hiatus",250 ContactInfo: "gone@fishing.net",251 UserLevel: LevelHiatus}252 u.SetAuthCode("hiatus123")253 auth.AddNewUser("root123", u)254 // Member without contact info255 u = User{UserLevel: LevelMember}256 u.SetAuthCode("member_nocontact")257 auth.AddNewUser("root123", u)258 // User without contact info259 u = User{UserLevel: LevelUser}260 u.SetAuthCode("user_nocontact")261 auth.AddNewUser("root123", u)262 mockClock.now = nightTime_3h263 ExpectAuthResult(t, auth, "member123", TargetUpstairs, AuthOk, "")264 ExpectAuthResult(t, auth, "philanthropist123", TargetUpstairs, AuthOk, "")265 ExpectAuthResult(t, auth, "fulltimeuser123", TargetUpstairs,266 AuthOkButOutsideTime, "outside")267 ExpectAuthResult(t, auth, "user123", TargetUpstairs,268 AuthOkButOutsideTime, "outside")269 ExpectAuthResult(t, auth, "member_nocontact", TargetUpstairs, AuthOk, "")270 ExpectAuthResult(t, auth, "user_nocontact", TargetUpstairs,271 AuthOkButOutsideTime, "outside")272 mockClock.now = earlyMorning_7h273 ExpectAuthResult(t, auth, "member123", TargetUpstairs, AuthOk, "")274 ExpectAuthResult(t, auth, "philanthropist123", TargetUpstairs, AuthOk, "")275 ExpectAuthResult(t, auth, "fulltimeuser123", TargetUpstairs, AuthOk, "")276 ExpectAuthResult(t, auth, "user123", TargetUpstairs,277 AuthOkButOutsideTime, "outside")278 ExpectAuthResult(t, auth, "member_nocontact", TargetUpstairs, AuthOk, "")279 ExpectAuthResult(t, auth, "user_nocontact", TargetUpstairs,280 AuthOkButOutsideTime, "outside")281 mockClock.now = hackerDaytime_13h282 ExpectAuthResult(t, auth, "member123", TargetUpstairs, AuthOk, "")283 ExpectAuthResult(t, auth, "philanthropist123", TargetUpstairs, AuthOk, "")284 ExpectAuthResult(t, auth, "fulltimeuser123", TargetUpstairs, AuthOk, "")285 ExpectAuthResult(t, auth, "user123", TargetUpstairs, AuthOk, "")286 ExpectAuthResult(t, auth, "hiatus123", TargetUpstairs,287 AuthFail, "hiatus")288 ExpectAuthResult(t, auth, "member_nocontact", TargetUpstairs, AuthOk, "")289 ExpectAuthResult(t, auth, "user_nocontact", TargetUpstairs, AuthOk, "")290 mockClock.now = closingTime_22h // should behave similar to earlyMorning291 ExpectAuthResult(t, auth, "philanthropist123", TargetUpstairs, AuthOk, "")292 ExpectAuthResult(t, auth, "member123", TargetUpstairs, AuthOk, "")293 ExpectAuthResult(t, auth, "fulltimeuser123", TargetUpstairs, AuthOk, "")294 ExpectAuthResult(t, auth, "user123", TargetUpstairs,295 AuthOkButOutsideTime, "outside")296 ExpectAuthResult(t, auth, "member_nocontact", TargetUpstairs, AuthOk, "")297 ExpectAuthResult(t, auth, "user_nocontact", TargetUpstairs,298 AuthOkButOutsideTime, "outside")299 mockClock.now = lateStayUsers_23h // members, philanthropists, and fulltimeusers left300 ExpectAuthResult(t, auth, "member123", TargetUpstairs, AuthOk, "")301 ExpectAuthResult(t, auth, "philanthropist123", TargetUpstairs, AuthOk, "")302 ExpectAuthResult(t, auth, "fulltimeuser123", TargetUpstairs, AuthOk, "")303 ExpectAuthResult(t, auth, "user123", TargetUpstairs,304 AuthOkButOutsideTime, "outside")305 ExpectAuthResult(t, auth, "member_nocontact", TargetUpstairs, AuthOk, "")306 ExpectAuthResult(t, auth, "user_nocontact", TargetUpstairs,307 AuthOkButOutsideTime, "outside")308 // Automatic expiry of entries that don't have contact info309 mockClock.now = anonExpiry_30d310 ExpectAuthResult(t, auth, "member123", TargetUpstairs, AuthOk, "")311 ExpectAuthResult(t, auth, "philanthropist123", TargetUpstairs, AuthOk, "")312 ExpectAuthResult(t, auth, "fulltimeuser123", TargetUpstairs, AuthOk, "")313 ExpectAuthResult(t, auth, "user123", TargetUpstairs, AuthOk, "")314 ExpectAuthResult(t, auth, "member_nocontact", TargetUpstairs,315 AuthExpired, "Code not valid yet/expired")316 ExpectAuthResult(t, auth, "user_nocontact", TargetUpstairs,317 AuthExpired, "Code not valid yet/expired")318}319func TestHolidayTimeLimits(t *testing.T) {320 authFile, _ := ioutil.TempFile("", "holiday-timing-tests")321 mockClock := &MockClock{}322 auth := CreateSimpleFileAuth(authFile, mockClock)323 if !keepGeneratedFiles {324 defer syscall.Unlink(authFile.Name())325 }326 someMidnight, _ := time.Parse("2006-01-02", "2016-12-24") // midnight327 nightTime_3h := someMidnight.Add(3 * time.Hour) // 03:00328 earlyMorning_7h := someMidnight.Add(7 * time.Hour) // 09:00329 hackerDaytime_13h := someMidnight.Add(13 * time.Hour) // 16:00330 closingTime_22h := someMidnight.Add(23 * time.Hour) // 22:00331 lateStayUsers_23h := someMidnight.Add(23*time.Hour + 30*time.Minute) // 23:00332 // We 'register' the users a day before333 mockClock.now = someMidnight.Add(-12 * time.Hour)334 // Adding various users.335 u := User{336 Name: "Some User",337 ContactInfo: "user@noisebridge.net",338 UserLevel: LevelUser}339 u.SetAuthCode("user123")340 auth.AddNewUser("root123", u)341 mockClock.now = nightTime_3h342 ExpectAuthResult(t, auth, "user123", TargetUpstairs,343 AuthOkButOutsideTime, "outside")344 mockClock.now = earlyMorning_7h345 ExpectAuthResult(t, auth, "user123", TargetUpstairs,346 AuthOkButOutsideTime, "outside")347 mockClock.now = hackerDaytime_13h348 ExpectAuthResult(t, auth, "user123", TargetUpstairs,349 AuthOkButOutsideTime, "holiday")350 mockClock.now = closingTime_22h // should behave similar to earlyMorning351 ExpectAuthResult(t, auth, "user123", TargetUpstairs,352 AuthOkButOutsideTime, "outside")353 mockClock.now = lateStayUsers_23h354 ExpectAuthResult(t, auth, "user123", TargetUpstairs,355 AuthOkButOutsideTime, "outside")356}...

Full Screen

Full Screen

dbbackend_test.go

Source:dbbackend_test.go Github

copy

Full Screen

1package main2import (3 "database/sql"4 "fmt"5 _ "github.com/mattn/go-sqlite3"6 "io/ioutil"7 "log"8 "syscall"9 "testing"10)11func ExpectTrue(t *testing.T, condition bool, message string) {12 if !condition {13 t.Errorf("Expected to succeed, but didn't: %s", message)14 }15}16func TestBasicStore(t *testing.T) {17 dbfile, _ := ioutil.TempFile("", "basic-store")18 defer syscall.Unlink(dbfile.Name())19 db, err := sql.Open("sqlite3", dbfile.Name())20 if err != nil {21 log.Fatal(err)22 }23 store, _ := NewDBBackend(db, true)24 ExpectTrue(t, store.FindById(1) == nil, "Expected id:1 not to exist.")25 // Create record 1, set description26 store.EditRecord(1, func(c *Component) bool {27 c.Description = "foo"28 return true29 })30 ExpectTrue(t, store.FindById(1) != nil, "Expected id:1 to exist now.")31 // Edit it, but decide not to proceed32 store.EditRecord(1, func(c *Component) bool {33 ExpectTrue(t, c.Description == "foo", "Initial value set")34 c.Description = "bar"35 return false // don't commit36 })37 ExpectTrue(t, store.FindById(1).Description == "foo", "Unchanged in second tx")38 // Now change it39 store.EditRecord(1, func(c *Component) bool {40 c.Description = "bar"41 return true42 })43 ExpectTrue(t, store.FindById(1).Description == "bar", "Description change")44}45func TestJoinSets(t *testing.T) {46 dbfile, _ := ioutil.TempFile("", "join-sets")47 defer syscall.Unlink(dbfile.Name())48 db, err := sql.Open("sqlite3", dbfile.Name())49 if err != nil {50 log.Fatal(err)51 }52 store, _ := NewDBBackend(db, true)53 // Three components, each in their own equiv-class54 store.EditRecord(1, func(c *Component) bool { c.Value = "one"; return true })55 store.EditRecord(2, func(c *Component) bool { c.Value = "two"; return true })56 store.EditRecord(3, func(c *Component) bool { c.Value = "three"; return true })57 // Expecting baseline.58 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#1")59 ExpectTrue(t, store.FindById(2).Equiv_set == 2, "#2")60 ExpectTrue(t, store.FindById(3).Equiv_set == 3, "#3")61 // Component 2 join set 3. Final equivalence-set is lowest62 // id of the result set.63 store.JoinSet(2, 3)64 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#4")65 ExpectTrue(t, store.FindById(2).Equiv_set == 2, "#5")66 ExpectTrue(t, store.FindById(3).Equiv_set == 2, "#6")67 // Break out article three out of this set.68 store.LeaveSet(3)69 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#7")70 ExpectTrue(t, store.FindById(2).Equiv_set == 2, "#8")71 ExpectTrue(t, store.FindById(3).Equiv_set == 3, "#9")72 // Join everything together.73 store.JoinSet(3, 1)74 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#10")75 ExpectTrue(t, store.FindById(2).Equiv_set == 2, "#11")76 ExpectTrue(t, store.FindById(3).Equiv_set == 1, "#12")77 store.JoinSet(2, 1)78 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#12")79 ExpectTrue(t, store.FindById(2).Equiv_set == 1, "#13")80 ExpectTrue(t, store.FindById(3).Equiv_set == 1, "#14")81 // Lowest component leaving the set leaves the equivalence set82 // at the lowest of the remaining.83 store.LeaveSet(1)84 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#15")85 ExpectTrue(t, store.FindById(2).Equiv_set == 2, "#16")86 ExpectTrue(t, store.FindById(3).Equiv_set == 2, "#17")87 // If we add lowest again, then the new equiv-set is back to 1.88 store.JoinSet(1, 2)89 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#18")90 ExpectTrue(t, store.FindById(2).Equiv_set == 1, "#19")91 ExpectTrue(t, store.FindById(3).Equiv_set == 1, "#20")92 store.LeaveSet(2)93 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#18")94 ExpectTrue(t, store.FindById(2).Equiv_set == 2, "#19")95 ExpectTrue(t, store.FindById(3).Equiv_set == 1, "#20")96}97func TestLeaveSetRegression(t *testing.T) {98 dbfile, _ := ioutil.TempFile("", "join-sets")99 defer syscall.Unlink(dbfile.Name())100 db, err := sql.Open("sqlite3", dbfile.Name())101 if err != nil {102 log.Fatal(err)103 }104 store, _ := NewDBBackend(db, true)105 // We store components in a slightly different106 // sequence.107 store.EditRecord(2, func(c *Component) bool { c.Value = "two"; return true })108 store.EditRecord(1, func(c *Component) bool { c.Value = "one"; return true })109 store.EditRecord(3, func(c *Component) bool { c.Value = "three"; return true })110 store.JoinSet(2, 1)111 store.JoinSet(3, 1)112 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#1")113 ExpectTrue(t, store.FindById(2).Equiv_set == 1, "#2")114 ExpectTrue(t, store.FindById(3).Equiv_set == 1, "#3")115 // The way LeaveSet() was implemented, it used an SQL in a way that116 // SQLite didn't process correctly wrt. sequence of operations.117 store.LeaveSet(2)118 ExpectTrue(t, store.FindById(1).Equiv_set == 1, "#4")119 ExpectTrue(t, store.FindById(2).Equiv_set == 2, "#5")120 ExpectTrue(t, store.FindById(3).Equiv_set == 1, "#6")121}122func TestQueryEquiv(t *testing.T) {123 dbfile, _ := ioutil.TempFile("", "equiv-query")124 defer syscall.Unlink(dbfile.Name())125 db, err := sql.Open("sqlite3", dbfile.Name())126 if err != nil {127 log.Fatal(err)128 }129 store, _ := NewDBBackend(db, true)130 // Three components, each in their own equiv-class131 store.EditRecord(1, func(c *Component) bool {132 c.Value = "10k"133 c.Category = "Resist"134 return true135 })136 store.EditRecord(2, func(c *Component) bool {137 c.Value = "foo"138 c.Category = "Resist"139 return true140 })141 store.EditRecord(3, func(c *Component) bool {142 c.Value = "three"143 c.Category = "Resist"144 return true145 })146 store.EditRecord(4, func(c *Component) bool {147 c.Value = "10K" // different case, but should work148 c.Category = "Resist"149 return true150 })151 matching := store.MatchingEquivSetForComponent(1)152 ExpectTrue(t, len(matching) == 2, fmt.Sprintf("Expected 2 10k, got %d", len(matching)))153 ExpectTrue(t, matching[0].Id == 1, "#1")154 ExpectTrue(t, matching[1].Id == 4, "#2")155 // Add one component to the set one is in. Even though it does not156 // match the value name, it should show up in the result157 store.JoinSet(2, 1)158 matching = store.MatchingEquivSetForComponent(1)159 ExpectTrue(t, len(matching) == 3, fmt.Sprintf("Expected 3 got %d", len(matching)))160 ExpectTrue(t, matching[0].Id == 1, "#10")161 ExpectTrue(t, matching[1].Id == 2, "#11")162 ExpectTrue(t, matching[2].Id == 4, "#12")163}...

Full Screen

Full Screen

thing_test.go

Source:thing_test.go Github

copy

Full Screen

...46func TestNot(t *testing.T) {47 True := ThingPredicate(func(x Thing) bool { return true })48 False := ThingPredicate(func(x Thing) bool { return false })49 expectFalse := True.Not()50 expectTrue := False.Not()51 if expectFalse(zero) {52 t.Errorf("Not True should not be true")53 }54 if !expectTrue(zero) {55 t.Errorf("Not False should be true")56 }57}...

Full Screen

Full Screen

expectTrue

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 expectTrue(true)4 expectTrue(false)5}6import "fmt"7func expectTrue(b bool) {8 if b {9 fmt.Println("true")10 } else {11 fmt.Println("false")12 }13}14The import keyword is used to import the packages that are defined in other files. The import keyword is used in the following format:15import "path to the package"16In this example, the import keyword is used to import the package that is defined in 1.go. The import keyword is used in the following format:17import "./1"18The ./ is used to specify the path to the package in the same folder. The import keyword can also be used to import packages that are defined in other folders. For example, if the package is defined in the folder named utils, then the import keyword can be used in the following format:19import "utils/1"20The above code will import the package that is defined in the 1.go file present in the utils folder. The import keyword can also be used to import multiple packages. For example, the following code will import the package that is defined in the 1.go file and the package that is defined in the 2.go file:21import (22The import keyword can also be used to import packages that are defined in the same folder. For example, if the package that is defined in 1.go is also used in 2.go, then the import keyword can be used in the following format:23import "./1"24The above code will import the package that is defined in the 1.go file. The import keyword can also be used to import packages that are defined in the same folder. For example, if the package that is defined in 1.go is also used in 2.go, then the import keyword can be used in the following format:25import "./1"26The above code will import the package that is defined in the

Full Screen

Full Screen

expectTrue

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 expectTrue(1 == 1)5 expectTrue(1 == 2)6}7import (8func expectTrue(param interface{}) {9 if !reflect.ValueOf(param).Bool() {10 panic(fmt.Sprintf("Expected true, but got %v", param))11 }12}13import (14func main() {15 fmt.Println("Hello, playground")16 expectTrue(1 == 1)17 expectTrue(1 == 2)18}19import (20func expectTrue(param interface{}) {21 if !reflect.ValueOf(param).Bool() {22 panic(fmt.Sprintf("Expected true, but got %v", param))23 }24}25import (26func main() {27 fmt.Println("Hello, playground")28 expectTrue(1 == 1)29 expectTrue(1 == 2)30}31import (32func expectTrue(param interface{}) {33 if !reflect.ValueOf(param).Bool() {34 panic(fmt.Sprintf("Expected true, but got %v", param))35 }36}37import (38func main() {39 fmt.Println("Hello, playground")40 expectTrue(1 == 1)41 expectTrue(1 == 2)42}43import (44func expectTrue(param interface{}) {45 if !reflect.ValueOf(param).Bool() {46 panic(fmt.Sprintf("Expected true, but got %v", param))47 }48}49import (50func main() {

Full Screen

Full Screen

expectTrue

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello World")4 expectTrue(1 == 1)5 expectTrue(1 == 2)6 fmt.Println("Bye World")7}8import "fmt"9func expectTrue(condition bool) {10 if condition != true {11 panic("Expected true, but was false")12 }13}14main.expectTrue(0x0, 0x0)15main.main()16import "fmt"17func main() {18 fmt.Println("Hello World")19 defer func() {20 if r := recover(); r != nil {21 fmt.Println("Recovered from panic in expectTrue")22 }23 }()24 expectTrue(1 == 1)25 expectTrue(1 == 2)26 fmt.Println("Bye World")27}28import "fmt"29func expectTrue(condition bool) {30 if condition != true {31 panic("Expected true, but was false")32 }33}

Full Screen

Full Screen

expectTrue

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3 fmt.Println("2.go")4 expectTrue(true)5 expectFalse(true)6}7import "fmt"8func main(){9 fmt.Println("1.go")10 expectTrue(true)11 expectFalse(true)12}

Full Screen

Full Screen

expectTrue

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, World!")4 expectTrue(1, 1)5}6import "fmt"7func expectTrue(a, b int) {8 if a != b {9 fmt.Println("Expectation Failed")10 }11}12import "fmt"13func main() {14 fmt.Println("Hello, World!")15}16 C:\Go\src\fmt (from $GOROOT)17 C:\Users\abc\go\src\fmt (from $GOPATH)

Full Screen

Full Screen

expectTrue

Using AI Code Generation

copy

Full Screen

1func main() {2 expectTrue(x < y)3}4func expectTrue(b bool) {5 if !b {6 panic("assertion failed")7 }8}9func main() {10 expectTrue(x < y)11}12func expectTrue(b bool) {13 if !b {14 panic("assertion failed")15 }16}17func main() {18 expectTrue(x < y)19}20func expectTrue(b bool) {21 if !b {22 panic("assertion failed")23 }24}25func main() {26 expectTrue(x < y)27}28func expectTrue(b bool) {29 if !b {30 panic("assertion failed")31 }32}33func main() {34 expectTrue(x < y)35}36func expectTrue(b bool) {37 if !b {38 panic("assertion failed")39 }40}41func main() {42 expectTrue(x < y)43}

Full Screen

Full Screen

expectTrue

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

expectTrue

Using AI Code Generation

copy

Full Screen

1import main2func main() {3 main.expectTrue(true)4}5import main6func main() {7 main.expectFalse(false)8}

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.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful