-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
doctor_test.go
65 lines (55 loc) · 1.79 KB
/
doctor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package cli
import (
"strings"
"testing"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
)
// This test doctoring a secure cluster.
func TestDoctorCluster(t *testing.T) {
defer leaktest.AfterTest(t)()
c := NewCliTest(TestCliParams{T: t})
defer c.Cleanup()
// Introduce a corruption in the descriptor table by adding a table and
// removing its parent.
c.RunWithArgs([]string{"sql", "-e", strings.Join([]string{
"CREATE TABLE to_drop (id INT)",
"DROP TABLE to_drop",
"CREATE TABLE foo (id INT)",
"INSERT INTO system.users VALUES ('node', NULL, true)",
"GRANT node TO root",
"DELETE FROM system.namespace WHERE name = 'foo'",
}, ";\n"),
})
out, err := c.RunWithCapture("debug doctor cluster")
if err != nil {
t.Fatal(err)
}
// Using datadriven allows TESTFLAGS=-rewrite.
datadriven.RunTest(t, "testdata/doctor/testcluster", func(t *testing.T, td *datadriven.TestData) string {
return out
})
}
// This test the operation of zip over secure clusters.
func TestDoctorZipDir(t *testing.T) {
defer leaktest.AfterTest(t)()
c := NewCliTest(TestCliParams{T: t, NoServer: true})
defer c.Cleanup()
out, err := c.RunWithCapture("debug doctor zipdir testdata/doctor/debugzip")
if err != nil {
t.Fatal(err)
}
// Using datadriven allows TESTFLAGS=-rewrite.
datadriven.RunTest(t, "testdata/doctor/testzipdir", func(t *testing.T, td *datadriven.TestData) string {
return out
})
}