Skip to content

Commit

Permalink
Remove test from oss file
Browse files Browse the repository at this point in the history
  • Loading branch information
divyaac committed Dec 2, 2024
1 parent 4c3b040 commit 773f7aa
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions vault/external_tests/activity_testonly/activity_testonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,77 +892,3 @@ func TestHandleQuery_MultipleMounts(t *testing.T) {
})
}
}

// Test_ActivityLog_PreviousMonths_GlobalLocalClients verifies that
// local and global clients seen in previous months are correctly written
// to storage by the clientcountutil library, and are subsequently correctly extracted
// when a call to the counters API is made.
func Test_ActivityLog_PreviousMonths_GlobalLocalClients(t *testing.T) {
t.Parallel()

cluster := minimal.NewTestSoloCluster(t, nil)
client := cluster.Cores[0].Client
_, err := client.Logical().Write("sys/internal/counters/config", map[string]interface{}{
"enabled": "enable",
})
require.NoError(t, err)
for i := 0; i < 2; i++ {
_, err = client.Logical().Write(fmt.Sprintf("sys/namespaces/ns%d", i), nil)
require.NoError(t, err)
}

now := time.Now().UTC()

localPaths, globalPaths, err := clientcountutil.NewActivityLogData(client).
NewPreviousMonthData(2).
NewClientsSeen(10, clientcountutil.WithClientNamespace("ns0"), clientcountutil.WithClientMount("identity")).
NewClientsSeen(20, clientcountutil.WithClientNamespace("ns1"), clientcountutil.WithClientMount("sys")).
NewClientsSeen(30, clientcountutil.WithClientNamespace("ns0"), clientcountutil.WithClientMount("sys")).
NewClientsSeen(40, clientcountutil.WithClientNamespace("ns1"), clientcountutil.WithClientMount("identity")).
NewPreviousMonthData(1).
NewClientsSeen(10, clientcountutil.WithClientNamespace("ns0"), clientcountutil.WithClientMount("cubbyhole")).
NewClientsSeen(20, clientcountutil.WithClientNamespace("ns1"), clientcountutil.WithClientMount("sys")).
NewClientsSeen(30, clientcountutil.WithClientNamespace("ns0"), clientcountutil.WithClientMount("sys")).
Write(context.Background(), generation.WriteOptions_WRITE_PRECOMPUTED_QUERIES, generation.WriteOptions_WRITE_ENTITIES)
require.NoError(t, err)
// cubbyhole is local and is created for one month, one segment for local should exist
require.Len(t, localPaths, 1)
// global segments should exist for two months seen
require.Len(t, globalPaths, 2)

resp, err := client.Logical().ReadWithData("sys/internal/counters/activity", map[string][]string{
"end_time": {timeutil.EndOfMonth(timeutil.MonthsPreviousTo(1, now)).Format(time.RFC3339)},
"start_time": {timeutil.StartOfMonth(timeutil.MonthsPreviousTo(2, now)).Format(time.RFC3339)},
})

require.NoError(t, err)
var byNamespace []*vault.ResponseNamespace
err = mapstructure.Decode(resp.Data["by_namespace"], &byNamespace)
require.Len(t, byNamespace, 2)
mountClientCount := func(mounts []*vault.ResponseMount, expect map[string]int) {
mountSet := make(map[string]int, len(mounts))
for _, mount := range mounts {
mountSet[mount.MountPath] = mount.Counts.Clients
}
require.Equal(t, expect, mountSet)
}
for _, byNS := range byNamespace {
switch byNS.NamespacePath {
case "ns0/":
require.Len(t, byNS.Mounts, 3)
mountClientCount(byNS.Mounts, map[string]int{
"identity/": 10,
"sys/": 60,
"cubbyhole/": 10,
})
case "ns1/":
require.Len(t, byNS.Mounts, 2)
mountClientCount(byNS.Mounts, map[string]int{
"identity/": 40,
"sys/": 40,
})
default:
require.Fail(t, "unknown namespace", byNS.NamespacePath)
}
}
}

0 comments on commit 773f7aa

Please sign in to comment.