stillbox/pkg/talkgroups/xport/import_test.go

52 lines
898 B
Go
Raw Normal View History

2024-11-21 13:23:21 -05:00
package xport_test
import (
"context"
"testing"
"dynatron.me/x/stillbox/pkg/talkgroups/xport"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestImport(t *testing.T) {
tests := []struct {
name string
impType string
input []byte
sysID int
sysName string
jsExpect []byte
expectErr error
}{
{
name: "unknown importer",
impType: "nonexistent",
expectErr: xport.ErrBadType,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
ij := &xport.ImportJob{
Type: xport.Format(tc.impType),
SystemID: tc.sysID,
Body: string(tc.input),
}
_, err := ij.Import(ctx)
if tc.expectErr != nil {
require.Error(t, err)
assert.Contains(t, err.Error(), tc.expectErr.Error())
} else {
require.NoError(t, err)
}
})
}
}