summaryrefslogtreecommitdiff
path: root/api/dns/dns_test.go
blob: cc561201c0bc61b3a65f4e35db629975d7123023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package dns_test

import (
	"database/sql"
	"net/http"
	"net/http/httptest"
	"os"
	"testing"

	//	"git.hatecomputers.club/hatecomputers/hatecomputers.club/api/dns"
	"git.hatecomputers.club/hatecomputers/hatecomputers.club/api/types"
	"git.hatecomputers.club/hatecomputers/hatecomputers.club/args"
	"git.hatecomputers.club/hatecomputers/hatecomputers.club/database"
	"git.hatecomputers.club/hatecomputers/hatecomputers.club/utils"
)

func IdContinuation(context *types.RequestContext, req *http.Request, resp http.ResponseWriter) types.ContinuationChain {
	return func(success types.Continuation, _failure types.Continuation) types.ContinuationChain {
		return success(context, req, resp)
	}
}

func setup() (*sql.DB, *types.RequestContext, func()) {
	randomDb := utils.RandomId()

	testDb := database.MakeConn(&randomDb)
	database.Migrate(testDb)

	context := &types.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()

	_ = &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) {
		//		dns.CreateDNSRecordContinuation(context, r, w)(IdContinuation, IdContinuation)
	}))
	defer ts.Close()

}