(t *testing.T)
| 37 | } |
| 38 | |
| 39 | func TestCheckSchema(t *testing.T) { |
| 40 | require.NoError(t, posting.DeleteAll()) |
| 41 | initTest(t, "name:string @index(term) .") |
| 42 | // non uid to uid |
| 43 | s1 := &pb.SchemaUpdate{Predicate: x.AttrInRootNamespace("name"), ValueType: pb.Posting_UID} |
| 44 | require.NoError(t, checkSchema(s1)) |
| 45 | |
| 46 | // uid to non uid |
| 47 | require.NoError(t, schema.ParseBytes([]byte("name:uid ."), 1)) |
| 48 | s1 = &pb.SchemaUpdate{Predicate: x.AttrInRootNamespace("name"), ValueType: pb.Posting_STRING} |
| 49 | require.NoError(t, checkSchema(s1)) |
| 50 | |
| 51 | // string to password |
| 52 | require.NoError(t, schema.ParseBytes([]byte("name:string ."), 1)) |
| 53 | s1 = &pb.SchemaUpdate{Predicate: x.AttrInRootNamespace("name"), ValueType: pb.Posting_PASSWORD} |
| 54 | require.Error(t, checkSchema(s1)) |
| 55 | |
| 56 | // password to string |
| 57 | require.NoError(t, schema.ParseBytes([]byte("name:password ."), 1)) |
| 58 | s1 = &pb.SchemaUpdate{Predicate: x.AttrInRootNamespace("name"), ValueType: pb.Posting_STRING} |
| 59 | require.Error(t, checkSchema(s1)) |
| 60 | |
| 61 | // int to password |
| 62 | require.NoError(t, schema.ParseBytes([]byte("name:int ."), 1)) |
| 63 | s1 = &pb.SchemaUpdate{Predicate: x.AttrInRootNamespace("name"), ValueType: pb.Posting_PASSWORD} |
| 64 | require.Error(t, checkSchema(s1)) |
| 65 | |
| 66 | // password to password |
| 67 | require.NoError(t, schema.ParseBytes([]byte("name:password ."), 1)) |
| 68 | s1 = &pb.SchemaUpdate{Predicate: x.AttrInRootNamespace("name"), ValueType: pb.Posting_PASSWORD} |
| 69 | require.NoError(t, checkSchema(s1)) |
| 70 | |
| 71 | // string to int |
| 72 | require.NoError(t, schema.ParseBytes([]byte("name:string ."), 1)) |
| 73 | s1 = &pb.SchemaUpdate{Predicate: x.AttrInRootNamespace("name"), ValueType: pb.Posting_FLOAT} |
| 74 | require.NoError(t, checkSchema(s1)) |
| 75 | |
| 76 | // index on uid type |
| 77 | s1 = &pb.SchemaUpdate{Predicate: x.AttrInRootNamespace("name"), ValueType: pb.Posting_UID, Directive: pb.SchemaUpdate_INDEX} |
| 78 | require.Error(t, checkSchema(s1)) |
| 79 | |
| 80 | // reverse on non-uid type |
| 81 | s1 = &pb.SchemaUpdate{ |
| 82 | Predicate: x.AttrInRootNamespace("name"), |
| 83 | ValueType: pb.Posting_STRING, |
| 84 | Directive: pb.SchemaUpdate_REVERSE, |
| 85 | } |
| 86 | require.Error(t, checkSchema(s1)) |
| 87 | |
| 88 | s1 = &pb.SchemaUpdate{ |
| 89 | Predicate: x.AttrInRootNamespace("name"), |
| 90 | ValueType: pb.Posting_FLOAT, |
| 91 | Directive: pb.SchemaUpdate_INDEX, |
| 92 | Tokenizer: []string{"term"}, |
| 93 | } |
| 94 | require.NoError(t, checkSchema(s1)) |
| 95 | |
| 96 | s1 = &pb.SchemaUpdate{ |
nothing calls this directly
no test coverage detected