Skip to content

Commit 471209b

Browse files
committed
oauth2: drop dependency on go-cmp
For #615 Change-Id: I1e17703f5a52240cbd7802ab1da1fd8b24be8d6c Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/666816 Reviewed-by: Junyang Shao <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Matt Hickford <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 6968da2 commit 471209b

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

deviceauth_test.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"strings"
88
"testing"
99
"time"
10-
11-
"github.com/google/go-cmp/cmp"
12-
"github.com/google/go-cmp/cmp/cmpopts"
1310
)
1411

1512
func TestDeviceAuthResponseMarshalJson(t *testing.T) {
@@ -74,7 +71,16 @@ func TestDeviceAuthResponseUnmarshalJson(t *testing.T) {
7471
if err != nil {
7572
t.Fatal(err)
7673
}
77-
if !cmp.Equal(got, tc.want, cmpopts.IgnoreUnexported(DeviceAuthResponse{}), cmpopts.EquateApproxTime(time.Second+time.Since(begin))) {
74+
margin := time.Second + time.Since(begin)
75+
timeDiff := got.Expiry.Sub(tc.want.Expiry)
76+
if timeDiff < 0 {
77+
timeDiff *= -1
78+
}
79+
if timeDiff > margin {
80+
t.Errorf("expiry time difference too large, got=%v, want=%v margin=%v", got.Expiry, tc.want.Expiry, margin)
81+
}
82+
got.Expiry, tc.want.Expiry = time.Time{}, time.Time{}
83+
if got != tc.want {
7884
t.Errorf("want=%#v, got=%#v", tc.want, got)
7985
}
8086
})

go.mod

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ module golang.org/x/oauth2
22

33
go 1.23.0
44

5-
require (
6-
cloud.google.com/go/compute/metadata v0.3.0
7-
github.com/google/go-cmp v0.5.9
8-
)
5+
require cloud.google.com/go/compute/metadata v0.3.0

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
22
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
3-
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
4-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=

google/externalaccount/executablecredsource_test.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"os"
12-
"sort"
12+
"slices"
1313
"testing"
1414
"time"
15-
16-
"github.com/google/go-cmp/cmp"
1715
)
1816

1917
type testEnvironment struct {
@@ -253,14 +251,12 @@ func TestExecutableCredentialGetEnvironment(t *testing.T) {
253251

254252
ecs.env = &tt.environment
255253

256-
// This Transformer sorts a []string.
257-
sorter := cmp.Transformer("Sort", func(in []string) []string {
258-
out := append([]string(nil), in...) // Copy input to avoid mutating it
259-
sort.Strings(out)
260-
return out
261-
})
254+
got := ecs.executableEnvironment()
255+
slices.Sort(got)
256+
want := tt.expectedEnvironment
257+
slices.Sort(want)
262258

263-
if got, want := ecs.executableEnvironment(), tt.expectedEnvironment; !cmp.Equal(got, want, sorter) {
259+
if !slices.Equal(got, want) {
264260
t.Errorf("Incorrect environment received.\nReceived: %s\nExpected: %s", got, want)
265261
}
266262
})

google/externalaccount/header_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ package externalaccount
77
import (
88
"runtime"
99
"testing"
10-
11-
"github.com/google/go-cmp/cmp"
1210
)
1311

1412
func TestGoVersion(t *testing.T) {
@@ -40,8 +38,8 @@ func TestGoVersion(t *testing.T) {
4038
} {
4139
version = tst.v
4240
got := goVersion()
43-
if diff := cmp.Diff(got, tst.want); diff != "" {
44-
t.Errorf("got(-),want(+):\n%s", diff)
41+
if got != tst.want {
42+
t.Errorf("go version = %q, want = %q", got, tst.want)
4543
}
4644
}
4745
version = runtime.Version

0 commit comments

Comments
 (0)