本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util.NewTime函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTime函数的具体用法?Golang NewTime怎么用?Golang NewTime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTime函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestPrintEventsResultSorted
func TestPrintEventsResultSorted(t *testing.T) {
// Arrange
printer := NewHumanReadablePrinter(false /* noHeaders */)
obj := api.EventList{
Items: []api.Event{
{
Source: api.EventSource{Component: "kubelet"},
Message: "Item 1",
Timestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
},
{
Source: api.EventSource{Component: "scheduler"},
Message: "Item 2",
Timestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
},
{
Source: api.EventSource{Component: "kubelet"},
Message: "Item 3",
Timestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
},
},
}
buffer := &bytes.Buffer{}
// Act
err := printer.PrintObj(&obj, buffer)
// Assert
if err != nil {
t.Fatalf("An error occurred printing the EventList: %#v", err)
}
out := buffer.String()
VerifyDatesInOrder(out, "\n" /* rowDelimiter */, " " /* columnDelimiter */, t)
}
开发者ID:nhr,项目名称:kubernetes,代码行数:35,代码来源:resource_printer_test.go
示例2: TestPodDescribeResultsSorted
func TestPodDescribeResultsSorted(t *testing.T) {
// Arrange
fake := &client.Fake{
EventsList: api.EventList{
Items: []api.Event{
{
Source: api.EventSource{Component: "kubelet"},
Message: "Item 1",
Timestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
},
{
Source: api.EventSource{Component: "scheduler"},
Message: "Item 2",
Timestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
},
{
Source: api.EventSource{Component: "kubelet"},
Message: "Item 3",
Timestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
},
},
},
}
c := &describeClient{T: t, Namespace: "foo", Fake: fake}
d := PodDescriber{c}
// Act
out, err := d.Describe("foo", "bar")
// Assert
if err != nil {
t.Errorf("unexpected error: %v", err)
}
VerifyDatesInOrder(out, "\n" /* rowDelimiter */, "\t" /* columnDelimiter */, t)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:35,代码来源:describe_test.go
示例3: TestSortableEvents
func TestSortableEvents(t *testing.T) {
// Arrange
list := SortableEvents([]api.Event{
{
Source: api.EventSource{Component: "kubelet"},
Message: "Item 1",
Timestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
},
{
Source: api.EventSource{Component: "scheduler"},
Message: "Item 2",
Timestamp: util.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
},
{
Source: api.EventSource{Component: "kubelet"},
Message: "Item 3",
Timestamp: util.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
},
})
// Act
sort.Sort(list)
// Assert
if list[0].Message != "Item 2" ||
list[1].Message != "Item 3" ||
list[2].Message != "Item 1" {
t.Fatal("List is not sorted by time. List: ", list)
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:30,代码来源:sorted_event_list_test.go
示例4: TestSort
// TestSort verifies that builds are sorted by most recently created
func TestSort(t *testing.T) {
present := util.Now()
past := util.NewTime(present.Time.Add(-1 * time.Minute))
builds := []*buildapi.Build{
{
ObjectMeta: kapi.ObjectMeta{
Name: "past",
CreationTimestamp: past,
},
},
{
ObjectMeta: kapi.ObjectMeta{
Name: "present",
CreationTimestamp: present,
},
},
}
sort.Sort(sortableBuilds(builds))
if builds[0].Name != "present" {
t.Errorf("Unexpected sort order")
}
if builds[1].Name != "past" {
t.Errorf("Unexpected sort order")
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:26,代码来源:sort_test.go
示例5: NewFilterBeforePredicate
// NewFilterBeforePredicate is a function that returns true if the build was created before the current time minus specified duration
func NewFilterBeforePredicate(d time.Duration) FilterPredicate {
now := util.Now()
before := util.NewTime(now.Time.Add(-1 * d))
return func(build *buildapi.Build) bool {
return build.CreationTimestamp.Before(before)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:8,代码来源:data.go
示例6: TestFillPodStatus
func TestFillPodStatus(t *testing.T) {
pod := makePod(api.NamespaceDefault, "foo", "machine", "bar")
expectedIP := "1.2.3.4"
expectedTime, _ := time.Parse("2013-Feb-03", "2013-Feb-03")
config := podCacheTestConfig{
kubeletContainerInfo: api.PodInfo{
"net": {
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.NewTime(expectedTime),
},
},
RestartCount: 1,
PodIP: expectedIP,
},
},
nodes: []api.Node{*makeNode("machine")},
pods: []api.Pod{*pod},
}
cache := config.Construct()
err := cache.updatePodStatus(&config.pods[0])
if err != nil {
t.Fatalf("Unexpected error: %+v", err)
}
status, err := cache.GetPodStatus(pod.Namespace, pod.Name)
if e, a := config.kubeletContainerInfo, status.Info; !reflect.DeepEqual(e, a) {
t.Errorf("Expected: %+v, Got %+v", e, a)
}
if status.PodIP != expectedIP {
t.Errorf("Expected %s, Got %s\n%+v", expectedIP, status.PodIP, status)
}
}
开发者ID:nhr,项目名称:kubernetes,代码行数:33,代码来源:pod_cache_test.go
示例7: TestSort
// TestSort verifies that builds are sorted by most recently created
func TestSort(t *testing.T) {
present := util.Now()
past := util.NewTime(present.Time.Add(-1 * time.Minute))
controllers := []*kapi.ReplicationController{
{
ObjectMeta: kapi.ObjectMeta{
Name: "past",
CreationTimestamp: past,
},
},
{
ObjectMeta: kapi.ObjectMeta{
Name: "present",
CreationTimestamp: present,
},
},
}
sort.Sort(sortableReplicationControllers(controllers))
if controllers[0].Name != "present" {
t.Errorf("Unexpected sort order")
}
if controllers[1].Name != "past" {
t.Errorf("Unexpected sort order")
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:26,代码来源:sort_test.go
示例8: NewFilterBeforePredicate
// NewFilterBeforePredicate is a function that returns true if the build was created before the current time minus specified duration
func NewFilterBeforePredicate(d time.Duration) FilterPredicate {
now := util.Now()
before := util.NewTime(now.Time.Add(-1 * d))
return func(item *kapi.ReplicationController) bool {
return item.CreationTimestamp.Before(before)
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:8,代码来源:data.go
示例9: TestFilterBeforePredicate
func TestFilterBeforePredicate(t *testing.T) {
youngerThan := time.Hour
now := util.Now()
old := util.NewTime(now.Time.Add(-1 * youngerThan))
builds := []*buildapi.Build{
{
ObjectMeta: kapi.ObjectMeta{
Name: "old",
CreationTimestamp: old,
},
},
{
ObjectMeta: kapi.ObjectMeta{
Name: "new",
CreationTimestamp: now,
},
},
}
filter := &andFilter{
filterPredicates: []FilterPredicate{NewFilterBeforePredicate(youngerThan)},
}
result := filter.Filter(builds)
if len(result) != 1 {
t.Errorf("Unexpected number of results")
}
if expected, actual := "old", result[0].Name; expected != actual {
t.Errorf("expected %v, actual %v", expected, actual)
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:29,代码来源:data_test.go
示例10: TestBuildDecorator
func TestBuildDecorator(t *testing.T) {
build := &buildapi.Build{
ObjectMeta: kapi.ObjectMeta{Name: "buildid", Namespace: "default"},
Parameters: buildapi.BuildParameters{
Source: buildapi.BuildSource{
Type: buildapi.BuildSourceGit,
Git: &buildapi.GitBuildSource{
URI: "http://github.com/my/repository",
},
ContextDir: "context",
},
Strategy: buildapi.BuildStrategy{
Type: buildapi.DockerBuildStrategyType,
DockerStrategy: &buildapi.DockerBuildStrategy{},
},
Output: buildapi.BuildOutput{
DockerImageReference: "repository/data",
},
},
Status: buildapi.BuildStatusNew,
}
now := util.Now()
startTime := util.NewTime(now.Time.Add(-1 * time.Minute))
build.StartTimestamp = &startTime
err := Decorator(build)
if err != nil {
t.Errorf("Unexpected error decorating build")
}
if build.Duration <= 0 {
t.Errorf("Build duration should be greater than zero")
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:32,代码来源:strategy_test.go
示例11: agedImage
func agedImage(id, ref string, ageInMinutes int64) imageapi.Image {
image := imageWithLayers(id, ref,
"tarsum.dev+sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"tarsum.dev+sha256:b194de3772ebbcdc8f244f663669799ac1cb141834b7cb8b69100285d357a2b0",
"tarsum.dev+sha256:c937c4bb1c1a21cc6d94340812262c6472092028972ae69b551b1a70d4276171",
"tarsum.dev+sha256:2aaacc362ac6be2b9e9ae8c6029f6f616bb50aec63746521858e47841b90fabd",
"tarsum.dev+sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
)
if ageInMinutes >= 0 {
image.CreationTimestamp = util.NewTime(util.Now().Add(time.Duration(-1*ageInMinutes) * time.Minute))
}
return image
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:15,代码来源:imagepruner_test.go
示例12: init
func init() {
err := kapi.Scheme.AddConversionFuncs(
// Convert docker client object to internal object, but only when this package is included
func(in *docker.ImagePre012, out *newer.DockerImage, s conversion.Scope) error {
if err := s.Convert(in.Config, &out.Config, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
if err := s.Convert(&in.ContainerConfig, &out.ContainerConfig, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.ID = in.ID
out.Parent = in.Parent
out.Comment = in.Comment
out.Created = util.NewTime(in.Created)
out.Container = in.Container
out.DockerVersion = in.DockerVersion
out.Author = in.Author
out.Architecture = in.Architecture
out.Size = in.Size
return nil
},
func(in *newer.DockerImage, out *docker.ImagePre012, s conversion.Scope) error {
if err := s.Convert(&in.Config, &out.Config, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
if err := s.Convert(&in.ContainerConfig, &out.ContainerConfig, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.ID = in.ID
out.Parent = in.Parent
out.Comment = in.Comment
out.Created = in.Created.Time
out.Container = in.Container
out.DockerVersion = in.DockerVersion
out.Author = in.Author
out.Architecture = in.Architecture
out.Size = in.Size
return nil
},
)
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:45,代码来源:conversion.go
示例13: TestFilterBeforePredicate
func TestFilterBeforePredicate(t *testing.T) {
youngerThan := time.Hour
now := util.Now()
old := util.NewTime(now.Time.Add(-1 * youngerThan))
items := []*kapi.ReplicationController{}
items = append(items, withCreated(mockDeployment("a", "old", nil), old))
items = append(items, withCreated(mockDeployment("a", "new", nil), now))
filter := &andFilter{
filterPredicates: []FilterPredicate{NewFilterBeforePredicate(youngerThan)},
}
result := filter.Filter(items)
if len(result) != 1 {
t.Errorf("Unexpected number of results")
}
if expected, actual := "old", result[0].Name; expected != actual {
t.Errorf("expected %v, actual %v", expected, actual)
}
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:18,代码来源:data_test.go
示例14: agedPod
func agedPod(namespace, name string, phase kapi.PodPhase, ageInMinutes int64, containerImages ...string) kapi.Pod {
pod := kapi.Pod{
ObjectMeta: kapi.ObjectMeta{
Namespace: namespace,
Name: name,
},
Spec: podSpec(containerImages...),
Status: kapi.PodStatus{
Phase: phase,
},
}
if ageInMinutes >= 0 {
pod.CreationTimestamp = util.NewTime(util.Now().Add(time.Duration(-1*ageInMinutes) * time.Minute))
}
return pod
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:18,代码来源:imagepruner_test.go
示例15: agedStream
func agedStream(registry, namespace, name string, ageInMinutes int64, tags map[string]imageapi.TagEventList) imageapi.ImageStream {
stream := imageapi.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Namespace: namespace,
Name: name,
},
Status: imageapi.ImageStreamStatus{
DockerImageRepository: fmt.Sprintf("%s/%s/%s", registry, namespace, name),
Tags: tags,
},
}
if ageInMinutes >= 0 {
stream.CreationTimestamp = util.NewTime(util.Now().Add(time.Duration(-1*ageInMinutes) * time.Minute))
}
return stream
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:18,代码来源:imagepruner_test.go
示例16: TestNewStatusPreservesPodStartTime
func TestNewStatusPreservesPodStartTime(t *testing.T) {
syncer := newTestStatusManager()
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
UID: "12345678",
Name: "foo",
Namespace: "new",
},
Status: api.PodStatus{},
}
now := util.Now()
startTime := util.NewTime(now.Time.Add(-1 * time.Minute))
pod.Status.StartTime = &startTime
syncer.SetPodStatus(pod, getRandomPodStatus())
status, _ := syncer.GetPodStatus(kubecontainer.GetPodFullName(pod))
if !status.StartTime.Time.Equal(startTime.Time) {
t.Errorf("Unexpected start time, expected %v, actual %v", startTime, status.StartTime)
}
}
开发者ID:mbforbes,项目名称:kubernetes,代码行数:20,代码来源:status_manager_test.go
示例17: TestSortByCreationTimestamp
func TestSortByCreationTimestamp(t *testing.T) {
present := util.Now()
past := util.NewTime(present.Add(-time.Minute))
builds := []Build{
{
ObjectMeta: kapi.ObjectMeta{
Name: "present",
CreationTimestamp: present,
},
},
{
ObjectMeta: kapi.ObjectMeta{
Name: "past",
CreationTimestamp: past,
},
},
}
sort.Sort(ByCreationTimestamp(builds))
if [2]string{builds[0].Name, builds[1].Name} != [2]string{"past", "present"} {
t.Errorf("Unexpected sort order")
}
}
开发者ID:patrykattc,项目名称:origin,代码行数:22,代码来源:sort_test.go
示例18: TestPruneTask
func TestPruneTask(t *testing.T) {
buildStatusOptions := []buildapi.BuildStatus{
buildapi.BuildStatusCancelled,
buildapi.BuildStatusComplete,
buildapi.BuildStatusError,
buildapi.BuildStatusFailed,
buildapi.BuildStatusNew,
buildapi.BuildStatusPending,
buildapi.BuildStatusRunning,
}
buildStatusFilter := []buildapi.BuildStatus{
buildapi.BuildStatusCancelled,
buildapi.BuildStatusComplete,
buildapi.BuildStatusError,
buildapi.BuildStatusFailed,
}
buildStatusFilterSet := util.StringSet{}
for _, buildStatus := range buildStatusFilter {
buildStatusFilterSet.Insert(string(buildStatus))
}
for _, orphans := range []bool{true, false} {
for _, buildStatusOption := range buildStatusOptions {
keepYoungerThan := time.Hour
now := util.Now()
old := util.NewTime(now.Time.Add(-1 * keepYoungerThan))
buildConfigs := []*buildapi.BuildConfig{}
builds := []*buildapi.Build{}
buildConfig := mockBuildConfig("a", "build-config")
buildConfigs = append(buildConfigs, buildConfig)
builds = append(builds, withCreated(withStatus(mockBuild("a", "build-1", buildConfig), buildStatusOption), now))
builds = append(builds, withCreated(withStatus(mockBuild("a", "build-2", buildConfig), buildStatusOption), old))
builds = append(builds, withCreated(withStatus(mockBuild("a", "orphan-build-1", nil), buildStatusOption), now))
builds = append(builds, withCreated(withStatus(mockBuild("a", "orphan-build-2", nil), buildStatusOption), old))
keepComplete := 1
keepFailed := 1
expectedValues := util.StringSet{}
filter := &andFilter{
filterPredicates: []FilterPredicate{NewFilterBeforePredicate(keepYoungerThan)},
}
dataSet := NewDataSet(buildConfigs, filter.Filter(builds))
resolver := NewPerBuildConfigResolver(dataSet, keepComplete, keepFailed)
if orphans {
resolver = &mergeResolver{
resolvers: []Resolver{resolver, NewOrphanBuildResolver(dataSet, buildStatusFilter)},
}
}
expectedBuilds, err := resolver.Resolve()
for _, build := range expectedBuilds {
expectedValues.Insert(build.Name)
}
recorder := &mockPruneRecorder{set: util.StringSet{}}
task := NewPruneTasker(buildConfigs, builds, keepYoungerThan, orphans, keepComplete, keepFailed, recorder.Handler)
err = task.PruneTask()
if err != nil {
t.Errorf("Unexpected error %v", err)
}
recorder.Verify(t, expectedValues)
}
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:68,代码来源:prune_test.go
示例19:
defer GinkgoRecover()
if p.Status.Phase == api.PodRunning {
if _, found := watchTimes[p.Name]; !found {
watchTimes[p.Name] = util.Now()
createTimes[p.Name] = p.CreationTimestamp
nodes[p.Name] = p.Spec.NodeName
var startTime util.Time
for _, cs := range p.Status.ContainerStatuses {
if cs.State.Running != nil {
if startTime.Before(cs.State.Running.StartedAt) {
startTime = cs.State.Running.StartedAt
}
}
}
if startTime != util.NewTime(time.Time{}) {
runTimes[p.Name] = startTime
} else {
Failf("Pod %v is reported to be running, but none of its containers is", p.Name)
}
}
}
}
additionalPodsPrefix = "density-latency-pod-" + string(util.NewUUID())
_, controller := framework.NewInformer(
&cache.ListWatch{
ListFunc: func() (runtime.Object, error) {
return c.Pods(ns).List(labels.SelectorFromSet(labels.Set{"name": additionalPodsPrefix}), fields.Everything())
},
WatchFunc: func(rv string) (watch.Interface, error) {
开发者ID:Ima8,项目名称:kubernetes,代码行数:31,代码来源:density.go
示例20: TestDescribeContainers
func TestDescribeContainers(t *testing.T) {
testCases := []struct {
input api.ContainerStatus
expectedElements []string
}{
// Running state.
{
input: api.ContainerStatus{
Name: "test",
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: util.NewTime(time.Now()),
},
},
Ready: true,
RestartCount: 7,
Image: "image",
},
expectedElements: []string{"test", "State", "Running", "Ready", "True", "Restart Count", "7", "Image", "image", "Started"},
},
// Waiting state.
{
input: api.ContainerStatus{
Name: "test",
State: api.ContainerState{
Waiting: &api.ContainerStateWaiting{
Reason: "potato",
},
},
Ready: true,
RestartCount: 7,
Image: "image",
},
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "Reason", "potato"},
},
// Terminated state.
{
input: api.ContainerStatus{
Name: "test",
State: api.ContainerState{
Terminated: &api.ContainerStateTerminated{
StartedAt: util.NewTime(time.Now()),
FinishedAt: util.NewTime(time.Now()),
Reason: "potato",
ExitCode: 2,
},
},
Ready: true,
RestartCount: 7,
Image: "image",
},
expectedElements: []string{"test", "State", "Terminated", "Ready", "True", "Restart Count", "7", "Image", "image", "Reason", "potato", "Started", "Finished", "Exit Code", "2"},
},
// No state defaults to waiting.
{
input: api.ContainerStatus{
Name: "test",
Ready: true,
RestartCount: 7,
Image: "image",
},
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image"},
},
}
for i, testCase := range testCases {
out := new(bytes.Buffer)
describeContainers([]api.ContainerStatus{testCase.input}, out)
output := out.String()
for _, expected := range testCase.expectedElements {
if !strings.Contains(output, expected) {
t.Errorf("Test case %d: expected to find %q in output: %q", i, expected, output)
}
}
}
}
开发者ID:mbforbes,项目名称:kubernetes,代码行数:76,代码来源:describe_test.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/util.NewTime函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论