github.com/oam-dev/kubevela@v1.9.11/references/cli/top/model/log_test.go (about) 1 /* 2 Copyright 2022 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package model 18 19 import ( 20 "context" 21 22 . "github.com/onsi/ginkgo/v2" 23 . "github.com/onsi/gomega" 24 ) 25 26 var _ = Describe("test log output", func() { 27 var logC chan string 28 var err error 29 30 ctx, cancelFunc := context.WithCancel(context.Background()) 31 32 It("generate channel", func() { 33 logC, err = PrintLogOfPod(ctx, cfg, "local", "default", "pod1", "") 34 Expect(err).NotTo(HaveOccurred()) 35 Expect(len(logC)).To(Equal(0)) 36 37 flag := false 38 select { 39 case <-ctx.Done(): 40 flag = true 41 default: 42 } 43 Expect(flag).To(Equal(false)) 44 }) 45 46 It("close channel", func() { 47 cancelFunc() 48 flag := false 49 select { 50 case <-ctx.Done(): 51 flag = true 52 default: 53 } 54 Expect(flag).To(Equal(true)) 55 }) 56 })