Skip to Content
Kubernetes编程
book

Kubernetes编程

by Michael Hausenblas, Stefan Schimanski
June 2021
Intermediate to advanced
335 pages
5h 50m
Chinese
China Electric Power Press Ltd.
Content preview from Kubernetes编程
228
8
为某个类型开发随机函数时,建议先调用
c.FuzzNoCustom(s)
,它会为给定的
对象
s
进行随机赋值,并会调用其子结构的自定义随机函数,但不会调用
s
本身的自定义随机函数。然后开发者可以对随机值进行一些限制和调整来保
证生成的是一个合法的对象。
应当尽量让
Fuzzer
变得通用,以保证覆盖尽可能多的合法对象。如果对
Fuzzer
施加过多限制条件,测试的覆盖率将会很差。在
Kubernetes
的开发过
程中,我们遇到过很多次由于
Fuzzer
不好而导致没有在测试中及时发现新
引入的问题。
另一方面,
Fuzzer
只需要考虑合法的、外部版本定义的实际对象的投影对象。
通常你需要限制
c.FuzzNoCustom(s)
设置的随机值来让随机对象变得合法。
例如,如果
URL
校验逻辑会拒绝随机字符串,
URL
的双程测试中就无须覆
盖该字符串是完全随机值的情况。
我们前面的
PizzaSpec
例子首先调用
c.FuzzNoCustom(s)
,然后通过以下方式
来修改该对象:
为配料是
nil
的情况设置默认值。
为每种配料设置合理的数量(如果不这样做的话,向
v1alpha1
的转换复
杂度将会无法控制,可能会给
string
列表入插入过多的数据)。
归一化配料名称,因为一个披萨的重复配料是永远无法做到双程的(对于
内部类型而言,注意
v1alpha1
版本的类型中允许配料重复)。
8.4.8
验证
从外部输入的对象在反序列化、设置默认值以及转成内部类型之后就已经简
单验证过了。从图
8-5
中可知,验证过程中是在变更准入插件和验证准入插 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley
Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu
软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton

Publisher Resources

ISBN: 9787519854799