github.com/kubevela/workflow@v0.6.0/cmd/main_e2e_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 main
    18  
    19  import (
    20  	"fmt"
    21  	"os"
    22  	"os/signal"
    23  	"strings"
    24  	"syscall"
    25  	"testing"
    26  )
    27  
    28  func TestE2EMain(t *testing.T) {
    29  	fmt.Println("this is e2e test")
    30  	var (
    31  		args []string
    32  		run  bool
    33  	)
    34  
    35  	for _, arg := range os.Args {
    36  		switch {
    37  		case strings.HasPrefix(arg, "__DEVEL__E2E"):
    38  			run = true
    39  		case strings.HasPrefix(arg, "-test"):
    40  		default:
    41  			args = append(args, arg)
    42  		}
    43  	}
    44  
    45  	if !run {
    46  		return
    47  	}
    48  
    49  	waitCh := make(chan int, 1)
    50  
    51  	//args=append(args, "leader-election-namespace='someNS'")
    52  	os.Args = args
    53  	go func() {
    54  		main()
    55  		close(waitCh)
    56  	}()
    57  
    58  	signalCh := make(chan os.Signal, 1)
    59  	signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)
    60  	select {
    61  	case <-signalCh:
    62  	case <-waitCh:
    63  	}
    64  	fmt.Println("exit test e2e main")
    65  }