MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestUpdateDesignDoc

Function TestUpdateDesignDoc

db/database_test.go:2571–2599  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2569}
2570
2571func 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
2601func TestPostWithExistingId(t *testing.T) {
2602

Callers

nothing calls this directly

Calls 10

NewUserMethod · 0.95
NewAuthenticatorFunction · 0.92
BaseSetOfFunction · 0.92
PutDesignDocMethod · 0.80
GetDesignDocMethod · 0.80
AuthenticatorOptionsMethod · 0.80
assertHTTPErrorFunction · 0.70
CloseMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected