mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-16 20:20:57 +01:00
added testscript test to test the combination of all tasks
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
releases
|
||||
tablizer
|
||||
*.out
|
||||
|
||||
5
Makefile
5
Makefile
@@ -66,11 +66,10 @@ clean:
|
||||
rm -rf $(tool) releases coverage.out
|
||||
|
||||
test:
|
||||
go test -v ./...
|
||||
bash t/test.sh
|
||||
go test ./... $(OPTS)
|
||||
|
||||
singletest:
|
||||
@echo "Call like this: ''make singletest TEST=TestPrepareColumns MOD=lib"
|
||||
@echo "Call like this: 'make singletest TEST=TestPrepareColumns MOD=lib'"
|
||||
go test -run $(TEST) github.com/tlinden/tablizer/$(MOD)
|
||||
|
||||
cover-report:
|
||||
|
||||
7
go.mod
7
go.mod
@@ -30,6 +30,7 @@ require (
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
||||
github.com/philhofer/fwd v1.1.2 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/rogpeppe/go-internal v1.13.1 // indirect
|
||||
github.com/shurcooL/go v0.0.0-20230706063926-5fe729b41b3a // indirect
|
||||
github.com/shurcooL/go-goon v1.0.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
@@ -37,8 +38,8 @@ require (
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
github.com/zclconf/go-cty v1.13.3 // indirect
|
||||
golang.org/x/mod v0.13.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/mod v0.18.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.11.0 // indirect
|
||||
golang.org/x/tools v0.14.0 // indirect
|
||||
golang.org/x/tools v0.22.0 // indirect
|
||||
)
|
||||
|
||||
8
go.sum
8
go.sum
@@ -55,6 +55,8 @@ github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
|
||||
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 h1:aSISeOcal5irEhJd1M+IrApc0PdcN7e7Aj4yuEnOrfQ=
|
||||
@@ -92,6 +94,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
|
||||
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
|
||||
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
@@ -108,6 +112,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
@@ -124,6 +130,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
|
||||
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
|
||||
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
|
||||
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
10
main.go
10
main.go
@@ -18,9 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/tlinden/tablizer/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
os.Exit(Main())
|
||||
}
|
||||
|
||||
func Main() int {
|
||||
cmd.Execute()
|
||||
|
||||
return 0 // cmd takes care of exit 1 itself
|
||||
}
|
||||
|
||||
20
main_test.go
Normal file
20
main_test.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rogpeppe/go-internal/testscript"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
os.Exit(testscript.RunMain(m, map[string]func() int{
|
||||
"tablizer": Main,
|
||||
}))
|
||||
}
|
||||
|
||||
func TestRpn(t *testing.T) {
|
||||
testscript.Run(t, testscript.Params{
|
||||
Dir: "t",
|
||||
})
|
||||
}
|
||||
43
t/test-basics.txtar
Normal file
43
t/test-basics.txtar
Normal file
@@ -0,0 +1,43 @@
|
||||
# usage
|
||||
exec tablizer -h
|
||||
stdout Usage
|
||||
|
||||
# version
|
||||
exec tablizer -V
|
||||
stdout version
|
||||
|
||||
# manpage
|
||||
exec tablizer -m
|
||||
stdout SYNOPSIS
|
||||
|
||||
# completion
|
||||
exec tablizer --completion bash
|
||||
stdout __tablizer_init_completion
|
||||
|
||||
# use config (configures colors, but these are not being used, since
|
||||
# this env doesn't support it, but at least it should succeed.
|
||||
exec tablizer -f config.hcl -r testtable.txt Runn
|
||||
stdout Runn
|
||||
|
||||
|
||||
|
||||
# will be automatically created in work dir
|
||||
-- testtable.txt --
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
alertmanager-kube-prometheus-alertmanager-0 2/2 Running 35 (45m ago) 11d
|
||||
grafana-fcc54cbc9-bk7s8 1/1 Running 17 (45m ago) 1d
|
||||
kube-prometheus-blackbox-exporter-5d85b5d8f4-tskh7 1/1 Running 17 (45m ago) 1h44m
|
||||
kube-prometheus-kube-state-metrics-b4cd9487-75p7f 1/1 Running 20 (45m ago) 45m
|
||||
kube-prometheus-node-exporter-bfzpl 1/1 Running 17 (45m ago) 54s
|
||||
|
||||
|
||||
-- config.hcl --
|
||||
BG = "lightGreen"
|
||||
FG = "white"
|
||||
HighlightBG = "lightGreen"
|
||||
HighlightFG = "white"
|
||||
NoHighlightBG = "white"
|
||||
NoHighlightFG = "lightGreen"
|
||||
HighlightHdrBG = "red"
|
||||
HighlightHdrFG = "white"
|
||||
|
||||
26
t/test-csv.txtar
Normal file
26
t/test-csv.txtar
Normal file
@@ -0,0 +1,26 @@
|
||||
# reading from file and matching with lowercase words
|
||||
exec tablizer -c name,status -r testtable.csv -s,
|
||||
stdout grafana.*Runn
|
||||
|
||||
# matching mixed case
|
||||
exec tablizer -c NAME,staTUS -r testtable.csv -s,
|
||||
stdout grafana.*Runn
|
||||
|
||||
# matching using numbers
|
||||
exec tablizer -c 1,3 -r testtable.csv -s,
|
||||
stdout grafana.*Runn
|
||||
|
||||
# matching using regex
|
||||
exec tablizer -c 'na.*,stat.' -r testtable.csv -s,
|
||||
stdout grafana.*Runn
|
||||
|
||||
|
||||
# will be automatically created in work dir
|
||||
-- testtable.csv --
|
||||
NAME,READY,STATUS,RESTARTS,AGE
|
||||
alertmanager-kube-prometheus-alertmanager-0,2/2,Running,35 (45m ago),11d
|
||||
grafana-fcc54cbc9-bk7s8,1/1,Running,17 (45m ago),1d
|
||||
kube-prometheus-blackbox-exporter-5d85b5d8f4-tskh7,1/1,Running,17 (45m ago),1h44m
|
||||
kube-prometheus-kube-state-metrics-b4cd9487-75p7f,1/1,Running,20 (45m ago),45m
|
||||
kube-prometheus-node-exporter-bfzpl,1/1,Running,17 (45m ago),54s
|
||||
|
||||
21
t/test-filtering.txtar
Normal file
21
t/test-filtering.txtar
Normal file
@@ -0,0 +1,21 @@
|
||||
# filtering
|
||||
exec tablizer -r testtable.txt -F name=grafana
|
||||
stdout grafana.*Runn
|
||||
|
||||
# filtering two columns
|
||||
exec tablizer -r testtable.txt -F name=prometh -F age=1h
|
||||
stdout blackbox.*Runn
|
||||
|
||||
# filtering two same columns
|
||||
exec tablizer -r testtable.txt -F name=prometh -F name=alert
|
||||
stdout prometheus-alertmanager.*Runn
|
||||
|
||||
|
||||
# will be automatically created in work dir
|
||||
-- testtable.txt --
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
alertmanager-kube-prometheus-alertmanager-0 2/2 Running 35 (45m ago) 11d
|
||||
grafana-fcc54cbc9-bk7s8 1/1 Running 17 (45m ago) 1d
|
||||
kube-prometheus-blackbox-exporter-5d85b5d8f4-tskh7 1/1 Running 17 (45m ago) 1h44m
|
||||
kube-prometheus-kube-state-metrics-b4cd9487-75p7f 1/1 Running 20 (45m ago) 45m
|
||||
kube-prometheus-node-exporter-bfzpl 1/1 Running 17 (45m ago) 54s
|
||||
25
t/test-headermatching.txtar
Normal file
25
t/test-headermatching.txtar
Normal file
@@ -0,0 +1,25 @@
|
||||
# reading from file and matching with lowercase words
|
||||
exec tablizer -c name,status -r testtable.txt
|
||||
stdout grafana.*Runn
|
||||
|
||||
# matching mixed case
|
||||
exec tablizer -c NAME,staTUS -r testtable.txt
|
||||
stdout grafana.*Runn
|
||||
|
||||
# matching using numbers
|
||||
exec tablizer -c 1,3 -r testtable.txt
|
||||
stdout grafana.*Runn
|
||||
|
||||
# matching using regex
|
||||
exec tablizer -c 'na.*,stat.' -r testtable.txt
|
||||
stdout grafana.*Runn
|
||||
|
||||
|
||||
# will be automatically created in work dir
|
||||
-- testtable.txt --
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
alertmanager-kube-prometheus-alertmanager-0 2/2 Running 35 (45m ago) 11d
|
||||
grafana-fcc54cbc9-bk7s8 1/1 Running 17 (45m ago) 1d
|
||||
kube-prometheus-blackbox-exporter-5d85b5d8f4-tskh7 1/1 Running 17 (45m ago) 1h44m
|
||||
kube-prometheus-kube-state-metrics-b4cd9487-75p7f 1/1 Running 20 (45m ago) 45m
|
||||
kube-prometheus-node-exporter-bfzpl 1/1 Running 17 (45m ago) 54s
|
||||
49
t/test-sort.txtar
Normal file
49
t/test-sort.txtar
Normal file
@@ -0,0 +1,49 @@
|
||||
# sort by name
|
||||
exec tablizer -r testtable.txt -k 1
|
||||
stdout '^alert.*\n^grafana.*\n^kube'
|
||||
|
||||
# sort by name reversed
|
||||
exec tablizer -r testtable.txt -k 1 -D
|
||||
stdout 'kube.*\n^grafana.*\n^alert'
|
||||
|
||||
# sort by starts numerically
|
||||
exec tablizer -r testtable.txt -k 4 -i -c4
|
||||
stdout '17\s*\n^20\s*\n^35'
|
||||
|
||||
# sort by starts numerically reversed
|
||||
exec tablizer -r testtable.txt -k 4 -i -c4 -D
|
||||
stdout '35\s*\n^20\s*\n^17'
|
||||
|
||||
# sort by age
|
||||
exec tablizer -r testtable.txt -k 5 -a
|
||||
stdout '45m\s*\n.*1h44m'
|
||||
|
||||
# sort by age reverse
|
||||
exec tablizer -r testtable.txt -k 5 -a -D
|
||||
stdout '1h44m\s*\n.*45m'
|
||||
|
||||
# sort by time
|
||||
exec tablizer -r timetable.txt -k 2 -t
|
||||
stdout '^sel.*\n^foo.*\nbar'
|
||||
|
||||
# sort by time reverse
|
||||
exec tablizer -r timetable.txt -k 2 -t -D
|
||||
stdout '^bar.*\n^foo.*\nsel'
|
||||
|
||||
|
||||
# will be automatically created in work dir
|
||||
-- testtable.txt --
|
||||
NAME READY STATUS STARTS AGE
|
||||
alertmanager-kube-prometheus-alertmanager-0 2/2 Running 35 11d
|
||||
kube-prometheus-blackbox-exporter-5d85b5d8f4-tskh7 1/1 Running 17 1h44m
|
||||
grafana-fcc54cbc9-bk7s8 1/1 Running 17 1d
|
||||
kube-prometheus-kube-state-metrics-b4cd9487-75p7f 1/1 Running 20 45m
|
||||
kube-prometheus-node-exporter-bfzpl 1/1 Running 17 54s
|
||||
|
||||
|
||||
|
||||
-- timetable.txt --
|
||||
NAME TIME
|
||||
foo 2024-11-18T12:00:00+01:00
|
||||
bar 2024-11-18T12:45:00+01:00
|
||||
sel 2024-07-18T12:00:00+01:00
|
||||
18
t/test-stdin.txtar
Normal file
18
t/test-stdin.txtar
Normal file
@@ -0,0 +1,18 @@
|
||||
# reading from stdin and matching with lowercase words
|
||||
stdin testtable.txt
|
||||
exec tablizer -c name,status
|
||||
stdout grafana.*Runn
|
||||
|
||||
# reading from -r stdin and matching with lowercase words
|
||||
stdin testtable.txt
|
||||
exec tablizer -c name,status -r -
|
||||
stdout grafana.*Runn
|
||||
|
||||
# will be automatically created in work dir
|
||||
-- testtable.txt --
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
alertmanager-kube-prometheus-alertmanager-0 2/2 Running 35 (45m ago) 11d
|
||||
grafana-fcc54cbc9-bk7s8 1/1 Running 17 (45m ago) 1d
|
||||
kube-prometheus-blackbox-exporter-5d85b5d8f4-tskh7 1/1 Running 17 (45m ago) 1h44m
|
||||
kube-prometheus-kube-state-metrics-b4cd9487-75p7f 1/1 Running 20 (45m ago) 45m
|
||||
kube-prometheus-node-exporter-bfzpl 1/1 Running 17 (45m ago) 54s
|
||||
21
t/test-transpose.txtar
Normal file
21
t/test-transpose.txtar
Normal file
@@ -0,0 +1,21 @@
|
||||
# transpose one field
|
||||
exec tablizer -r testtable.txt -T status -R '/Running/OK/'
|
||||
stdout grafana.*OK
|
||||
|
||||
# transpose two fields
|
||||
exec tablizer -r testtable.txt -T name,status -R '/alertmanager-//' -R '/Running/OK/'
|
||||
stdout prometheus-0.*OK
|
||||
|
||||
# transpose one field and show one column
|
||||
exec tablizer -r testtable.txt -T status -R '/Running/OK/' -c name
|
||||
! stdout grafana.*OK
|
||||
|
||||
|
||||
# will be automatically created in work dir
|
||||
-- testtable.txt --
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
alertmanager-kube-prometheus-alertmanager-0 2/2 Running 35 (45m ago) 11d
|
||||
grafana-fcc54cbc9-bk7s8 1/1 Running 17 (45m ago) 1d
|
||||
kube-prometheus-blackbox-exporter-5d85b5d8f4-tskh7 1/1 Running 17 (45m ago) 1h44m
|
||||
kube-prometheus-kube-state-metrics-b4cd9487-75p7f 1/1 Running 20 (45m ago) 45m
|
||||
kube-prometheus-node-exporter-bfzpl 1/1 Running 17 (45m ago) 54s
|
||||
Reference in New Issue
Block a user