From e708a1873a0a8a75606c062368165ebf111e360a Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Wed, 10 May 2023 05:44:09 -0700 Subject: [PATCH] remove facebookgo/ensure (#44) Summary: The lib is deprecated. Pull Request resolved: https://github.com/facebookincubator/dhcplb/pull/44 Reviewed By: tfg13 Differential Revision: D45728188 fbshipit-source-id: 3f96f1145002ff93d9e66d0149ee7458974a2ef6 --- go.mod | 4 -- go.sum | 8 --- lib/update_servers_test.go | 118 ++++++++++++++++++------------------- 3 files changed, 57 insertions(+), 73 deletions(-) diff --git a/go.mod b/go.mod index aef9703..ec25022 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/facebookincubator/dhcplb go 1.19 require ( - github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c github.com/fsnotify/fsnotify v1.6.0 github.com/golang/glog v1.1.0 github.com/hashicorp/golang-lru/v2 v2.0.2 @@ -12,9 +11,6 @@ require ( ) require ( - github.com/davecgh/go-spew v1.1.0 // indirect - github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect - github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect github.com/josharian/native v1.1.0 // indirect github.com/pierrec/lz4/v4 v4.1.14 // indirect github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 // indirect diff --git a/go.sum b/go.sum index 44742b9..9d834a6 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,3 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= -github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= -github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= -github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= -github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk= -github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= diff --git a/lib/update_servers_test.go b/lib/update_servers_test.go index 8f918da..abd08b5 100644 --- a/lib/update_servers_test.go +++ b/lib/update_servers_test.go @@ -8,75 +8,71 @@ package dhcplb import ( - "github.com/facebookgo/ensure" + "fmt" "net" + "reflect" "testing" ) -func Test_Nil(t *testing.T) { - added, removed := diffServersList(nil, nil) - // added and removed lists should be empty - ensure.DeepEqual(t, added, make([]*DHCPServer, 0)) - ensure.DeepEqual(t, removed, make([]*DHCPServer, 0)) -} - -func UpdateServerTestEmpty(t *testing.T) { - added, removed := diffServersList(make([]*DHCPServer, 0), make([]*DHCPServer, 0)) - // added and removed lists should be empty - ensure.DeepEqual(t, added, make([]*DHCPServer, 0)) - ensure.DeepEqual(t, removed, make([]*DHCPServer, 0)) -} - -func Test_Add(t *testing.T) { - var original []*DHCPServer - updated := []*DHCPServer{ - &DHCPServer{ - Address: net.ParseIP("1.2.3.4"), - Port: 1, - }, - &DHCPServer{ - Address: net.ParseIP("5.6.7.8"), - Port: 2, +func TestDiffServerList(t *testing.T) { + for i, tt := range []struct { + original []*DHCPServer + updated []*DHCPServer + }{ + { + original: []*DHCPServer{}, + updated: []*DHCPServer{}, }, - } - added, removed := diffServersList(original, updated) - // original list was empty, so added should just be the new list - ensure.DeepEqual(t, added, updated) - ensure.DeepEqual(t, removed, make([]*DHCPServer, 0)) -} + { + original: []*DHCPServer{}, + updated: []*DHCPServer{ -func Test_Remove(t *testing.T) { - original := []*DHCPServer{ - &DHCPServer{ - Address: net.ParseIP("1.2.3.4"), - Port: 1, - }, - &DHCPServer{ - Address: net.ParseIP("5.6.7.8"), - Port: 2, + &DHCPServer{ + Address: net.ParseIP("1.2.3.4"), + Port: 1, + }, + &DHCPServer{ + Address: net.ParseIP("5.6.7.8"), + Port: 2, + }, + }, }, - } - var updated []*DHCPServer - added, removed := diffServersList(original, updated) - // new list is empty, so removed should just be the original list - ensure.DeepEqual(t, removed, original) - ensure.DeepEqual(t, added, make([]*DHCPServer, 0)) -} - -func Test_Add_Remove(t *testing.T) { - original := []*DHCPServer{ - &DHCPServer{ - Address: net.ParseIP("1.2.3.4"), - Port: 1, + { + original: []*DHCPServer{ + &DHCPServer{ + Address: net.ParseIP("1.2.3.4"), + Port: 1, + }, + &DHCPServer{ + Address: net.ParseIP("5.6.7.8"), + Port: 2, + }, + }, + updated: []*DHCPServer{}, }, - } - updated := []*DHCPServer{ - &DHCPServer{ - Address: net.ParseIP("5.6.7.8"), - Port: 2, + { + original: []*DHCPServer{ + &DHCPServer{ + Address: net.ParseIP("1.2.3.4"), + Port: 1, + }, + }, + updated: []*DHCPServer{ + &DHCPServer{ + Address: net.ParseIP("5.6.7.8"), + Port: 2, + }, + }, }, + } { + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + added, removed := diffServersList(tt.original, tt.updated) + if !reflect.DeepEqual(added, tt.updated) { + t.Errorf("added %v, updated %v", added, tt.updated) + } + if !reflect.DeepEqual(removed, tt.original) { + t.Errorf("removed %v, original %v", removed, tt.original) + } + }) } - added, removed := diffServersList(original, updated) - ensure.DeepEqual(t, added, updated) - ensure.DeepEqual(t, removed, original) }