From 471209bbe29fc1e3bf8d4ca3ca89d67f8817d521 Mon Sep 17 00:00:00 2001 From: Sean Liao Date: Sat, 19 Apr 2025 12:13:17 +0100 Subject: [PATCH] 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 Reviewed-by: Michael Pratt Reviewed-by: Matt Hickford LUCI-TryBot-Result: Go LUCI --- deviceauth_test.go | 14 ++++++++++---- go.mod | 5 +---- go.sum | 2 -- .../externalaccount/executablecredsource_test.go | 16 ++++++---------- google/externalaccount/header_test.go | 6 ++---- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/deviceauth_test.go b/deviceauth_test.go index 3b99620..0e61a25 100644 --- a/deviceauth_test.go +++ b/deviceauth_test.go @@ -7,9 +7,6 @@ import ( "strings" "testing" "time" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" ) func TestDeviceAuthResponseMarshalJson(t *testing.T) { @@ -74,7 +71,16 @@ func TestDeviceAuthResponseUnmarshalJson(t *testing.T) { if err != nil { 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) } }) diff --git a/go.mod b/go.mod index da302fb..48950e7 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,4 @@ module golang.org/x/oauth2 go 1.23.0 -require ( - cloud.google.com/go/compute/metadata v0.3.0 - github.com/google/go-cmp v0.5.9 -) +require cloud.google.com/go/compute/metadata v0.3.0 diff --git a/go.sum b/go.sum index 0c90528..3eecfcc 100644 --- a/go.sum +++ b/go.sum @@ -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/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= diff --git a/google/externalaccount/executablecredsource_test.go b/google/externalaccount/executablecredsource_test.go index 1440b56..fd0c79f 100644 --- a/google/externalaccount/executablecredsource_test.go +++ b/google/externalaccount/executablecredsource_test.go @@ -9,11 +9,9 @@ import ( "encoding/json" "fmt" "os" - "sort" + "slices" "testing" "time" - - "github.com/google/go-cmp/cmp" ) type testEnvironment struct { @@ -253,14 +251,12 @@ func TestExecutableCredentialGetEnvironment(t *testing.T) { ecs.env = &tt.environment - // This Transformer sorts a []string. - sorter := cmp.Transformer("Sort", func(in []string) []string { - out := append([]string(nil), in...) // Copy input to avoid mutating it - sort.Strings(out) - return out - }) + got := ecs.executableEnvironment() + slices.Sort(got) + want := tt.expectedEnvironment + slices.Sort(want) - 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) } }) diff --git a/google/externalaccount/header_test.go b/google/externalaccount/header_test.go index 39f279d..bd59a09 100644 --- a/google/externalaccount/header_test.go +++ b/google/externalaccount/header_test.go @@ -7,8 +7,6 @@ package externalaccount import ( "runtime" "testing" - - "github.com/google/go-cmp/cmp" ) func TestGoVersion(t *testing.T) { @@ -40,8 +38,8 @@ func TestGoVersion(t *testing.T) { } { version = tst.v got := goVersion() - if diff := cmp.Diff(got, tst.want); diff != "" { - t.Errorf("got(-),want(+):\n%s", diff) + if got != tst.want { + t.Errorf("go version = %q, want = %q", got, tst.want) } } version = runtime.Version