示例#1
0
func TestGetters(t *testing.T) {
	defer storage.DeleteAllData(enum.ANALYTICS)
	data.SaveMockAnalytics()
	analytics := data.CreateMockAnalytics()

	assert.Equal(t, analytics, GetAnalytics())
	assert.Equal(t, analytics.Service["service1"], GetServiceAnalytics("service1"))
	assert.Equal(t, analytics.Service, GetServicesAnalytics())
	assert.Equal(t, analytics.System, GetSystemAnalytics())
}
示例#2
0
func TestSaveAnalytics(t *testing.T) {
	defer storage.DeleteAllData(enum.ANALYTICS)
	analytics := CreateMockAnalytics()
	SaveAnalytics(analytics)

	encoded, _ := storage.GetLocalData(enum.ANALYTICS)
	decoded := GruAnalytics{}
	json.Unmarshal(encoded, &decoded)

	assert.Equal(t, analytics, decoded)
}
示例#3
0
func TestSavePolicy(t *testing.T) {
	defer storage.DeleteAllData(enum.POLICIES)
	policy := CreateRandomMockPolicies(1)[0]
	SavePolicy(policy)

	encoded, _ := storage.GetLocalData(enum.POLICIES)
	decoded := Policy{}
	json.Unmarshal(encoded, &decoded)

	assert.Equal(t, policy, decoded)
}
示例#4
0
func TestSaveStats(t *testing.T) {
	defer storage.DeleteAllData(enum.STATS)
	stats := CreateMockStats()
	SaveStats(stats)

	encoded, _ := storage.GetLocalData(enum.STATS)
	decoded := GruStats{}
	json.Unmarshal(encoded, &decoded)

	assert.Equal(t, stats, decoded)
}
示例#5
0
func TestGetPolicy(t *testing.T) {
	defer storage.DeleteAllData(enum.POLICIES)
	var err error

	_, err = GetPolicy()
	assert.Error(t, err)

	expected := CreateRandomMockPolicies(1)[0]
	SavePolicy(expected)
	policy, err := GetPolicy()
	assert.NoError(t, err)
	assert.Equal(t, expected, policy)
}
示例#6
0
func TestGetAnalytics(t *testing.T) {
	defer storage.DeleteAllData(enum.ANALYTICS)
	var err error

	_, err = GetAnalytics()
	assert.Error(t, err)

	expected := CreateMockAnalytics()
	SaveMockAnalytics()
	analytics, err := GetAnalytics()
	assert.NoError(t, err)
	assert.Equal(t, expected, analytics)
}
示例#7
0
func TestGetStats(t *testing.T) {
	defer storage.DeleteAllData(enum.STATS)
	var err error

	_, err = GetStats()
	assert.Error(t, err)

	expected := CreateMockStats()
	SaveMockStats()
	stats, err := GetStats()
	assert.NoError(t, err)
	assert.Equal(t, expected, stats)
}
示例#8
0
func TestSaveShared(t *testing.T) {
	defer storage.DeleteAllData(enum.SHARED)
	info := CreateMockShared()
	// Local
	SaveSharedLocal(info)

	encoded, _ := storage.GetLocalData(enum.SHARED)
	decoded := Shared{}
	json.Unmarshal(encoded, &decoded)
	assert.Equal(t, info, decoded)

	// Cluster
	SaveSharedCluster(info)

	encoded, _ = storage.GetLocalData(enum.SHARED)
	decoded = Shared{}
	json.Unmarshal(encoded, &decoded)
	assert.Equal(t, info, decoded)

}
示例#9
0
func TestGeShared(t *testing.T) {
	defer storage.DeleteAllData(enum.SHARED)
	var err error
	expected := CreateMockShared()

	// Local
	_, err = GetSharedLocal()
	assert.Error(t, err)

	SaveSharedLocal(expected)
	info, err := GetSharedLocal()
	assert.NoError(t, err)
	assert.Equal(t, expected, info)

	// Local
	_, err = GetSharedCluster()
	assert.Error(t, err)

	SaveSharedCluster(expected)
	info, err = GetSharedCluster()
	assert.NoError(t, err)
	assert.Equal(t, expected, info)
}