oauth2: drop dependency on go-cmp

For golang/oauth2#615

Change-Id: I1e17703f5a52240cbd7802ab1da1fd8b24be8d6c
Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/666816
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Matt Hickford <matt.hickford@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Sean Liao 2025-04-19 12:13:17 +01:00
parent 6968da209b
commit 471209bbe2
5 changed files with 19 additions and 24 deletions

View File

@ -7,9 +7,6 @@ import (
"strings" "strings"
"testing" "testing"
"time" "time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
) )
func TestDeviceAuthResponseMarshalJson(t *testing.T) { func TestDeviceAuthResponseMarshalJson(t *testing.T) {
@ -74,7 +71,16 @@ func TestDeviceAuthResponseUnmarshalJson(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if !cmp.Equal(got, tc.want, cmpopts.IgnoreUnexported(DeviceAuthResponse{}), cmpopts.EquateApproxTime(time.Second+time.Since(begin))) { margin := time.Second + time.Since(begin)
timeDiff := got.Expiry.Sub(tc.want.Expiry)
if timeDiff < 0 {
timeDiff *= -1
}
if timeDiff > margin {
t.Errorf("expiry time difference too large, got=%v, want=%v margin=%v", got.Expiry, tc.want.Expiry, margin)
}
got.Expiry, tc.want.Expiry = time.Time{}, time.Time{}
if got != tc.want {
t.Errorf("want=%#v, got=%#v", tc.want, got) t.Errorf("want=%#v, got=%#v", tc.want, got)
} }
}) })

5
go.mod
View File

@ -2,7 +2,4 @@ module golang.org/x/oauth2
go 1.23.0 go 1.23.0
require ( require cloud.google.com/go/compute/metadata v0.3.0
cloud.google.com/go/compute/metadata v0.3.0
github.com/google/go-cmp v0.5.9
)

2
go.sum
View File

@ -1,4 +1,2 @@
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=

View File

@ -9,11 +9,9 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"sort" "slices"
"testing" "testing"
"time" "time"
"github.com/google/go-cmp/cmp"
) )
type testEnvironment struct { type testEnvironment struct {
@ -253,14 +251,12 @@ func TestExecutableCredentialGetEnvironment(t *testing.T) {
ecs.env = &tt.environment ecs.env = &tt.environment
// This Transformer sorts a []string. got := ecs.executableEnvironment()
sorter := cmp.Transformer("Sort", func(in []string) []string { slices.Sort(got)
out := append([]string(nil), in...) // Copy input to avoid mutating it want := tt.expectedEnvironment
sort.Strings(out) slices.Sort(want)
return out
})
if got, want := ecs.executableEnvironment(), tt.expectedEnvironment; !cmp.Equal(got, want, sorter) { if !slices.Equal(got, want) {
t.Errorf("Incorrect environment received.\nReceived: %s\nExpected: %s", got, want) t.Errorf("Incorrect environment received.\nReceived: %s\nExpected: %s", got, want)
} }
}) })

View File

@ -7,8 +7,6 @@ package externalaccount
import ( import (
"runtime" "runtime"
"testing" "testing"
"github.com/google/go-cmp/cmp"
) )
func TestGoVersion(t *testing.T) { func TestGoVersion(t *testing.T) {
@ -40,8 +38,8 @@ func TestGoVersion(t *testing.T) {
} { } {
version = tst.v version = tst.v
got := goVersion() got := goVersion()
if diff := cmp.Diff(got, tst.want); diff != "" { if got != tst.want {
t.Errorf("got(-),want(+):\n%s", diff) t.Errorf("go version = %q, want = %q", got, tst.want)
} }
} }
version = runtime.Version version = runtime.Version