Skip to content

Commit

Permalink
Moving to V2 APIs (#84)
Browse files Browse the repository at this point in the history
* Moving to V2 APIs

* Using Go 1.22 everywhere

* Some more misc changes for massaging the tests
  • Loading branch information
AnomalRoil authored Aug 20, 2024
1 parent 543b497 commit 7b54141
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 134 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'

- name: Staticheck
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'
- run: go version

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
Expand Down
5 changes: 2 additions & 3 deletions cmd/tle/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (

// =============================================================================

const usage = `tlock v1.1.1 -- github.com/drand/tlock
const usage = `tlock v1.2.0 -- github.com/drand/tlock
Usage:
tle [--encrypt] (-r round)... [--armor] [-o OUTPUT] [INPUT]
Expand Down Expand Up @@ -87,8 +87,6 @@ type Flags struct {
// Parse will parse the environment variables and command line flags. The command
// line flags will overwrite environment variables. Validation takes place.
func Parse() (Flags, error) {
flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", usage) }

f := Flags{
Network: DefaultNetwork,
Chain: DefaultChain,
Expand All @@ -110,6 +108,7 @@ func Parse() (Flags, error) {
// parseCmdline will parse all the command line flags.
// The default value is set to the values parsed by the environment variables.
func parseCmdline(f *Flags) {
flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", usage) }

flag.BoolVar(&f.Encrypt, "e", f.Encrypt, "encrypt the input to the output")
flag.BoolVar(&f.Encrypt, "encrypt", f.Encrypt, "encrypt the input to the output")
Expand Down
27 changes: 16 additions & 11 deletions cmd/tle/commands/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package commands

import (
"flag"
"github.com/stretchr/testify/require"
"io"
"os"
"testing"

"github.com/stretchr/testify/require"
)

type KV struct {
Expand Down Expand Up @@ -221,24 +223,27 @@ func Test(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
for _, flag := range test.flags {
f := flag
flag.CommandLine = flag.NewFlagSet("testcommandline", flag.ContinueOnError)
r, w, _ := os.Pipe()
defer require.NoError(t, r.Close())
defer require.NoError(t, w.Close())
flag.CommandLine.SetOutput(w)

for _, f := range test.flags {
require.NoError(t, os.Setenv(f.key, f.value))
t.Cleanup(func() {
require.NoError(t, os.Unsetenv(f.key))
})
}

_, err := Parse()

if test.shouldError {
require.Error(t, err)
} else {
require.NoError(t, err)
out, _ := io.ReadAll(r)
require.NotContains(t, string(out), "flag provided but not defined")
}

for _, flag := range test.flags {
f := flag
require.NoError(t, os.Unsetenv(f.key))
}

flag.CommandLine = flag.NewFlagSet("this seems to work with nonsense in it", 0)
})
}
}
45 changes: 23 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
module github.com/drand/tlock

go 1.20
go 1.22

require (
filippo.io/age v1.1.1
github.com/drand/drand v1.5.9
github.com/drand/kyber v1.2.0
github.com/drand/drand/v2 v2.0.2
github.com/drand/go-clients v0.2.0
github.com/drand/kyber v1.3.1
github.com/drand/kyber-bls12381 v0.3.1
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
go.dedis.ch/fixbuf v1.0.3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240723171418-e6d459c13d2a // indirect
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/kelseyhightower/envconfig v1.4.0
github.com/kilic/bls12-381 v0.1.0 // indirect
github.com/nikkolasg/hexjson v0.1.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Loading

0 comments on commit 7b54141

Please sign in to comment.