File: registration_test.go

package info (click to toggle)
golang-github-influxdb-usage-client 0.0~git20151204.0.475977e-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 152 kB
  • sloc: makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,255 bytes parent folder | download | duplicates (4)
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
package client_test

import (
	"fmt"
	"testing"

	"github.com/influxdata/usage-client/v1"
	"github.com/stretchr/testify/require"
)

func Test_Client_RegistrationURL(t *testing.T) {
	r := require.New(t)
	c := client.New("foo")
	u, _ := c.RegistrationURL(client.Registration{
		ClusterID:   "clus1",
		Product:     "chronograf",
		RedirectURL: "http://example.com",
	})
	r.Equal("https://usage.influxdata.com/start?cluster_id=clus1&product=chronograf&redirect_url=http%3A%2F%2Fexample.com", u)
}

func Test_Registration_IsValid(t *testing.T) {
	r := require.New(t)
	reg := client.Registration{}
	err := reg.IsValid()
	r.Error(err)

	reg.ClusterID = "clus1"
	err = reg.IsValid()
	r.Error(err)

	reg.ClusterID = ""
	reg.Product = "foo"
	err = reg.IsValid()
	r.Error(err)

	reg.ClusterID = "clus1"
	reg.Product = "foo"
	err = reg.IsValid()
	r.NoError(err)
}

// Example of getting a registration URL for a product
func Example_registrationURL() {
	c := client.New("")
	r := client.Registration{
		ClusterID:   "clus1",
		Product:     "chronograf",
		RedirectURL: "http://example.com",
	}

	s, _ := c.RegistrationURL(r)
	fmt.Printf("s: %s\n", s)
	// https://usage.influxdata.com/start?cluster_id=clus1&product=chronograf&redirect_url=http%3A%2F%2Fexample.com
}