Skip to content

Commit

Permalink
Merge pull request #14840 from Bhargav-InfraCloud/copyright-check-in-…
Browse files Browse the repository at this point in the history
…test-files

Shell func go_srcs_in_module to list go src+test files (#14827)
  • Loading branch information
ahrtr authored Nov 23, 2022
2 parents 51c0b4d + dbfe42b commit b6a3594
Show file tree
Hide file tree
Showing 38 changed files with 152 additions and 126 deletions.
2 changes: 1 addition & 1 deletion api/etcdserverpb/raft_internal_stringer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
)

// TestInvalidGoYypeIntPanic tests conditions that caused
// TestInvalidGoTypeIntPanic tests conditions that caused
// panic: invalid Go type int for field k8s_io.kubernetes.vendor.go_etcd_io.etcd.etcdserver.etcdserverpb.loggablePutRequest.value_size
// See https://github.com/kubernetes/kubernetes/issues/91937 for more details
func TestInvalidGoTypeIntPanic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion etcdctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func SplitTestArgs(args []string) (testArgs, appArgs []string) {
return
}

// Empty test to avoid no-tests warning.
// TestEmpty is an empty test to avoid no-tests warning.
func TestEmpty(t *testing.T) {}

/**
Expand Down
2 changes: 1 addition & 1 deletion etcdutl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func SplitTestArgs(args []string) (testArgs, appArgs []string) {
return
}

// Empty test to avoid no-tests warning.
// TestEmpty is empty test to avoid no-tests warning.
func TestEmpty(t *testing.T) {}

/**
Expand Down
2 changes: 1 addition & 1 deletion pkg/ioutil/pagewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestPageWriterRandom(t *testing.T) {
t.Logf("total write bytes: %d (of %d)", cw.writeBytes, n)
}

// TestPageWriterPariallack tests the case where a write overflows the buffer
// TestPageWriterPartialSlack tests the case where a write overflows the buffer
// but there is not enough data to complete the slack write.
func TestPageWriterPartialSlack(t *testing.T) {
defaultBufferBytes = 1024
Expand Down
2 changes: 1 addition & 1 deletion raft/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestNodeStep(t *testing.T) {
}
}

// Cancel and Stop should unblock Step()
// TestNodeStepUnblock should Cancel and Stop should unblock Step()
func TestNodeStepUnblock(t *testing.T) {
// a node without buffer to block step
n := &node{
Expand Down
14 changes: 7 additions & 7 deletions raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,8 @@ func TestPastElectionTimeout(t *testing.T) {
}
}

// ensure that the Step function ignores the message from old term and does not pass it to the
// actual stepX function.
// TestStepIgnoreOldTermMsg to ensure that the Step function ignores the message
// from old term and does not pass it to the actual stepX function.
func TestStepIgnoreOldTermMsg(t *testing.T) {
called := false
fakeStep := func(r *raft, m pb.Message) error {
Expand Down Expand Up @@ -2509,7 +2509,7 @@ func TestLeaderAppResp(t *testing.T) {
}
}

// When the leader receives a heartbeat tick, it should
// TestBcastBeat is when the leader receives a heartbeat tick, it should
// send a MsgHeartbeat with m.Index = 0, m.LogTerm=0 and empty entries.
func TestBcastBeat(t *testing.T) {
offset := uint64(1000)
Expand Down Expand Up @@ -2569,7 +2569,7 @@ func TestBcastBeat(t *testing.T) {
}
}

// tests the output of the state machine when receiving MsgBeat
// TestRecvMsgBeat tests the output of the state machine when receiving MsgBeat
func TestRecvMsgBeat(t *testing.T) {
tests := []struct {
state StateType
Expand Down Expand Up @@ -2848,7 +2848,7 @@ func TestRestoreWithLearner(t *testing.T) {
}
}

// / Tests if outgoing voter can receive and apply snapshot correctly.
// TestRestoreWithVotersOutgoing tests if outgoing voter can receive and apply snapshot correctly.
func TestRestoreWithVotersOutgoing(t *testing.T) {
s := pb.Snapshot{
Metadata: pb.SnapshotMetadata{
Expand Down Expand Up @@ -4340,12 +4340,12 @@ func testConfChangeCheckBeforeCampaign(t *testing.T, v2 bool) {
}
}

// Tests if unapplied ConfChange is checked before campaign.
// TestConfChangeCheckBeforeCampaign tests if unapplied ConfChange is checked before campaign.
func TestConfChangeCheckBeforeCampaign(t *testing.T) {
testConfChangeCheckBeforeCampaign(t, false)
}

// Tests if unapplied ConfChangeV2 is checked before campaign.
// TestConfChangeV2CheckBeforeCampaign tests if unapplied ConfChangeV2 is checked before campaign.
func TestConfChangeV2CheckBeforeCampaign(t *testing.T) {
testConfChangeCheckBeforeCampaign(t, true)
}
Expand Down
10 changes: 5 additions & 5 deletions raft/rawnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ type rawNodeAdapter struct {

var _ Node = (*rawNodeAdapter)(nil)

// Node specifies lead, which is pointless, can just be filled in.
// TransferLeadership is to test when node specifies lead, which is pointless, can just be filled in.
func (a *rawNodeAdapter) TransferLeadership(ctx context.Context, lead, transferee uint64) {
a.RawNode.TransferLeader(transferee)
}

// Node has a goroutine, RawNode doesn't need this.
// Stop when node has a goroutine, RawNode doesn't need this.
func (a *rawNodeAdapter) Stop() {}

// RawNode returns a *Status.
// Status retirns RawNode's status as *Status.
func (a *rawNodeAdapter) Status() Status { return a.RawNode.Status() }

// RawNode takes a Ready. It doesn't really have to do that I think? It can hold on
// Advance is when RawNode takes a Ready. It doesn't really have to do that I think? It can hold on
// to it internally. But maybe that approach is frail.
func (a *rawNodeAdapter) Advance() { a.RawNode.Advance(Ready{}) }

// RawNode returns a Ready, not a chan of one.
// Ready when RawNode returns a Ready, not a chan of one.
func (a *rawNodeAdapter) Ready() <-chan Ready { return nil }

// Node takes more contexts. Easy enough to fix.
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function relativePath {
# go_srcs_in_module [package]
# returns list of all not-generated go sources in the current (dir) module.
function go_srcs_in_module {
go list -f "{{with \$c:=.}}{{range \$f:=\$c.GoFiles }}{{\$c.Dir}}/{{\$f}}{{\"\n\"}}{{end}}{{end}}" ./... | grep -vE "(\\.pb\\.go|\\.pb\\.gw.go)"
go list -f "{{with \$c:=.}}{{range \$f:=\$c.GoFiles }}{{\$c.Dir}}/{{\$f}}{{\"\n\"}}{{end}}{{range \$f:=\$c.TestGoFiles }}{{\$c.Dir}}/{{\$f}}{{\"\n\"}}{{end}}{{range \$f:=\$c.XTestGoFiles }}{{\$c.Dir}}/{{\$f}}{{\"\n\"}}{{end}}{{end}}" ./... | grep -vE "(\\.pb\\.go|\\.pb\\.gw.go)"
}

# pkgs_in_module [optional:package_pattern]
Expand Down
4 changes: 2 additions & 2 deletions server/auth/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestNewAuthStoreRevision(t *testing.T) {
}
}

// TestNewAuthStoreBryptCost ensures that NewAuthStore uses default when given bcrypt-cost is invalid
// TestNewAuthStoreBcryptCost ensures that NewAuthStore uses default when given bcrypt-cost is invalid
func TestNewAuthStoreBcryptCost(t *testing.T) {
tp, err := NewTokenProvider(zaptest.NewLogger(t), tokenTypeSimple, dummyIndexWaiter, simpleTokenTTLDefault)
if err != nil {
Expand Down Expand Up @@ -779,7 +779,7 @@ func TestIsAuthEnabled(t *testing.T) {
}
}

// TestAuthRevisionRace ensures that access to authStore.revision is thread-safe.
// TestAuthInfoFromCtxRace ensures that access to authStore.revision is thread-safe.
func TestAuthInfoFromCtxRace(t *testing.T) {
tp, err := NewTokenProvider(zaptest.NewLogger(t), tokenTypeSimple, dummyIndexWaiter, simpleTokenTTLDefault)
if err != nil {
Expand Down
22 changes: 11 additions & 11 deletions server/etcdserver/api/v2store/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,84 @@ import (
"github.com/stretchr/testify/assert"
)

// Ensure that a successful Get is recorded in the stats.
// TestStoreStatsGetSuccess ensures that a successful Get is recorded in the stats.
func TestStoreStatsGetSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.Get("/foo", false, false)
assert.Equal(t, uint64(1), s.Stats.GetSuccess, "")
}

// Ensure that a failed Get is recorded in the stats.
// TestStoreStatsGetFail ensures that a failed Get is recorded in the stats.
func TestStoreStatsGetFail(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.Get("/no_such_key", false, false)
assert.Equal(t, uint64(1), s.Stats.GetFail, "")
}

// Ensure that a successful Create is recorded in the stats.
// TestStoreStatsCreateSuccess ensures that a successful Create is recorded in the stats.
func TestStoreStatsCreateSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
assert.Equal(t, uint64(1), s.Stats.CreateSuccess, "")
}

// Ensure that a failed Create is recorded in the stats.
// TestStoreStatsCreateFail ensures that a failed Create is recorded in the stats.
func TestStoreStatsCreateFail(t *testing.T) {
s := newStore()
s.Create("/foo", true, "", false, TTLOptionSet{ExpireTime: Permanent})
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
assert.Equal(t, uint64(1), s.Stats.CreateFail, "")
}

// Ensure that a successful Update is recorded in the stats.
// TestStoreStatsUpdateSuccess ensures that a successful Update is recorded in the stats.
func TestStoreStatsUpdateSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.Update("/foo", "baz", TTLOptionSet{ExpireTime: Permanent})
assert.Equal(t, uint64(1), s.Stats.UpdateSuccess, "")
}

// Ensure that a failed Update is recorded in the stats.
// TestStoreStatsUpdateFail ensures that a failed Update is recorded in the stats.
func TestStoreStatsUpdateFail(t *testing.T) {
s := newStore()
s.Update("/foo", "bar", TTLOptionSet{ExpireTime: Permanent})
assert.Equal(t, uint64(1), s.Stats.UpdateFail, "")
}

// Ensure that a successful CAS is recorded in the stats.
// TestStoreStatsCompareAndSwapSuccess ensures that a successful CAS is recorded in the stats.
func TestStoreStatsCompareAndSwapSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.CompareAndSwap("/foo", "bar", 0, "baz", TTLOptionSet{ExpireTime: Permanent})
assert.Equal(t, uint64(1), s.Stats.CompareAndSwapSuccess, "")
}

// Ensure that a failed CAS is recorded in the stats.
// TestStoreStatsCompareAndSwapFail ensures that a failed CAS is recorded in the stats.
func TestStoreStatsCompareAndSwapFail(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.CompareAndSwap("/foo", "wrong_value", 0, "baz", TTLOptionSet{ExpireTime: Permanent})
assert.Equal(t, uint64(1), s.Stats.CompareAndSwapFail, "")
}

// Ensure that a successful Delete is recorded in the stats.
// TestStoreStatsDeleteSuccess ensures that a successful Delete is recorded in the stats.
func TestStoreStatsDeleteSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.Delete("/foo", false, false)
assert.Equal(t, uint64(1), s.Stats.DeleteSuccess, "")
}

// Ensure that a failed Delete is recorded in the stats.
// TestStoreStatsDeleteFail ensures that a failed Delete is recorded in the stats.
func TestStoreStatsDeleteFail(t *testing.T) {
s := newStore()
s.Delete("/foo", false, false)
assert.Equal(t, uint64(1), s.Stats.DeleteFail, "")
}

// Ensure that the number of expirations is recorded in the stats.
// TestStoreStatsExpireCount ensures that the number of expirations is recorded in the stats.
func TestStoreStatsExpireCount(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand Down
22 changes: 11 additions & 11 deletions server/etcdserver/api/v2store/store_ttl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/jonboulle/clockwork"
)

// Ensure that any TTL <= minExpireTime becomes Permanent
// TestMinExpireTime ensures that any TTL <= minExpireTime becomes Permanent
func TestMinExpireTime(t *testing.T) {
s := newStore()
fc := clockwork.NewFakeClock()
Expand All @@ -45,7 +45,7 @@ func TestMinExpireTime(t *testing.T) {
assert.Equal(t, e.Node.TTL, int64(0))
}

// Ensure that the store can recursively retrieve a directory listing.
// TestStoreGetDirectory ensures that the store can recursively retrieve a directory listing.
// Note that hidden files should not be returned.
func TestStoreGetDirectory(t *testing.T) {
s := newStore()
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestStoreGetDirectory(t *testing.T) {
}
}

// Ensure that the store can update the TTL on a value.
// TestStoreUpdateValueTTL ensures that the store can update the TTL on a value.
func TestStoreUpdateValueTTL(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand All @@ -114,7 +114,7 @@ func TestStoreUpdateValueTTL(t *testing.T) {
assert.Equal(t, err.(*v2error.Error).ErrorCode, v2error.EcodeKeyNotFound)
}

// Ensure that the store can update the TTL on a directory.
// TestStoreUpdateDirTTL ensures that the store can update the TTL on a directory.
func TestStoreUpdateDirTTL(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand All @@ -140,7 +140,7 @@ func TestStoreUpdateDirTTL(t *testing.T) {
assert.Equal(t, err.(*v2error.Error).ErrorCode, v2error.EcodeKeyNotFound)
}

// Ensure that the store can watch for key expiration.
// TestStoreWatchExpire ensures that the store can watch for key expiration.
func TestStoreWatchExpire(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestStoreWatchExpire(t *testing.T) {
assert.Equal(t, e.Node.Dir, true)
}

// Ensure that the store can watch for key expiration when refreshing.
// TestStoreWatchExpireRefresh ensures that the store can watch for key expiration when refreshing.
func TestStoreWatchExpireRefresh(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestStoreWatchExpireRefresh(t *testing.T) {
assert.Equal(t, e.Node.Key, "/foofoo")
}

// Ensure that the store can watch for key expiration when refreshing with an empty value.
// TestStoreWatchExpireEmptyRefresh ensures that the store can watch for key expiration when refreshing with an empty value.
func TestStoreWatchExpireEmptyRefresh(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand All @@ -239,7 +239,7 @@ func TestStoreWatchExpireEmptyRefresh(t *testing.T) {
assert.Equal(t, *e.PrevNode.Value, "bar")
}

// Update TTL of a key (set TTLOptionSet.Refresh to false) and send notification
// TestStoreWatchNoRefresh updates TTL of a key (set TTLOptionSet.Refresh to false) and send notification
func TestStoreWatchNoRefresh(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand All @@ -265,7 +265,7 @@ func TestStoreWatchNoRefresh(t *testing.T) {
assert.Equal(t, *e.PrevNode.Value, "bar")
}

// Ensure that the store can update the TTL on a value with refresh.
// TestStoreRefresh ensures that the store can update the TTL on a value with refresh.
func TestStoreRefresh(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand All @@ -287,7 +287,7 @@ func TestStoreRefresh(t *testing.T) {
testutil.AssertNil(t, err)
}

// Ensure that the store can recover from a previously saved state that includes an expiring key.
// TestStoreRecoverWithExpiration ensures that the store can recover from a previously saved state that includes an expiring key.
func TestStoreRecoverWithExpiration(t *testing.T) {
s := newStore()
s.clock = newFakeClock()
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestStoreRecoverWithExpiration(t *testing.T) {
testutil.AssertNil(t, e)
}

// Ensure that the store doesn't see expirations of hidden keys.
// TestStoreWatchExpireWithHiddenKey ensures that the store doesn't see expirations of hidden keys.
func TestStoreWatchExpireWithHiddenKey(t *testing.T) {
s := newStore()
fc := newFakeClock()
Expand Down
10 changes: 5 additions & 5 deletions server/etcdserver/api/v3discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type fakeKVForClusterSize struct {
clusterSizeStr string
}

// We only need to overwrite the method `Get`.
// Get when we only need to overwrite the method `Get`.
func (fkv *fakeKVForClusterSize) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) {
if fkv.clusterSizeStr == "" {
// cluster size isn't configured in this case.
Expand Down Expand Up @@ -108,7 +108,7 @@ type fakeKVForClusterMembers struct {
members []memberInfo
}

// We only need to overwrite method `Get`.
// Get when we only need to overwrite method `Get`.
func (fkv *fakeKVForClusterMembers) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) {
kvs := memberInfoToKeyValues(fkv.members)

Expand Down Expand Up @@ -230,7 +230,7 @@ type fakeKVForCheckCluster struct {
getMembersRetries int
}

// We only need to overwrite method `Get`.
// Get when we only need to overwrite method `Get`.
func (fkv *fakeKVForCheckCluster) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) {
clusterSizeKey := fmt.Sprintf("/_etcd/registry/%s/_config/size", fkv.token)
clusterMembersKey := fmt.Sprintf("/_etcd/registry/%s/members", fkv.token)
Expand Down Expand Up @@ -420,7 +420,7 @@ type fakeKVForRegisterSelf struct {
retries int
}

// We only need to overwrite method `Put`.
// Put when we only need to overwrite method `Put`.
func (fkv *fakeKVForRegisterSelf) Put(ctx context.Context, key string, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) {
if key != fkv.expectedRegKey {
fkv.t.Errorf("unexpected register key, expected: %s, got: %s", fkv.expectedRegKey, key)
Expand Down Expand Up @@ -515,7 +515,7 @@ type fakeWatcherForWaitPeers struct {
members []memberInfo
}

// We only need to overwrite method `Watch`.
// Watch we only need to overwrite method `Watch`.
func (fw *fakeWatcherForWaitPeers) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan {
expectedWatchKey := fmt.Sprintf("/_etcd/registry/%s/members", fw.token)
if key != expectedWatchKey {
Expand Down
Loading

0 comments on commit b6a3594

Please sign in to comment.