(t *testing.T)
| 2569 | } |
| 2570 | |
| 2571 | func TestUpdateDesignDoc(t *testing.T) { |
| 2572 | |
| 2573 | db, ctx := setupTestDBWithViewsEnabled(t) |
| 2574 | defer db.Close(ctx) |
| 2575 | |
| 2576 | mapFunction := `function (doc, meta) { emit(); }` |
| 2577 | err := db.PutDesignDoc(ctx, "official", sgbucket.DesignDoc{ |
| 2578 | Views: sgbucket.ViewMap{ |
| 2579 | "TestView": sgbucket.ViewDef{Map: mapFunction}, |
| 2580 | }, |
| 2581 | }) |
| 2582 | assert.NoError(t, err, "add design doc as admin") |
| 2583 | |
| 2584 | // Validate retrieval of the design doc by admin |
| 2585 | var result sgbucket.DesignDoc |
| 2586 | result, err = db.GetDesignDoc("official") |
| 2587 | log.Printf("design doc: %+v", result) |
| 2588 | |
| 2589 | assert.NoError(t, err, "retrieve design doc as admin") |
| 2590 | retrievedView, ok := result.Views["TestView"] |
| 2591 | assert.True(t, ok) |
| 2592 | assert.True(t, strings.Contains(retrievedView.Map, "emit()")) |
| 2593 | assert.NotEqual(t, mapFunction, retrievedView.Map) // SG should wrap the map function, so they shouldn't be equal |
| 2594 | |
| 2595 | authenticator := auth.NewAuthenticator(db.MetadataStore, db, db.AuthenticatorOptions(ctx)) |
| 2596 | db.user, _ = authenticator.NewUser("naomi", "letmein", channels.BaseSetOf(t, "Netflix")) |
| 2597 | err = db.PutDesignDoc(ctx, "_design/pwn3d", sgbucket.DesignDoc{}) |
| 2598 | assertHTTPError(t, err, 403) |
| 2599 | } |
| 2600 | |
| 2601 | func TestPostWithExistingId(t *testing.T) { |
| 2602 |
nothing calls this directly
no test coverage detected