51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package dataexport
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestCategoriesFromScope(t *testing.T) {
|
|
categories, err := categoriesFromScope([]byte(`{"categories":["profile","memories"]}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !reflect.DeepEqual(categories, []string{"profile", "memories"}) {
|
|
t.Fatalf("categories = %#v", categories)
|
|
}
|
|
}
|
|
|
|
func TestCategoriesFromEmptyScopeDefaultsToAll(t *testing.T) {
|
|
categories, err := categoriesFromScope([]byte(`{}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(categories) != 8 || categories[0] != "profile" || categories[7] != "memories" {
|
|
t.Fatalf("default categories = %#v", categories)
|
|
}
|
|
}
|
|
|
|
func TestProcessorValidationAndSanitization(t *testing.T) {
|
|
if _, err := NewProcessor(nil, nil, 0); err == nil {
|
|
t.Fatal("invalid export processor dependencies were accepted")
|
|
}
|
|
if _, err := NewExpiryScanner(nil, nil, nil, 0); err == nil {
|
|
t.Fatal("invalid expiry scanner dependencies were accepted")
|
|
}
|
|
if _, err := categoriesFromScope([]byte(`{"categories":`)); err == nil {
|
|
t.Fatal("malformed export scope was accepted")
|
|
}
|
|
processor := &Processor{}
|
|
if _, err := processor.collectCategory(context.Background(), "unknown", "", ""); err == nil || !strings.Contains(err.Error(), "unsupported") {
|
|
t.Fatalf("unsupported category error=%v", err)
|
|
}
|
|
if got := sanitizeError(" short failure "); got != "short failure" {
|
|
t.Fatalf("sanitized short error=%q", got)
|
|
}
|
|
if got := sanitizeError(strings.Repeat("x", 600)); len(got) != 500 {
|
|
t.Fatalf("sanitized long error length=%d", len(got))
|
|
}
|
|
}
|