diff options
| author | Elizabeth <elizabeth@simponic.xyz> | 2024-04-03 16:22:19 -0600 |
|---|---|---|
| committer | Elizabeth <elizabeth@simponic.xyz> | 2024-04-03 16:22:19 -0600 |
| commit | e398cf05402c010d594cea4e2dea307ca1a36dbe (patch) | |
| tree | 57a878b408a2066275fefb8058a43ec44d9bd223 /api/dns_test.go | |
| parent | b74a955dcb8cc1d5d2599a1b096510a60e55e7d7 (diff) | |
| download | hatecomputers.club-e398cf05402c010d594cea4e2dea307ca1a36dbe.tar.gz hatecomputers.club-e398cf05402c010d594cea4e2dea307ca1a36dbe.zip | |
checkpoint to save work; had to get on the bus
Diffstat (limited to 'api/dns_test.go')
| -rw-r--r-- | api/dns_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/api/dns_test.go b/api/dns_test.go new file mode 100644 index 0000000..59dd85b --- /dev/null +++ b/api/dns_test.go @@ -0,0 +1,56 @@ +package api_test + +import ( + "database/sql" + "net/http" + "net/http/httptest" + "os" + "testing" + + "git.hatecomputers.club/hatecomputers/hatecomputers.club/api" + "git.hatecomputers.club/hatecomputers/hatecomputers.club/args" + "git.hatecomputers.club/hatecomputers/hatecomputers.club/database" + "git.hatecomputers.club/hatecomputers/hatecomputers.club/utils" +) + +func setup() (*sql.DB, *api.RequestContext, func()) { + randomDb := utils.RandomId() + + testDb := database.MakeConn(&randomDb) + database.Migrate(testDb) + + context := &api.RequestContext{ + DBConn: testDb, + Args: &args.Arguments{}, + TemplateData: &(map[string]interface{}{}), + } + + return testDb, context, func() { + testDb.Close() + os.Remove(randomDb) + } +} + +func TestThatOwnerCanPutRecordInDomain(t *testing.T) { + db, context, cleanup := setup() + defer cleanup() + + testUser := &database.User{ + ID: "test", + Username: "test", + } + + records, err := database.GetUserDNSRecords(db, context.User.ID) + if err != nil { + t.Fatal(err) + } + if len(records) > 0 { + t.Errorf("expected no records, got records") + } + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + api.PutDNSRecordContinuation(context, r, w)(api.IdContinuation, api.IdContinuation) + })) + defer ts.Close() + +} |
