Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
4c58fd82
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4c58fd82
编写于
6月 01, 2017
作者:
K
kushalpandya
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tests for `PrometheusMetrics` class
上级
afc1a67d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
166 addition
and
0 deletion
+166
-0
spec/javascripts/prometheus_metrics/mock_data.js
spec/javascripts/prometheus_metrics/mock_data.js
+41
-0
spec/javascripts/prometheus_metrics/prometheus_metrics_spec.js
...javascripts/prometheus_metrics/prometheus_metrics_spec.js
+125
-0
未找到文件。
spec/javascripts/prometheus_metrics/mock_data.js
0 → 100644
浏览文件 @
4c58fd82
export
const
metrics
=
[
{
group
:
'
Kubernetes
'
,
priority
:
1
,
active_metrics
:
4
,
metrics_missing_requirements
:
0
,
},
{
group
:
'
HAProxy
'
,
priority
:
2
,
active_metrics
:
3
,
metrics_missing_requirements
:
0
,
},
{
group
:
'
Apache
'
,
priority
:
3
,
active_metrics
:
5
,
metrics_missing_requirements
:
0
,
},
];
export
const
missingVarMetrics
=
[
{
group
:
'
Kubernetes
'
,
priority
:
1
,
active_metrics
:
4
,
metrics_missing_requirements
:
0
,
},
{
group
:
'
HAProxy
'
,
priority
:
2
,
active_metrics
:
3
,
metrics_missing_requirements
:
1
,
},
{
group
:
'
Apache
'
,
priority
:
3
,
active_metrics
:
5
,
metrics_missing_requirements
:
3
,
},
];
spec/javascripts/prometheus_metrics/prometheus_metrics_spec.js
0 → 100644
浏览文件 @
4c58fd82
import
PrometheusMetrics
from
'
~/prometheus_metrics/prometheus_metrics
'
;
import
{
metrics
,
missingVarMetrics
}
from
'
./mock_data
'
;
describe
(
'
PrometheusMetrics
'
,
()
=>
{
const
FIXTURE
=
'
services/prometheus_service.html.raw
'
;
preloadFixtures
(
FIXTURE
);
beforeEach
(()
=>
{
loadFixtures
(
FIXTURE
);
});
describe
(
'
constructor
'
,
()
=>
{
let
prometheusMetrics
;
beforeEach
(()
=>
{
prometheusMetrics
=
new
PrometheusMetrics
(
'
.js-prometheus-metrics-monitoring
'
);
});
it
(
'
should initialize wrapper element refs on class object
'
,
()
=>
{
expect
(
prometheusMetrics
.
$wrapper
).
toBeDefined
();
expect
(
prometheusMetrics
.
$monitoredMetricsPanel
).
toBeDefined
();
expect
(
prometheusMetrics
.
$monitoredMetricsCount
).
toBeDefined
();
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
).
toBeDefined
();
expect
(
prometheusMetrics
.
$monitoredMetricsEmpty
).
toBeDefined
();
expect
(
prometheusMetrics
.
$monitoredMetricsList
).
toBeDefined
();
expect
(
prometheusMetrics
.
$missingEnvVarPanel
).
toBeDefined
();
expect
(
prometheusMetrics
.
$panelToggle
).
toBeDefined
();
expect
(
prometheusMetrics
.
$missingEnvVarMetricCount
).
toBeDefined
();
expect
(
prometheusMetrics
.
$missingEnvVarMetricsList
).
toBeDefined
();
});
it
(
'
should initialize metadata on class object
'
,
()
=>
{
expect
(
prometheusMetrics
.
backOffRequestCounter
).
toEqual
(
0
);
expect
(
prometheusMetrics
.
activeMetricsEndpoint
).
toContain
(
'
/test
'
);
});
});
describe
(
'
populateActiveMetrics
'
,
()
=>
{
let
prometheusMetrics
;
beforeEach
(()
=>
{
prometheusMetrics
=
new
PrometheusMetrics
(
'
.js-prometheus-metrics-monitoring
'
);
});
it
(
'
should show monitored metrics list
'
,
()
=>
{
prometheusMetrics
.
populateActiveMetrics
(
metrics
);
const
$metricsListLi
=
prometheusMetrics
.
$monitoredMetricsList
.
find
(
'
li
'
);
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
expect
(
prometheusMetrics
.
$monitoredMetricsList
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
expect
(
prometheusMetrics
.
$monitoredMetricsCount
.
text
()).
toEqual
(
'
12
'
);
expect
(
$metricsListLi
.
length
).
toEqual
(
metrics
.
length
);
expect
(
$metricsListLi
.
first
().
find
(
'
.badge-count
'
).
text
()).
toEqual
(
`
${
metrics
[
0
].
active_metrics
}
`
);
});
it
(
'
should show missing environment variables list
'
,
()
=>
{
prometheusMetrics
.
populateActiveMetrics
(
missingVarMetrics
);
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
expect
(
prometheusMetrics
.
$missingEnvVarPanel
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
expect
(
prometheusMetrics
.
$missingEnvVarMetricCount
.
text
()).
toEqual
(
'
2
'
);
expect
(
prometheusMetrics
.
$missingEnvVarPanel
.
find
(
'
li
'
).
length
).
toEqual
(
2
);
expect
(
prometheusMetrics
.
$missingEnvVarPanel
.
find
(
'
.flash-container
'
)).
toBeDefined
();
});
});
describe
(
'
loadActiveMetrics
'
,
()
=>
{
let
prometheusMetrics
;
beforeEach
(()
=>
{
prometheusMetrics
=
new
PrometheusMetrics
(
'
.js-prometheus-metrics-monitoring
'
);
});
it
(
'
should show loader animation while response is being loaded and hide it when request is complete
'
,
(
done
)
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'
getJSON
'
).
and
.
returnValue
(
deferred
.
promise
());
prometheusMetrics
.
loadActiveMetrics
();
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
expect
(
$
.
getJSON
).
toHaveBeenCalledWith
(
prometheusMetrics
.
activeMetricsEndpoint
);
deferred
.
resolve
({
data
:
metrics
,
success
:
true
});
setTimeout
(()
=>
{
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
done
();
});
});
it
(
'
should show empty state if response failed to load
'
,
(
done
)
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'
getJSON
'
).
and
.
returnValue
(
deferred
.
promise
());
spyOn
(
prometheusMetrics
,
'
populateActiveMetrics
'
);
prometheusMetrics
.
loadActiveMetrics
();
deferred
.
reject
();
setTimeout
(()
=>
{
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
expect
(
prometheusMetrics
.
$monitoredMetricsEmpty
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
done
();
});
});
it
(
'
should populate metrics list once response is loaded
'
,
(
done
)
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'
getJSON
'
).
and
.
returnValue
(
deferred
.
promise
());
spyOn
(
prometheusMetrics
,
'
populateActiveMetrics
'
);
prometheusMetrics
.
loadActiveMetrics
();
deferred
.
resolve
({
data
:
metrics
,
success
:
true
});
setTimeout
(()
=>
{
expect
(
prometheusMetrics
.
populateActiveMetrics
).
toHaveBeenCalledWith
(
metrics
);
done
();
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录