Compare commits
No commits in common. "e1211c8d6fdff8f871417f420f4ec11f1ed732a6" and "b804ae9d32145eb29a35fe471a3e4e1387c8b7a8" have entirely different histories.
e1211c8d6f
...
b804ae9d32
|
@ -27,13 +27,12 @@ type API struct {
|
||||||
Opts config.Options
|
Opts config.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) InstanceInfo() (*BBJResponse, error) {
|
||||||
type instanceInfo struct {
|
type instanceInfo struct {
|
||||||
InstanceName string `json:"instance_name"`
|
InstanceName string `json:"instance_name"`
|
||||||
AllowAnon bool `json:"allow_anon"`
|
AllowAnon bool `json:"allow_anon"`
|
||||||
Admins []string
|
Admins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) InstanceInfo() (*BBJResponse, error) {
|
|
||||||
return &BBJResponse{
|
return &BBJResponse{
|
||||||
Data: instanceInfo{
|
Data: instanceInfo{
|
||||||
InstanceName: a.Opts.Config.InstanceName,
|
InstanceName: a.Opts.Config.InstanceName,
|
||||||
|
|
|
@ -1,78 +1,22 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.tilde.town/tildetown/bbj2/server/cmd/config"
|
"git.tilde.town/tildetown/bbj2/server/cmd/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInstanceInfo(t *testing.T) {
|
func TestInstanceInfo(t *testing.T) {
|
||||||
stderr := []byte{}
|
|
||||||
stdout := []byte{}
|
|
||||||
testIO := config.IOStreams{
|
|
||||||
Err: bufio.NewWriter(bytes.NewBuffer(stderr)),
|
|
||||||
Out: bufio.NewWriter(bytes.NewBuffer(stdout)),
|
|
||||||
}
|
|
||||||
dbFile, err := os.CreateTemp("", "bbj2-test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to make test db: %s", err.Error())
|
|
||||||
}
|
|
||||||
defaultOptions := config.Options{
|
|
||||||
IO: testIO,
|
|
||||||
Log: func(s string) { fmt.Fprintln(testIO.Out, s) },
|
|
||||||
Logf: func(s string, args ...interface{}) {
|
|
||||||
fmt.Fprintf(testIO.Out, s, args...)
|
|
||||||
fmt.Fprintln(testIO.Out)
|
|
||||||
},
|
|
||||||
Config: config.Config{
|
|
||||||
Admins: []string{"jillValentine", "rebeccaChambers"},
|
|
||||||
Port: 666,
|
|
||||||
Host: "hell.cool",
|
|
||||||
InstanceName: "cool test zone",
|
|
||||||
AllowAnon: true,
|
|
||||||
DBPath: dbFile.Name(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
ts := []struct {
|
ts := []struct {
|
||||||
name string
|
name string
|
||||||
opts config.Options
|
opts config.Options
|
||||||
wantData instanceInfo
|
wantResp *BBJResponse
|
||||||
wantErr *HTTPError
|
wantErr HTTPError
|
||||||
}{
|
}{}
|
||||||
{
|
|
||||||
name: "basic",
|
|
||||||
opts: defaultOptions,
|
|
||||||
wantData: instanceInfo{
|
|
||||||
InstanceName: "cool test zone",
|
|
||||||
AllowAnon: true,
|
|
||||||
Admins: []string{"jillValentine", "rebeccaChambers"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range ts {
|
for _, tt := range ts {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
api := &API{
|
// TODO
|
||||||
Opts: tt.opts,
|
|
||||||
}
|
|
||||||
resp, err := api.InstanceInfo()
|
|
||||||
if tt.wantErr != nil && err != nil {
|
|
||||||
t.Errorf("got unwanted error: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ii, ok := resp.Data.(instanceInfo)
|
|
||||||
if !ok {
|
|
||||||
t.Errorf("could not cast data in %s", tt.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(ii, tt.wantData) {
|
|
||||||
t.Errorf("did not get expected data in %s", tt.name)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue