示例#1
0
func TestSettingsSetFromEnv(t *testing.T) {
	dictObj := NewSettingsObj()

	dictObj.SetFromEnv("a", "bad_key_here", true)
	assert.Equal(t, true, dictObj.Bool("a"))

	dictObj.SetFromEnv("a", "bad_key_here", false)
	assert.Equal(t, false, dictObj.Bool("a"))

	dictObj.SetFromEnv("debug", "bad_key_here222", true)

	assert.Panic(t, "SetFromEnv received too many args: [2]", func() {
		dictObj.SetFromEnv("z", "bbaadddddd", false, true)
	})
}
示例#2
0
func TestDictObjJsonData(t *testing.T) {
	tmp := make(map[string]interface{})

	err := json.Unmarshal([]byte(`{"intOne":1,"intTwo":23456789}`), &tmp)
	if err != nil {
		t.Errorf("Json unmarshal error: %q", err)
	}

	dictObj := NewSettingsObj()

	dictObj.Set("a", tmp["intOne"])
	dictObj.Set("b", tmp["intTwo"])

	assert.Equal(t, 1, dictObj.Int("a"))
	assert.Equal(t, 23456789, dictObj.Int("b"))
}
示例#3
0
func TestServiceFull(t *testing.T) {
	strData := `{"token": "71c12814d8f7095df0bc4881fcd9163c81aede02c1ebc176a548e03a3943cb14", "identifier": 9, "data": {"aps": {"sound": "default", "badge": 9, "alert": "You got your emails."}, "acme1": "bar", "acme2": 42}, "expiry": 3600}`
	apsData := `{"acme1":"bar","acme2":42,"aps":{"alert":"You got your emails.","badge":9,"sound":"default"}}`
	jParsed := make(map[string]interface{})
	_ = json.Unmarshal([]byte(strData), &jParsed)

	hexTok, _ := hex.DecodeString("71c12814d8f7095df0bc4881fcd9163c81aede02c1ebc176a548e03a3943cb14")
	dur := time.Duration(3600) * time.Second
	result, err := parseApnsJson(jParsed)

	assert.Equal(t, nil, err)
	assert.Equal(t, uint32(9), result.identifier)
	assert.Equal(t, hexTok, result.token)
	assert.Equal(t, dur, result.expiry)
	assert.Equal(t, []byte(apsData), result.jData)
}
示例#4
0
func TestDictObjFloat(t *testing.T) {
	dictObj := NewSettingsObj()

	dictObj.Set("a", 1.0)
	dictObj.Set("b", 12345678901234.56789)

	assert.Equal(t, 1.0, dictObj.Float("a"))
	assert.Equal(t, 12345678901234.56789, dictObj.Float("b"))

	dictObj.Set("a", 222.333)

	assert.Equal(t, 222.333, dictObj.Float("a"))
	assert.Equal(t, 55.667788, dictObj.Float("c", 55.667788))

	assert.Panic(t, "Float received too many args: [2]", func() {
		dictObj.Float("z", 12.23, 33.22)
	})
}
示例#5
0
func TestDictObjInt(t *testing.T) {
	dictObj := NewSettingsObj()

	dictObj.Set("a", 1)
	dictObj.Set("b", 12345678901234)

	assert.Equal(t, 1, dictObj.Int("a"))
	assert.Equal(t, 12345678901234, dictObj.Int("b"))

	dictObj.Set("a", 2)

	assert.Equal(t, 2, dictObj.Int("a"))
	assert.Equal(t, 55, dictObj.Int("c", 55))

	assert.Panic(t, "Int received too many args: [2]", func() {
		dictObj.Int("z", 12, 34)
	})
}
示例#6
0
func TestDictObjBool(t *testing.T) {
	dictObj := NewSettingsObj()

	dictObj.Set("a", true)
	dictObj.Set("b", false)

	assert.Equal(t, true, dictObj.Bool("a"))
	assert.Equal(t, false, dictObj.Bool("b"))
	assert.Equal(t, true, dictObj.Bool("c", true))
	assert.Equal(t, false, dictObj.Bool("d", false))

	dictObj.Set("a", false)
	assert.Equal(t, false, dictObj.Bool("a"))

	assert.Panic(t, "Bool received too many args: [3]", func() {
		dictObj.Bool("z", true, false, true)
	})
}
示例#7
0
func TestDictObjString(t *testing.T) {
	dictObj := NewSettingsObj()

	dictObj.Set("a", "AAA")
	dictObj.Set("b", "BBB")

	assert.Equal(t, "AAA", dictObj.String("a"))
	assert.Equal(t, "BBB", dictObj.String("b"))

	dictObj.Set("a", "not AAA")

	assert.Equal(t, "not AAA", dictObj.String("a"))
	assert.Equal(t, "CCC", dictObj.String("c", "CCC"))

	assert.Panic(t, "String received too many args: [2]", func() {
		dictObj.String("z", "default", "bad")
	})
}