From 58199a020ef1875060e927f5ca14f0307d46f17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 2 Dec 2019 15:15:50 +0200 Subject: [PATCH 1/4] Refactoring to reduce package count * Consolidate util and utils into the same package * Move internal/onboard into internal/cli/onboard * Move maybeOnboard into the onboard package --- internal/cli/onboard/onboard.go | 156 +++++++++++++++++++++- internal/cli/run/run.go | 3 +- internal/database/models.go | 2 +- internal/log/handlers/cli/cli.go | 8 +- internal/log/handlers/cli/measurements.go | 26 ++-- internal/log/handlers/cli/results.go | 22 +-- internal/onboard/onboard.go | 141 ------------------- internal/output/output.go | 6 +- ooni.go | 15 --- {internal => utils}/shutil/shutil.go | 0 {internal/util => utils}/util_test.go | 2 +- internal/util/util.go => utils/utils.go | 2 +- 12 files changed, 189 insertions(+), 194 deletions(-) delete mode 100644 internal/onboard/onboard.go rename {internal => utils}/shutil/shutil.go (100%) rename {internal/util => utils}/util_test.go (96%) rename internal/util/util.go => utils/utils.go (99%) diff --git a/internal/cli/onboard/onboard.go b/internal/cli/onboard/onboard.go index ddbe97f841..ef55bb927e 100644 --- a/internal/cli/onboard/onboard.go +++ b/internal/cli/onboard/onboard.go @@ -1,14 +1,164 @@ package onboard import ( - "errors" + "fmt" "github.com/alecthomas/kingpin" "github.com/apex/log" + "github.com/fatih/color" + ooni "github.com/ooni/probe-cli" + "github.com/ooni/probe-cli/config" "github.com/ooni/probe-cli/internal/cli/root" - "github.com/ooni/probe-cli/internal/onboard" + "github.com/ooni/probe-cli/internal/output" + "github.com/pkg/errors" + "gopkg.in/AlecAivazis/survey.v1" ) +// Onboarding start the interactive onboarding procedure +func Onboarding(config *config.Config) error { + output.SectionTitle("What is OONI Probe?") + + fmt.Println() + output.Paragraph("Your tool for detecting internet censorship!") + fmt.Println() + output.Paragraph("OONI Probe checks whether your provider blocks access to sites and services. Run OONI Probe to collect evidence of internet censorship and to measure your network performance.") + fmt.Println() + output.PressEnterToContinue("Press 'Enter' to continue...") + + output.SectionTitle("Heads Up") + fmt.Println() + output.Bullet("Anyone monitoring your internet activity (such as your government or ISP) may be able to see that you are running OONI Probe.") + fmt.Println() + output.Bullet("The network data you will collect will automatically be published (unless you opt-out in the settings).") + fmt.Println() + output.Bullet("You may test objectionable sites.") + fmt.Println() + output.Bullet("Read the documentation to learn more.") + fmt.Println() + output.PressEnterToContinue("Press 'Enter' to continue...") + + output.SectionTitle("Pop Quiz!") + output.Paragraph("") + answer := "" + quiz1 := &survey.Select{ + Message: "Anyone monitoring my internet activity may be able to see that I am running OONI Probe.", + Options: []string{"true", "false"}, + Default: "true", + } + survey.AskOne(quiz1, &answer, nil) + if answer != "true" { + output.Paragraph(color.RedString("Actually...")) + output.Paragraph("OONI Probe is not a privacy tool. Therefore, anyone monitoring your internet activity may be able to see which software you are running.") + } else { + output.Paragraph(color.BlueString("Good job!")) + } + answer = "" + quiz2 := &survey.Select{ + Message: "The network data I will collect will automatically be published (unless I opt-out in the settings).", + Options: []string{"true", "false"}, + Default: "true", + } + survey.AskOne(quiz2, &answer, nil) + if answer != "true" { + output.Paragraph(color.RedString("Actually...")) + output.Paragraph("The network data you will collect will automatically be published to increase transparency of internet censorship (unless you opt-out in the settings).") + } else { + output.Paragraph(color.BlueString("Well done!")) + } + + changeDefaults := false + prompt := &survey.Confirm{ + Message: "Do you want to change the default settings?", + Default: false, + } + survey.AskOne(prompt, &changeDefaults, nil) + + settings := struct { + IncludeIP bool + IncludeNetwork bool + IncludeCountry bool + UploadResults bool + SendCrashReports bool + }{} + settings.IncludeIP = false + settings.IncludeNetwork = true + settings.IncludeCountry = true + settings.UploadResults = true + settings.SendCrashReports = true + + if changeDefaults == true { + var qs = []*survey.Question{ + { + Name: "IncludeIP", + Prompt: &survey.Confirm{Message: "Should we include your IP?"}, + }, + { + Name: "IncludeNetwork", + Prompt: &survey.Confirm{ + Message: "Can we include your network name?", + Default: true, + }, + }, + { + Name: "IncludeCountry", + Prompt: &survey.Confirm{ + Message: "Can we include your country name?", + Default: true, + }, + }, + { + Name: "UploadResults", + Prompt: &survey.Confirm{ + Message: "Can we upload your results?", + Default: true, + }, + }, + { + Name: "SendCrashReports", + Prompt: &survey.Confirm{ + Message: "Can we send crash reports to OONI?", + Default: true, + }, + }, + } + + err := survey.Ask(qs, &settings) + if err != nil { + log.WithError(err).Error("there was an error in parsing your responses") + return err + } + } + + config.Lock() + config.InformedConsent = true + config.Sharing.IncludeCountry = settings.IncludeCountry + config.Advanced.SendCrashReports = settings.SendCrashReports + config.Sharing.IncludeIP = settings.IncludeIP + config.Sharing.IncludeASN = settings.IncludeNetwork + config.Sharing.UploadResults = settings.UploadResults + config.Unlock() + + if err := config.Write(); err != nil { + log.WithError(err).Error("failed to write config file") + return err + } + return nil +} + +// MaybeOnboarding will run the onboarding process only if the informed consent +// config option is set to false +func MaybeOnboarding(c *ooni.Context) error { + if c.Config.InformedConsent == false { + if c.IsBatch == true { + return errors.New("cannot run onboarding in batch mode") + } + if err := Onboarding(c.Config); err != nil { + return errors.Wrap(err, "onboarding") + } + } + return nil +} + func init() { cmd := root.Command("onboard", "Starts the onboarding process") @@ -35,6 +185,6 @@ func init() { return errors.New("cannot do onboarding in batch mode") } - return onboard.Onboarding(ctx.Config) + return Onboarding(ctx.Config) }) } diff --git a/internal/cli/run/run.go b/internal/cli/run/run.go index f27aecdaf9..8090180ff6 100644 --- a/internal/cli/run/run.go +++ b/internal/cli/run/run.go @@ -7,6 +7,7 @@ import ( "github.com/apex/log" "github.com/fatih/color" ooni "github.com/ooni/probe-cli" + "github.com/ooni/probe-cli/internal/cli/onboard" "github.com/ooni/probe-cli/internal/cli/root" "github.com/ooni/probe-cli/internal/database" "github.com/ooni/probe-cli/nettests" @@ -66,7 +67,7 @@ func init() { return err } - if err = ctx.MaybeOnboarding(); err != nil { + if err = onboard.MaybeOnboarding(ctx); err != nil { log.WithError(err).Error("failed to perform onboarding") return err } diff --git a/internal/database/models.go b/internal/database/models.go index 8e26de5ffa..6ec6306d66 100644 --- a/internal/database/models.go +++ b/internal/database/models.go @@ -6,7 +6,7 @@ import ( "path/filepath" "time" - "github.com/ooni/probe-cli/internal/shutil" + "github.com/ooni/probe-cli/utils/shutil" "github.com/pkg/errors" "upper.io/db.v3/lib/sqlbuilder" ) diff --git a/internal/log/handlers/cli/cli.go b/internal/log/handlers/cli/cli.go index cd3e97e75d..5bb033af13 100644 --- a/internal/log/handlers/cli/cli.go +++ b/internal/log/handlers/cli/cli.go @@ -11,7 +11,7 @@ import ( "github.com/apex/log" "github.com/fatih/color" colorable "github.com/mattn/go-colorable" - "github.com/ooni/probe-cli/internal/util" + "github.com/ooni/probe-cli/utils" ) // Default handler outputting to stderr. @@ -67,7 +67,7 @@ func logSectionTitle(w io.Writer, f log.Fields) error { title := f.Get("title").(string) fmt.Fprintf(w, "┏"+strings.Repeat("━", colWidth+2)+"┓\n") - fmt.Fprintf(w, "┃ %s ┃\n", util.RightPad(title, colWidth)) + fmt.Fprintf(w, "┃ %s ┃\n", utils.RightPad(title, colWidth)) fmt.Fprintf(w, "┗"+strings.Repeat("━", colWidth+2)+"┛\n") return nil } @@ -84,7 +84,7 @@ func logTable(w io.Writer, f log.Fields) error { continue } line := fmt.Sprintf("%s: %s", color.Sprint(name), f.Get(name)) - lineLength := util.EscapeAwareRuneCountInString(line) + lineLength := utils.EscapeAwareRuneCountInString(line) lines = append(lines, line) if colWidth < lineLength { colWidth = lineLength @@ -94,7 +94,7 @@ func logTable(w io.Writer, f log.Fields) error { fmt.Fprintf(w, "┏"+strings.Repeat("━", colWidth+2)+"┓\n") for _, line := range lines { fmt.Fprintf(w, "┃ %s ┃\n", - util.RightPad(line, colWidth), + utils.RightPad(line, colWidth), ) } fmt.Fprintf(w, "┗"+strings.Repeat("━", colWidth+2)+"┛\n") diff --git a/internal/log/handlers/cli/measurements.go b/internal/log/handlers/cli/measurements.go index a0ed0c7e08..fa27c75498 100644 --- a/internal/log/handlers/cli/measurements.go +++ b/internal/log/handlers/cli/measurements.go @@ -9,7 +9,7 @@ import ( "time" "github.com/apex/log" - "github.com/ooni/probe-cli/internal/util" + "github.com/ooni/probe-cli/utils" ) func statusIcon(ok bool) string { @@ -35,7 +35,7 @@ func logTestKeys(w io.Writer, testKeys string) error { } for _, line := range testKeysLines { fmt.Fprintf(w, fmt.Sprintf("│ %s │\n", - util.RightPad(line, colWidth*2))) + utils.RightPad(line, colWidth*2))) } return nil } @@ -71,22 +71,22 @@ func logMeasurementItem(w io.Writer, f log.Fields) error { failureStr := fmt.Sprintf("success: %s", statusIcon(!isFailed)) fmt.Fprintf(w, fmt.Sprintf("│ %s │\n", - util.RightPad( + utils.RightPad( fmt.Sprintf("#%d", rID), colWidth*2))) if url != "" { fmt.Fprintf(w, fmt.Sprintf("│ %s │\n", - util.RightPad( + utils.RightPad( fmt.Sprintf("%s (%s)", url, urlCategoryCode), colWidth*2))) } fmt.Fprintf(w, fmt.Sprintf("│ %s %s│\n", - util.RightPad(testName, colWidth), - util.RightPad(anomalyStr, colWidth))) + utils.RightPad(testName, colWidth), + utils.RightPad(anomalyStr, colWidth))) fmt.Fprintf(w, fmt.Sprintf("│ %s %s│\n", - util.RightPad(failureStr, colWidth), - util.RightPad(uploadStr, colWidth))) + utils.RightPad(failureStr, colWidth), + utils.RightPad(uploadStr, colWidth))) if testKeys != "" { if err := logTestKeys(w, testKeys); err != nil { @@ -116,15 +116,15 @@ func logMeasurementSummary(w io.Writer, f log.Fields) error { networkName := f.Get("network_name").(string) fmt.Fprintf(w, " │ %s │\n", - util.RightPad(startTime.Format(time.RFC822), (colWidth+3)*3), + utils.RightPad(startTime.Format(time.RFC822), (colWidth+3)*3), ) fmt.Fprintf(w, " │ %s │\n", - util.RightPad(fmt.Sprintf("AS%d, %s (%s)", asn, networkName, countryCode), (colWidth+3)*3), + utils.RightPad(fmt.Sprintf("AS%d, %s (%s)", asn, networkName, countryCode), (colWidth+3)*3), ) fmt.Fprintf(w, " │ %s %s %s │\n", - util.RightPad(fmt.Sprintf("%.2fs", totalRuntime), colWidth), - util.RightPad(fmt.Sprintf("%d/%d anmls", anomalyCount, totalCount), colWidth), - util.RightPad(fmt.Sprintf("⬆ %s ⬇ %s", formatSize(dataUp), formatSize(dataDown)), colWidth+4)) + utils.RightPad(fmt.Sprintf("%.2fs", totalRuntime), colWidth), + utils.RightPad(fmt.Sprintf("%d/%d anmls", anomalyCount, totalCount), colWidth), + utils.RightPad(fmt.Sprintf("⬆ %s ⬇ %s", formatSize(dataUp), formatSize(dataDown)), colWidth+4)) fmt.Fprintf(w, " └────────────────────────────────────────────────┘\n") return nil diff --git a/internal/log/handlers/cli/results.go b/internal/log/handlers/cli/results.go index 2c367aa1fc..f0d9f2a4f6 100644 --- a/internal/log/handlers/cli/results.go +++ b/internal/log/handlers/cli/results.go @@ -9,7 +9,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/internal/database" - "github.com/ooni/probe-cli/internal/util" + "github.com/ooni/probe-cli/utils" ) func formatSpeed(speed float64) string { @@ -95,7 +95,7 @@ func logResultItem(w io.Writer, f log.Fields) error { fmt.Fprintf(w, "┢"+strings.Repeat("━", colWidth*2+2)+"┪\n") } - firstRow := util.RightPad(fmt.Sprintf("#%d - %s", rID, startTime.Format(time.RFC822)), colWidth*2) + firstRow := utils.RightPad(fmt.Sprintf("#%d - %s", rID, startTime.Format(time.RFC822)), colWidth*2) fmt.Fprintf(w, "┃ "+firstRow+" ┃\n") fmt.Fprintf(w, "┡"+strings.Repeat("━", colWidth*2+2)+"┩\n") @@ -105,14 +105,14 @@ func logResultItem(w io.Writer, f log.Fields) error { f.Get("test_keys").(string)) fmt.Fprintf(w, fmt.Sprintf("│ %s %s│\n", - util.RightPad(name, colWidth), - util.RightPad(summary[0], colWidth))) + utils.RightPad(name, colWidth), + utils.RightPad(summary[0], colWidth))) fmt.Fprintf(w, fmt.Sprintf("│ %s %s│\n", - util.RightPad(networkName, colWidth), - util.RightPad(summary[1], colWidth))) + utils.RightPad(networkName, colWidth), + utils.RightPad(summary[1], colWidth))) fmt.Fprintf(w, fmt.Sprintf("│ %s %s│\n", - util.RightPad(asn, colWidth), - util.RightPad(summary[2], colWidth))) + utils.RightPad(asn, colWidth), + utils.RightPad(summary[2], colWidth))) if index == totalCount-1 { if isDone == true { @@ -139,9 +139,9 @@ func logResultSummary(w io.Writer, f log.Fields) error { } // └┬──────────────┬──────────────┬──────────────┬ fmt.Fprintf(w, " │ %s │ %s │ %s │\n", - util.RightPad(fmt.Sprintf("%d tests", tests), 12), - util.RightPad(fmt.Sprintf("%d nets", networks), 12), - util.RightPad(fmt.Sprintf("⬆ %s ⬇ %s", formatSize(dataUp), formatSize(dataDown)), 16)) + utils.RightPad(fmt.Sprintf("%d tests", tests), 12), + utils.RightPad(fmt.Sprintf("%d nets", networks), 12), + utils.RightPad(fmt.Sprintf("⬆ %s ⬇ %s", formatSize(dataUp), formatSize(dataDown)), 16)) fmt.Fprintf(w, " └──────────────┴──────────────┴──────────────────┘\n") return nil diff --git a/internal/onboard/onboard.go b/internal/onboard/onboard.go deleted file mode 100644 index 2144d0da2c..0000000000 --- a/internal/onboard/onboard.go +++ /dev/null @@ -1,141 +0,0 @@ -package onboard - -import ( - "fmt" - - "github.com/apex/log" - "github.com/fatih/color" - "github.com/ooni/probe-cli/config" - "github.com/ooni/probe-cli/internal/output" - survey "gopkg.in/AlecAivazis/survey.v1" -) - -func Onboarding(config *config.Config) error { - output.SectionTitle("What is OONI Probe?") - - fmt.Println() - output.Paragraph("Your tool for detecting internet censorship!") - fmt.Println() - output.Paragraph("OONI Probe checks whether your provider blocks access to sites and services. Run OONI Probe to collect evidence of internet censorship and to measure your network performance.") - fmt.Println() - output.PressEnterToContinue("Press 'Enter' to continue...") - - output.SectionTitle("Heads Up") - fmt.Println() - output.Bullet("Anyone monitoring your internet activity (such as your government or ISP) may be able to see that you are running OONI Probe.") - fmt.Println() - output.Bullet("The network data you will collect will automatically be published (unless you opt-out in the settings).") - fmt.Println() - output.Bullet("You may test objectionable sites.") - fmt.Println() - output.Bullet("Read the documentation to learn more.") - fmt.Println() - output.PressEnterToContinue("Press 'Enter' to continue...") - - output.SectionTitle("Pop Quiz!") - output.Paragraph("") - answer := "" - quiz1 := &survey.Select{ - Message: "Anyone monitoring my internet activity may be able to see that I am running OONI Probe.", - Options: []string{"true", "false"}, - Default: "true", - } - survey.AskOne(quiz1, &answer, nil) - if answer != "true" { - output.Paragraph(color.RedString("Actually...")) - output.Paragraph("OONI Probe is not a privacy tool. Therefore, anyone monitoring your internet activity may be able to see which software you are running.") - } else { - output.Paragraph(color.BlueString("Good job!")) - } - answer = "" - quiz2 := &survey.Select{ - Message: "The network data I will collect will automatically be published (unless I opt-out in the settings).", - Options: []string{"true", "false"}, - Default: "true", - } - survey.AskOne(quiz2, &answer, nil) - if answer != "true" { - output.Paragraph(color.RedString("Actually...")) - output.Paragraph("The network data you will collect will automatically be published to increase transparency of internet censorship (unless you opt-out in the settings).") - } else { - output.Paragraph(color.BlueString("Well done!")) - } - - changeDefaults := false - prompt := &survey.Confirm{ - Message: "Do you want to change the default settings?", - Default: false, - } - survey.AskOne(prompt, &changeDefaults, nil) - - settings := struct { - IncludeIP bool - IncludeNetwork bool - IncludeCountry bool - UploadResults bool - SendCrashReports bool - }{} - settings.IncludeIP = false - settings.IncludeNetwork = true - settings.IncludeCountry = true - settings.UploadResults = true - settings.SendCrashReports = true - - if changeDefaults == true { - var qs = []*survey.Question{ - { - Name: "IncludeIP", - Prompt: &survey.Confirm{Message: "Should we include your IP?"}, - }, - { - Name: "IncludeNetwork", - Prompt: &survey.Confirm{ - Message: "Can we include your network name?", - Default: true, - }, - }, - { - Name: "IncludeCountry", - Prompt: &survey.Confirm{ - Message: "Can we include your country name?", - Default: true, - }, - }, - { - Name: "UploadResults", - Prompt: &survey.Confirm{ - Message: "Can we upload your results?", - Default: true, - }, - }, - { - Name: "SendCrashReports", - Prompt: &survey.Confirm{ - Message: "Can we send crash reports to OONI?", - Default: true, - }, - }, - } - - err := survey.Ask(qs, &settings) - if err != nil { - log.WithError(err).Error("there was an error in parsing your responses") - return err - } - } - - config.Lock() - config.InformedConsent = true - config.Sharing.IncludeCountry = settings.IncludeCountry - config.Advanced.SendCrashReports = settings.SendCrashReports - config.Sharing.IncludeIP = settings.IncludeIP - config.Sharing.IncludeASN = settings.IncludeNetwork - config.Sharing.UploadResults = settings.UploadResults - config.Unlock() - - if err := config.Write(); err != nil { - log.WithError(err).Error("failed to write config file") - return err - } - return nil -} diff --git a/internal/output/output.go b/internal/output/output.go index f5ed02a292..bd92717011 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -8,7 +8,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/internal/database" - "github.com/ooni/probe-cli/internal/util" + "github.com/ooni/probe-cli/utils" ) // MeasurementJSON prints the JSON of a measurement @@ -154,12 +154,12 @@ func SectionTitle(text string) { func Paragraph(text string) { const width = 80 - fmt.Println(util.WrapString(text, width)) + fmt.Println(utils.WrapString(text, width)) } func Bullet(text string) { const width = 80 - fmt.Printf("• %s\n", util.WrapString(text, width)) + fmt.Printf("• %s\n", utils.WrapString(text, width)) } func PressEnterToContinue(text string) { diff --git a/ooni.go b/ooni.go index 58d20eb292..d79922282e 100644 --- a/ooni.go +++ b/ooni.go @@ -10,7 +10,6 @@ import ( "github.com/ooni/probe-cli/internal/database" "github.com/ooni/probe-cli/internal/enginex" "github.com/ooni/probe-cli/internal/legacy" - "github.com/ooni/probe-cli/internal/onboard" "github.com/ooni/probe-cli/utils" "github.com/ooni/probe-cli/version" engine "github.com/ooni/probe-engine" @@ -37,20 +36,6 @@ func (c *Context) MaybeLocationLookup() error { return c.Session.MaybeLookupLocation() } -// MaybeOnboarding will run the onboarding process only if the informed consent -// config option is set to false -func (c *Context) MaybeOnboarding() error { - if c.Config.InformedConsent == false { - if c.IsBatch == true { - return errors.New("cannot run onboarding in batch mode") - } - if err := onboard.Onboarding(c.Config); err != nil { - return errors.Wrap(err, "onboarding") - } - } - return nil -} - // Init the OONI manager func (c *Context) Init() error { var err error diff --git a/internal/shutil/shutil.go b/utils/shutil/shutil.go similarity index 100% rename from internal/shutil/shutil.go rename to utils/shutil/shutil.go diff --git a/internal/util/util_test.go b/utils/util_test.go similarity index 96% rename from internal/util/util_test.go rename to utils/util_test.go index 3a567c7ec7..304be37280 100644 --- a/internal/util/util_test.go +++ b/utils/util_test.go @@ -1,4 +1,4 @@ -package util +package utils import ( "testing" diff --git a/internal/util/util.go b/utils/utils.go similarity index 99% rename from internal/util/util.go rename to utils/utils.go index 7f481427a9..328e4da970 100644 --- a/internal/util/util.go +++ b/utils/utils.go @@ -1,4 +1,4 @@ -package util +package utils import ( "bytes" From cda9a3ee4f2f85a934bafc8b400cb380e17bacea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 2 Dec 2019 15:25:23 +0200 Subject: [PATCH 2/4] Add code coverage integration --- .travis.yml | 2 ++ build.sh | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7bedfbf351..427b40f38d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,5 @@ env: script: - ./build.sh _travis-${TRAVIS_OS_NAME} - ./scripts/travis_test.sh +after_success: +- bash <(curl -s https://codecov.io/bash) diff --git a/build.sh b/build.sh index 9995cd3f42..c9c846e804 100755 --- a/build.sh +++ b/build.sh @@ -51,7 +51,7 @@ elif [ "$1" = "_travis-linux" ]; then set -x $0 linux docker run -v `pwd`:/oonibuild -w /oonibuild -t oonibuild \ - go test -v -coverprofile=ooni.cov ./... + go test -v -coverprofile=coverage.txt -covermode=atomic ./... elif [ "$1" = "_travis-osx" ]; then set -x @@ -60,7 +60,7 @@ elif [ "$1" = "_travis-osx" ]; then brew upgrade brew install measurement-kit $0 macos - go test -v -coverprofile=ooni.cov ./... + go test -v -coverprofile=coverage.txt -covermode=atomic ./... elif [ "$1" = "help" ]; then echo "Usage: $0 linux | macos | release | windows" From a3685ae6b02d748caf6bbff8b97e065daf700812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 2 Dec 2019 15:26:12 +0200 Subject: [PATCH 3/4] Add coverage.txt to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fde82b1183..5ee9870470 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /dist /ooni.cov +/coverage.txt *.njson .DS_Store From 410b7514d7d1f198285725744b47f63f8afe8021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 2 Dec 2019 15:42:14 +0200 Subject: [PATCH 4/4] Use coveralls which is the same thing used in other repos --- .travis.yml | 6 ++++-- build.sh | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 427b40f38d..d9312ebe37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,10 @@ services: - docker env: - OS_NAME: linux +before_script: +- go get golang.org/x/tools/cmd/cover +- go get github.com/mattn/goveralls script: - ./build.sh _travis-${TRAVIS_OS_NAME} +- $GOPATH/bin/goveralls -coverprofile=coverage.cov -service=travis-ci - ./scripts/travis_test.sh -after_success: -- bash <(curl -s https://codecov.io/bash) diff --git a/build.sh b/build.sh index c9c846e804..76757d2d6c 100755 --- a/build.sh +++ b/build.sh @@ -51,7 +51,7 @@ elif [ "$1" = "_travis-linux" ]; then set -x $0 linux docker run -v `pwd`:/oonibuild -w /oonibuild -t oonibuild \ - go test -v -coverprofile=coverage.txt -covermode=atomic ./... + go test -v -coverprofile=coverage.cov -covermode=atomic ./... elif [ "$1" = "_travis-osx" ]; then set -x @@ -60,7 +60,7 @@ elif [ "$1" = "_travis-osx" ]; then brew upgrade brew install measurement-kit $0 macos - go test -v -coverprofile=coverage.txt -covermode=atomic ./... + go test -v -coverprofile=coverage.cov -covermode=atomic ./... elif [ "$1" = "help" ]; then echo "Usage: $0 linux | macos | release | windows"