From fc0cac7d2998348e4c99fdb4058a1f3cd214c5ed Mon Sep 17 00:00:00 2001 From: Craig Peterson Date: Tue, 11 Apr 2017 23:02:57 -0600 Subject: [PATCH] adding mx and cname --- docs/_functions/domain/CNAME.md | 4 ++-- docs/_functions/domain/MX.md | 25 +++++++++++++++++++++++++ js/helpers.js | 12 ++++++++++++ js/js_test.go | 26 +++++++++++--------------- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/docs/_functions/domain/CNAME.md b/docs/_functions/domain/CNAME.md index c9c66ff3a..d69ce8f38 100644 --- a/docs/_functions/domain/CNAME.md +++ b/docs/_functions/domain/CNAME.md @@ -2,14 +2,14 @@ name: CNAME parameters: - name - - address + - target - modifiers... --- CNAME adds a CNAME record to the domain. The name should be the relative label for the domain. Using `@` or `*` for CNAME records is not recommended, as different providers support them differently. -Adress should be a string representing the CNAME target. If it is a single label we will assume it is a relative name on the current domain. If it contains *any* dots, it should be a fully qualified domain name, ending with a `.`. +Target should be a string representing the CNAME target. If it is a single label we will assume it is a relative name on the current domain. If it contains *any* dots, it should be a fully qualified domain name, ending with a `.`. {% include startExample.html %} {% highlight js %} diff --git a/docs/_functions/domain/MX.md b/docs/_functions/domain/MX.md index e69de29bb..c94d1256f 100644 --- a/docs/_functions/domain/MX.md +++ b/docs/_functions/domain/MX.md @@ -0,0 +1,25 @@ +--- +name: MX +parameters: + - name + - priority + - target + - modifiers... +--- + +MX adds an MX record to the domain. + +Priority should be a number. + +Target should be a string representing the MX target. If it is a single label we will assume it is a relative name on the current domain. If it contains *any* dots, it should be a fully qualified domain name, ending with a `.`. + +{% include startExample.html %} +{% highlight js %} + +D("example.com", REGISTRAR, DnsProvider(R53), + MX("@", 5, "mail"), // mx example.com -> mail.example.com + MX("sub", 10, "mail.foo.com.") +); + +{%endhighlight%} +{% include endExample.html %} \ No newline at end of file diff --git a/js/helpers.js b/js/helpers.js index 8872fbc59..f17b6c488 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -141,6 +141,7 @@ function TXT(name, target) { // MX(name,priority,target, recordModifiers...) function MX(name, priority, target) { + checkArgs([_.isString, _.isNumber, _.isString], arguments, "MX expects (name, priority, target)") var mods = getModifiers(arguments,3) return function(d) { mods.push(priority); @@ -148,6 +149,17 @@ function MX(name, priority, target) { } } +function checkArgs(checks, args, desc){ + if (args.length < checks.length){ + throw(desc) + } + for (var i = 0; i< checks.length; i++){ + if (!checks[i](args[i])){ + throw(desc+" - argument "+i+" is not correct type") + } + } +} + // NS(name,target, recordModifiers...) function NS(name, target) { var mods = getModifiers(arguments,2) diff --git a/js/js_test.go b/js/js_test.go index 9178625de..61a90f7be 100644 --- a/js/js_test.go +++ b/js/js_test.go @@ -67,21 +67,17 @@ func TestParsedFiles(t *testing.T) { } func TestErrors(t *testing.T) { - files, err := ioutil.ReadDir(errorDir) - if err != nil { - t.Fatal(err) + tests := []struct{ desc, text string }{ + {"old dsp style", `D("foo.com","reg","dsp")`}, + {"MX no priority", `D("foo.com","reg",MX("@","test."))`}, + {"MX reversed", `D("foo.com","reg",MX("@","test.", 5))`}, } - for _, f := range files { - if filepath.Ext(f.Name()) != ".js" { - continue - } - t.Log(f.Name(), "------") - content, err := ioutil.ReadFile(filepath.Join(errorDir, f.Name())) - if err != nil { - t.Fatal(err) - } - if _, err = ExecuteJavascript(string(content), true); err == nil { - t.Fatal("Expected error but found none") - } + for _, tst := range tests { + t.Run(tst.desc, func(t *testing.T) { + if _, err := ExecuteJavascript(tst.text, true); err == nil { + t.Fatal("Expected error but found none") + } + }) + } }