How to use updateCommits method of main Package

Best Syzkaller code snippet using main.updateCommits

exists_test.go

Source:exists_test.go Github

copy

Full Screen

1package api2import (3 "context"4 "strconv"5 "testing"6 "github.com/google/go-cmp/cmp"7 bundles "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/bundles/client"8 bundlemocks "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/bundles/client/mocks"9 gitservermocks "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/gitserver/mocks"10 "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/store"11 storemocks "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/store/mocks"12)13func TestFindClosestDumps(t *testing.T) {14 mockStore := storemocks.NewMockStore()15 mockBundleManagerClient := bundlemocks.NewMockBundleManagerClient()16 mockBundleClient1 := bundlemocks.NewMockBundleClient()17 mockBundleClient2 := bundlemocks.NewMockBundleClient()18 mockBundleClient3 := bundlemocks.NewMockBundleClient()19 mockBundleClient4 := bundlemocks.NewMockBundleClient()20 mockGitserverClient := gitservermocks.NewMockClient()21 setMockStoreFindClosestDumps(t, mockStore, 42, testCommit, "s1/main.go", true, "idx", []store.Dump{22 {ID: 50, Root: "s1/"},23 {ID: 51, Root: "s1/"},24 {ID: 52, Root: "s1/"},25 {ID: 53, Root: "s2/"},26 })27 setMockBundleManagerClientBundleClient(t, mockBundleManagerClient, map[int]bundles.BundleClient{28 50: mockBundleClient1,29 51: mockBundleClient2,30 52: mockBundleClient3,31 53: mockBundleClient4,32 })33 setMockBundleClientExists(t, mockBundleClient1, "main.go", true)34 setMockBundleClientExists(t, mockBundleClient2, "main.go", false)35 setMockBundleClientExists(t, mockBundleClient3, "main.go", true)36 setMockBundleClientExists(t, mockBundleClient4, "s1/main.go", false)37 // Set a different tip commit38 mockGitserverClient.HeadFunc.SetDefaultReturn(makeCommit(30), nil)39 // Return some ancestors for each commit args40 mockGitserverClient.CommitsNearFunc.SetDefaultHook(func(ctx context.Context, store store.Store, repositoryID int, commit string) (map[string][]string, error) {41 offset, err := strconv.ParseInt(commit, 10, 64)42 if err != nil {43 return nil, err44 }45 commits := map[string][]string{}46 for i := 0; i < 10; i++ {47 commits[makeCommit(int(offset)+i)] = []string{makeCommit(int(offset) + i + 1)}48 }49 return commits, nil50 })51 api := testAPI(mockStore, mockBundleManagerClient, mockGitserverClient)52 dumps, err := api.FindClosestDumps(context.Background(), 42, testCommit, "s1/main.go", true, "idx")53 if err != nil {54 t.Fatalf("unexpected error finding closest dumps: %s", err)55 }56 expected := []store.Dump{57 {ID: 50, Root: "s1/"},58 {ID: 52, Root: "s1/"},59 }60 if diff := cmp.Diff(expected, dumps); diff != "" {61 t.Errorf("unexpected dumps (-want +got):\n%s", diff)62 }63 expectedCommits := map[string][]string{}64 for i := 0; i < 10; i++ {65 expectedCommits[makeCommit(i)] = []string{makeCommit(i + 1)}66 }67 if len(mockStore.UpdateCommitsFunc.History()) != 1 {68 t.Errorf("unexpected number of update UpdateCommits calls. want=%d have=%d", 1, len(mockStore.UpdateCommitsFunc.History()))69 } else if diff := cmp.Diff(expectedCommits, mockStore.UpdateCommitsFunc.History()[0].Arg2); diff != "" {70 t.Errorf("unexpected update UpdateCommitsFunc args (-want +got):\n%s", diff)71 }72 if len(mockStore.UpdateDumpsVisibleFromTipFunc.History()) != 1 {73 t.Errorf("unexpected number of UpdateDumpsVisibleFromTip calls. want=%d have=%d", 1, len(mockStore.UpdateDumpsVisibleFromTipFunc.History()))74 } else if mockStore.UpdateDumpsVisibleFromTipFunc.History()[0].Arg1 != 42 {75 t.Errorf("unexpected value for repository id. want=%d have=%d", 42, mockStore.UpdateDumpsVisibleFromTipFunc.History()[0].Arg1)76 } else if mockStore.UpdateDumpsVisibleFromTipFunc.History()[0].Arg2 != makeCommit(30) {77 t.Errorf("unexpected value for tip commit. want=%s have=%s", makeCommit(30), mockStore.UpdateDumpsVisibleFromTipFunc.History()[0].Arg2)78 }79}80func TestFindClosestSkipsGitserverIfCommitIsKnown(t *testing.T) {81 mockStore := storemocks.NewMockStore()82 mockBundleManagerClient := bundlemocks.NewMockBundleManagerClient()83 mockBundleClient := bundlemocks.NewMockBundleClient()84 mockGitserverClient := gitservermocks.NewMockClient()85 setMockStoreHasCommit(t, mockStore, 42, testCommit, true)86 setMockStoreFindClosestDumps(t, mockStore, 42, testCommit, "main.go", true, "idx", []store.Dump{87 {ID: 50, Root: ""},88 })89 setMockBundleManagerClientBundleClient(t, mockBundleManagerClient, map[int]bundles.BundleClient{90 50: mockBundleClient,91 })92 setMockBundleClientExists(t, mockBundleClient, "main.go", true)93 api := New(mockStore, mockBundleManagerClient, mockGitserverClient)94 dumps, err := api.FindClosestDumps(context.Background(), 42, testCommit, "main.go", true, "idx")95 if err != nil {96 t.Fatalf("unexpected error finding closest dumps: %s", err)97 }98 expected := []store.Dump{{ID: 50, Root: ""}}99 if diff := cmp.Diff(expected, dumps); diff != "" {100 t.Errorf("unexpected dumps (-want +got):\n%s", diff)101 }102 if len(mockGitserverClient.CommitsNearFunc.History()) != 0 {103 t.Errorf("expected gitserverClient.CommitsNear not to be called")104 }105}...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "flag"4 "fmt"5 "log"6 "path/filepath"7 "strings"8 "time"9 "github.com/synw/ghobserver/activity"10 "github.com/synw/ghobserver/conf"11 "github.com/synw/ghobserver/db"12 "github.com/synw/ghobserver/exe"13 "github.com/synw/ghobserver/server"14 "github.com/synw/terr"15)16var initDb = flag.Bool("db", false, "Initialize the database and exit")17var httpServerOnly = flag.Bool("s", false, "Run the http server only")18var dev = flag.Bool("d", false, "Run in developement mode")19var noUpdate = flag.Bool("nu", false, "Do not update data from api")20func main() {21 flag.Parse()22 pypath, tr := exe.GetPath()23 if tr != nil {24 tr.Fatal(tr.Error())25 }26 staticPath := pypath + "/static"27 templatesPath := pypath + "/templates"28 localpath, _ := filepath.Abs("./")29 dbpath := localpath + "/ghobserver.db"30 db.Init(dbpath)31 username, pwd, apikey, repositories, externalRepositories, err := conf.GetConf()32 if err != nil {33 log.Fatal(err)34 /*tr.Print()35 fmt.Println("ERR " + tr.Error())36 tr.Add("Can not get conf")37 tr.Check()*/38 return39 }40 // internal repos41 user, tr := db.GetOrCreateUser(username)42 if tr != nil {43 tr.Fatal(tr.Error())44 }45 db.CheckRepos(repositories, user, dbpath, apikey)46 if *initDb == true {47 log.Print("Done")48 return49 }50 var exrep = make(map[string][]string)51 // get external repos52 for _, addr := range externalRepositories {53 li := strings.Split(addr, "/")54 u := li[0]55 rep := li[1]56 _, has := exrep[u]57 if has {58 exrep[u] = append(exrep[u], rep)59 } else {60 exrep[u] = []string{rep}61 }62 }63 // process external repos64 for u, reps := range exrep {65 exuser, tr := db.GetOrCreateUser(u)66 if tr != nil {67 tr.Fatal(tr.Error())68 }69 db.CheckRepos(reps, exuser, dbpath, apikey)70 }71 // update loop72 if *httpServerOnly == false {73 go update(pypath, dbpath, apikey, *noUpdate, user, pwd, staticPath)74 }75 // http76 server.StartHttp(templatesPath, staticPath, *dev)77}78func update(pypath string, dbpath string, apikey string, noUpdate bool, user *db.User, pwd string, staticPath string) {79 for {80 if noUpdate == false {81 // update activity82 activity.Update(user, pwd, staticPath)83 // update repos84 log.Print("Updating commits data ...")85 msg, tr := exe.UpdateCommits(pypath, dbpath, apikey)86 if tr != nil {87 tr.Check()88 }89 if msg != "ok" {90 fmt.Println(msg)91 }92 }93 // run data pipeline94 updateList, tr := db.GetDashboardsToUpdate()95 if tr != nil {96 tr.Add("Can not get dashboards to udpate")97 tr.Fatal(tr.Error())98 }99 if len(updateList) == 0 {100 log.Print("Nothing changed")101 } else {102 // update dashboards103 var strli string104 for _, reponame := range updateList {105 strli = strli + " " + reponame106 }107 log.Print("Updating dashboard for" + strli)108 msg, tr := exe.RunPipeline(pypath, dbpath)109 if tr != nil {110 tr.Check()111 }112 if msg != "ok" {113 tr := terr.New("Error running the data pipeline:\n" + msg)114 tr.Fatal(tr.Error())115 }116 log.Print("Dashboard updated")117 }118 //}119 time.Sleep(10 * time.Minute)120 }121}...

Full Screen

Full Screen

utils.go

Source:utils.go Github

copy

Full Screen

1package main2import (3 "time"4 "github.com/NicoNex/covidtron-19000/c19"5 "github.com/NicoNex/covidtron-19000/cache"6 "github.com/NicoNex/covidtron-19000/vax"7 "github.com/NicoNex/echotron/v3"8)9func generateKeyboard(values []string) (kbd [][]echotron.KeyboardButton) {10 for i, v := range values {11 if i%2 == 0 {12 kbd = append(kbd, []echotron.KeyboardButton{})13 }14 kbd[len(kbd)-1] = append(kbd[len(kbd)-1], echotron.KeyboardButton{Text: v})15 }16 return append(kbd, cancelBtn)17}18func extractText(update *echotron.Update) string {19 if update.Message != nil {20 return update.Message.Text21 } else if update.EditedMessage != nil {22 return update.EditedMessage.Text23 }24 return ""25}26func isMaster(chatID int64) bool {27 for _, i := range masters {28 if i == chatID {29 return true30 }31 }32 return false33}34func getMainKbd(chatID int64) [][]echotron.KeyboardButton {35 if isMaster(chatID) {36 return append(mainKbd, masterKbd)37 }38 return mainKbd39}40func ticker(tch <-chan time.Time) {41 for t := range tch {42 if t.Hour() >= 16 && t.Hour() <= 19 {43 updateData()44 }45 }46}47func updateData() {48 cc = cache.LoadCache(BOT_NAME)49 latest := cc.UpdateCommits()50 saved := cc.GetCommits()51 if saved.C19 != latest.C19 {52 c19.Update()53 }54 if saved.Vax != latest.Vax {55 vax.Update()56 }57 cc.SaveCommits(latest)58}...

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