Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
test against the latest versions of go (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum committed Nov 3, 2022
1 parent 4cf71eb commit 589798d
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 84 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
language: go
go:
- 1.17.x
- 1.19.x
os:
- linux
- osx
before_install:
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
- go get github.com/axw/gocov/gocov
- go get github.com/modocache/gover
- go get github.com/keybase/go-updater/test
- go install github.com/mattn/goveralls@latest
- go install golang.org/x/tools/cmd/cover@latest
- go install github.com/axw/gocov/gocov@latest
- go install github.com/modocache/gover@latest
- go install github.com/keybase/go-updater/test
script:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.43.0
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.0
- golangci-lint run
- go vet ./...
- go test -v -coverprofile=command.coverprofile ./command
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Updater

[![Build Status](https://travis-ci.org/keybase/go-updater.svg?branch=master)](https://travis-ci.org/keybase/go-updater)
[![Build Status](https://app.travis-ci.com/keybase/go-updater.svg?branch=master)](https://app.travis-ci.com/github/keybase/go-updater)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/keybase/go-updater?branch=master&svg=true)](https://ci.appveyor.com/project/keybase/go-updater)
[![Coverage Status](https://coveralls.io/repos/github/keybase/go-updater/badge.svg?branch=master)](https://coveralls.io/github/keybase/go-updater?branch=master)
[![GoDoc](https://godoc.org/github.com/keybase/go-updater?status.svg)](https://godoc.org/github.com/keybase/go-updater)
Expand All @@ -24,7 +24,6 @@ The goals of this library are to provide an updater that:
This updater library is used to support updating (in background and on-demand)
for Keybase apps and services.


### Packages

The main package is the updater core, there are other support packages:
Expand All @@ -41,7 +40,6 @@ The main package is the updater core, there are other support packages:
- watchdog: Utility to monitor processes and restart them (like launchd), for use with updater service
- windows: Windows specific UI


### Development

This library should pass the [gometalinter](https://github.com/alecthomas/gometalinter).
Expand All @@ -55,4 +53,3 @@ gometalinter --install --update
pre-commit install
pre-commit run -a
```

8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clone_folder: c:\gopath\src\github.com\keybase\go-updater

environment:
GOPATH: c:\gopath
GOVERSION: 1.17.x
GOVERSION: 1.19.x

install:
- set PATH=%GOPATH%\bin;C:\go\bin;%PATH%
Expand All @@ -14,9 +14,9 @@ install:
- 7z x go%GOVERSION%.windows-amd64.zip -y -oC:\ > NUL
- go version
- go env
- go get -u github.com/stretchr/testify/assert
- go get -u github.com/stretchr/testify/require
- go get github.com/keybase/go-updater/test
- go install github.com/stretchr/testify/assert@latest
- go install github.com/stretchr/testify/require@latest
- go install github.com/keybase/go-updater/test
- dir %GOPATH%\bin\test.exe /s

build_script:
Expand Down
5 changes: 2 additions & 3 deletions keybase/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package keybase

import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -135,7 +134,7 @@ func TestConfigExtra(t *testing.T) {
}`
path := filepath.Join(os.TempDir(), "TestConfigExtra")
defer util.RemoveFileAtPath(path)
err := ioutil.WriteFile(path, []byte(data), 0644)
err := os.WriteFile(path, []byte(data), 0644)
assert.NoError(t, err)

cfg := newDefaultConfig("", "", testLog, false)
Expand All @@ -159,7 +158,7 @@ func TestConfigBadType(t *testing.T) {
}`
path := filepath.Join(os.TempDir(), "TestConfigBadType")
defer util.RemoveFileAtPath(path)
err := ioutil.WriteFile(path, []byte(data), 0644)
err := os.WriteFile(path, []byte(data), 0644)
assert.NoError(t, err)

cfg := newDefaultConfig("", "", testLog, false)
Expand Down
3 changes: 2 additions & 1 deletion saltpack/saltpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var validCodeSigningKIDs = map[string]bool{
const message1 = "This is a test message\n"

// This is the output of running:
// echo "This is a test message" | keybase sign -d
//
// echo "This is a test message" | keybase sign -d
const signature1 = `BEGIN KEYBASE SALTPACK DETACHED SIGNATURE. kXR7VktZdyH7rvq
v5weRa8moXPeKBe e2YLT0PnyHzCrVi RbC1J5uJtYgYyLW eGg4qzsWqkXuVtJ yTsutKVn8DT97Oe
mnvASPWsbU2VjnR t4EChFoYF1RSi75 MvyyWify9iZldeI 0OTYM5yKLpbCrX5 yD0Tmjf2txwg7Jx
Expand Down
7 changes: 3 additions & 4 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -75,20 +74,20 @@ func echo(s string) {
}

func writeToFile(s string, path string) {
err := ioutil.WriteFile(path, []byte(s), 0700)
err := os.WriteFile(path, []byte(s), 0700)
if err != nil {
log.Fatalf("Error writing to file: %s", err)
}
}

func copyFakeLayout(dst string) {
// Read all content of src to data
data, err := ioutil.ReadFile("winlayout.log")
data, err := os.ReadFile("winlayout.log")
if err != nil {
log.Fatalf("Error reading winlayout.log: %s", err)
}
// Write data to dst
err = ioutil.WriteFile(dst, data, 0644)
err = os.WriteFile(dst, data, 0644)
if err != nil {
log.Fatalf("Error writing to %s: %s", dst, err)
}
Expand Down
5 changes: 2 additions & 3 deletions updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package updater
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -490,7 +489,7 @@ func (u *Updater) CleanupPreviousUpdates() (err error) {
if parent == "" || parent == "." {
return fmt.Errorf("temp directory is '%v'", parent)
}
files, err := ioutil.ReadDir(parent)
files, err := os.ReadDir(parent)
if err != nil {
return fmt.Errorf("listing parent directory: %v", err)
}
Expand Down Expand Up @@ -530,7 +529,7 @@ func (u *Updater) FindDownloadedAsset(assetName string) (matchingAssetPath strin
return matchingAssetPath, fmt.Errorf("temp directory is %v", parent)
}

files, err := ioutil.ReadDir(parent)
files, err := os.ReadDir(parent)
if err != nil {
return matchingAssetPath, fmt.Errorf("listing parent directory: %v", err)
}
Expand Down
11 changes: 5 additions & 6 deletions updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package updater
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"time"

Expand Down Expand Up @@ -736,7 +735,7 @@ func TestFindDownloadedAsset(t *testing.T) {
tmpDir, err = util.MakeTempDir("KeybaseUpdater.", 0700)
assert.NoError(t, err)
tmpFile := filepath.Join(tmpDir, "nottemp")
err = ioutil.WriteFile(tmpFile, []byte("Contents of temp file"), 0700)
err = os.WriteFile(tmpFile, []byte("Contents of temp file"), 0700)
require.NoError(t, err)

matchingAssetPath, err = upr.FindDownloadedAsset("temp")
Expand All @@ -748,7 +747,7 @@ func TestFindDownloadedAsset(t *testing.T) {
// 5. asset given -> created KeybaseUpdate. -> file exixst and matches
tmpDir, err = util.MakeTempDir("KeybaseUpdater.", 0700)
tmpFile = filepath.Join(tmpDir, "temp")
err = ioutil.WriteFile(tmpFile, []byte("Contents of temp file"), 0700)
err = os.WriteFile(tmpFile, []byte("Contents of temp file"), 0700)
require.NoError(t, err)

matchingAssetPath, err = upr.FindDownloadedAsset("temp")
Expand All @@ -772,14 +771,14 @@ func TestUpdaterGuiBusy(t *testing.T) {

// Now put the config file there and make sure the right error is returned
now := time.Now().Unix() * 1000
err = ioutil.WriteFile(testAppStatePath, []byte(fmt.Sprintf(`{"isUserActive":true, "changedAtMs":%d}`, now)), 0644)
err = os.WriteFile(testAppStatePath, []byte(fmt.Sprintf(`{"isUserActive":true, "changedAtMs":%d}`, now)), 0644)
assert.NoError(t, err)
defer util.RemoveFileAtPath(testAppStatePath)
_, err = upr.Update(ctx)
assert.EqualError(t, err, "Update Error (guiBusy): User active, retrying later")

// If the user was recently active, they are still considered busy.
err = ioutil.WriteFile(testAppStatePath, []byte(fmt.Sprintf(`{"isUserActive":false, "changedAtMs":%d}`, now)), 0644)
err = os.WriteFile(testAppStatePath, []byte(fmt.Sprintf(`{"isUserActive":false, "changedAtMs":%d}`, now)), 0644)
assert.NoError(t, err)
_, err = upr.Update(ctx)
assert.EqualError(t, err, "Update Error (guiBusy): User active, retrying later")
Expand All @@ -792,7 +791,7 @@ func TestUpdaterGuiBusy(t *testing.T) {
// If the user wasn't recently active, they are not considered busy
ctx.isCheckCommand = false
later := time.Now().Add(-5*time.Minute).Unix() * 1000
err = ioutil.WriteFile(testAppStatePath, []byte(fmt.Sprintf(`{"isUserActive":false, "changedAtMs":%d}`, later)), 0644)
err = os.WriteFile(testAppStatePath, []byte(fmt.Sprintf(`{"isUserActive":false, "changedAtMs":%d}`, later)), 0644)
assert.NoError(t, err)
_, err = upr.Update(ctx)
assert.NoError(t, err)
Expand Down
36 changes: 20 additions & 16 deletions util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package util
import (
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -87,8 +86,9 @@ func safeWriteToFile(t SafeWriter, mode os.FileMode, log Log) error {
// Close closes a file and ignores the error.
// This satisfies lint checks when using with defer and you don't care if there
// is an error, so instead of:
// defer func() { _ = f.Close() }()
// defer Close(f)
//
// defer func() { _ = f.Close() }()
// defer Close(f)
func Close(f io.Closer) {
if f == nil {
return
Expand All @@ -100,8 +100,9 @@ func Close(f io.Closer) {
// We do nothing if path == "".
// This satisfies lint checks when using with defer and you don't care if there
// is an error, so instead of:
// defer func() { _ = os.Remove(path) }()
// defer RemoveFileAtPath(path)
//
// defer func() { _ = os.Remove(path) }()
// defer RemoveFileAtPath(path)
func RemoveFileAtPath(path string) {
if path == "" {
return
Expand All @@ -111,9 +112,8 @@ func RemoveFileAtPath(path string) {

// openTempFile creates an opened temporary file.
//
// openTempFile("foo", ".zip", 0755) => "foo.RCG2KUSCGYOO3PCKNWQHBOXBKACOPIKL.zip"
// openTempFile(path.Join(os.TempDir(), "foo"), "", 0600) => "/tmp/foo.RCG2KUSCGYOO3PCKNWQHBOXBKACOPIKL"
//
// openTempFile("foo", ".zip", 0755) => "foo.RCG2KUSCGYOO3PCKNWQHBOXBKACOPIKL.zip"
// openTempFile(path.Join(os.TempDir(), "foo"), "", 0600) => "/tmp/foo.RCG2KUSCGYOO3PCKNWQHBOXBKACOPIKL"
func openTempFile(prefix string, suffix string, mode os.FileMode) (string, *os.File, error) {
filename, err := RandomID(prefix)
if err != nil {
Expand Down Expand Up @@ -189,10 +189,11 @@ func TempPath(tempDir string, prefix string) string {
// WriteTempFile creates a unique temp file with data.
//
// For example:
// WriteTempFile("Test.", byte[]("test data"), 0600)
//
// WriteTempFile("Test.", byte[]("test data"), 0600)
func WriteTempFile(prefix string, data []byte, mode os.FileMode) (string, error) {
path := TempPath("", prefix)
if err := ioutil.WriteFile(path, data, mode); err != nil {
if err := os.WriteFile(path, data, mode); err != nil {
return "", err
}
return path, nil
Expand All @@ -201,7 +202,8 @@ func WriteTempFile(prefix string, data []byte, mode os.FileMode) (string, error)
// MakeTempDir creates a unique temp directory.
//
// For example:
// MakeTempDir("Test.", 0700)
//
// MakeTempDir("Test.", 0700)
func MakeTempDir(prefix string, mode os.FileMode) (string, error) {
path := TempPath("", prefix)
if err := os.MkdirAll(path, mode); err != nil {
Expand Down Expand Up @@ -298,7 +300,7 @@ func ReadFile(path string) ([]byte, error) {
return nil, err
}
defer Close(file)
data, err := ioutil.ReadAll(file)
data, err := io.ReadAll(file)
if err != nil {
return nil, err
}
Expand All @@ -311,8 +313,9 @@ func convertPathForWindows(path string) string {

// URLStringForPath returns an URL as string with file scheme for path.
// For example,
// /usr/local/go/bin => file:///usr/local/go/bin
// C:\Go\bin => file:///C:/Go/bin
//
// /usr/local/go/bin => file:///usr/local/go/bin
// C:\Go\bin => file:///C:/Go/bin
func URLStringForPath(path string) string {
if runtime.GOOS == "windows" {
path = convertPathForWindows(path)
Expand All @@ -324,8 +327,9 @@ func URLStringForPath(path string) string {

// PathFromURL returns path for file URL scheme
// For example,
// file:///usr/local/go/bin => /usr/local/go/bin
// file:///C:/Go/bin => C:\Go\bin
//
// file:///usr/local/go/bin => /usr/local/go/bin
// file:///C:/Go/bin => C:\Go\bin
func PathFromURL(u *url.URL) string {
path := u.Path
if runtime.GOOS == "windows" && u.Scheme == fileScheme {
Expand Down
9 changes: 4 additions & 5 deletions util/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package util

import (
"fmt"
"io/ioutil"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -139,7 +138,7 @@ func TestMoveFileValid(t *testing.T) {
exists, err := FileExists(destinationPath)
assert.NoError(t, err)
assert.True(t, exists)
data, err := ioutil.ReadFile(destinationPath)
data, err := os.ReadFile(destinationPath)
assert.NoError(t, err)
assert.Equal(t, []byte("test"), data)
srcExists, err := FileExists(sourcePath)
Expand All @@ -154,7 +153,7 @@ func TestMoveFileValid(t *testing.T) {
exists, err = FileExists(destinationPath)
assert.NoError(t, err)
assert.True(t, exists)
data2, err := ioutil.ReadFile(destinationPath)
data2, err := os.ReadFile(destinationPath)
assert.NoError(t, err)
assert.Equal(t, []byte("test2"), data2)
srcExists2, err := FileExists(sourcePath2)
Expand Down Expand Up @@ -222,7 +221,7 @@ func TestCopyFileValid(t *testing.T) {
exists, err := FileExists(destinationPath)
assert.NoError(t, err)
assert.True(t, exists)
data, err := ioutil.ReadFile(destinationPath)
data, err := os.ReadFile(destinationPath)
assert.NoError(t, err)
assert.Equal(t, []byte("test"), data)

Expand All @@ -234,7 +233,7 @@ func TestCopyFileValid(t *testing.T) {
exists, err = FileExists(destinationPath)
assert.NoError(t, err)
assert.True(t, exists)
data2, err := ioutil.ReadFile(destinationPath)
data2, err := os.ReadFile(destinationPath)
assert.NoError(t, err)
assert.Equal(t, []byte("test2"), data2)
}
Expand Down
Loading

0 comments on commit 589798d

Please sign in to comment.