mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
Add "json" as output type (#513)
Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/513 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: strk <strk@noreply.gitea.io>
This commit is contained in:
40
modules/print/table_test.go
Normal file
40
modules/print/table_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package print
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestToSnakeCase(t *testing.T) {
|
||||
assert.EqualValues(t, "some_test_var_at2d", toSnakeCase("SomeTestVarAt2d"))
|
||||
}
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
tData := &table{
|
||||
headers: []string{"A", "B"},
|
||||
values: [][]string{
|
||||
{"new a", "some bbbb"},
|
||||
{"AAAAA", "b2"},
|
||||
},
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
tData.fprint(buf, "json")
|
||||
result := []struct {
|
||||
A string
|
||||
B string
|
||||
}{}
|
||||
assert.NoError(t, json.NewDecoder(buf).Decode(&result))
|
||||
|
||||
if assert.Len(t, result, 2) {
|
||||
assert.EqualValues(t, "new a", result[0].A)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user