(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func TestWriteSchemaWithDatabase(t *testing.T) { |
| 42 | var buf bytes.Buffer |
| 43 | |
| 44 | di := sdata.GetTestDBInfoWithDatabase() |
| 45 | if err := writeSchema(di, &buf); err != nil { |
| 46 | t.Fatal(err) |
| 47 | } |
| 48 | |
| 49 | output := buf.String() |
| 50 | |
| 51 | // Verify @database directive appears for tables with Database set |
| 52 | if !strings.Contains(output, "@database(name: analytics)") { |
| 53 | t.Error("expected @database directive for analytics database") |
| 54 | } |
| 55 | if !strings.Contains(output, "@database(name: logs)") { |
| 56 | t.Error("expected @database directive for logs database") |
| 57 | } |
| 58 | |
| 59 | // Verify no @database for tables without Database (users table) |
| 60 | // The users type declaration should not have @database |
| 61 | usersIdx := strings.Index(output, "type users") |
| 62 | if usersIdx == -1 { |
| 63 | t.Fatal("users table not found in output") |
| 64 | } |
| 65 | // Find the end of the users type block (next "type" keyword or end of output) |
| 66 | nextTypeIdx := strings.Index(output[usersIdx+1:], "\ntype ") |
| 67 | var usersBlock string |
| 68 | if nextTypeIdx == -1 { |
| 69 | usersBlock = output[usersIdx:] |
| 70 | } else { |
| 71 | usersBlock = output[usersIdx : usersIdx+1+nextTypeIdx] |
| 72 | } |
| 73 | if strings.Contains(usersBlock, "@database") { |
| 74 | t.Error("users table should not have @database directive") |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func TestParseSchemaWithDatabase(t *testing.T) { |
| 79 | schema := []byte(` |
nothing calls this directly
no test coverage detected